From b63144cb0d031c0c7ea5c1214100dbb1c0487995 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Fri, 5 Jan 2024 18:11:19 +0100 Subject: [PATCH] always allow workflows to mount /srv/example because it is generally useful to store informations about how the workflow ran --- .../example-cron/.forgejo/workflows/test.yml | 4 +-- actions/example-cron/run.sh | 2 +- actions/example-cron/runner-config.yaml | 30 ------------------- actions/example-cron/setup.sh | 4 +-- actions/example-cron/teardown.sh | 1 - .../.forgejo/workflows/test.yml | 4 +-- actions/example-pull-request/run.sh | 4 ++- actions/example-pull-request/setup.sh | 8 +---- actions/example-pull-request/teardown.sh | 1 - actions/run.sh | 20 ++++++++++++- .../runner-config.yaml | 2 +- 11 files changed, 30 insertions(+), 50 deletions(-) delete mode 100644 actions/example-cron/runner-config.yaml delete mode 100755 actions/example-cron/teardown.sh delete mode 100755 actions/example-pull-request/teardown.sh rename actions/{example-pull-request => }/runner-config.yaml (89%) diff --git a/actions/example-cron/.forgejo/workflows/test.yml b/actions/example-cron/.forgejo/workflows/test.yml index c81b017..5f9a843 100644 --- a/actions/example-cron/.forgejo/workflows/test.yml +++ b/actions/example-cron/.forgejo/workflows/test.yml @@ -7,8 +7,8 @@ jobs: runs-on: docker container: image: code.forgejo.org/oci/debian:bookworm - options: "--volume /srv/example-cron-volume:/srv/example-cron-volume" + options: "--volume /srv/example:/srv/example" steps: - run: | - touch /srv/example-cron-volume/DONE + touch /srv/example/cron-volume/DONE diff --git a/actions/example-cron/run.sh b/actions/example-cron/run.sh index 3ced64c..c0dc193 100755 --- a/actions/example-cron/run.sh +++ b/actions/example-cron/run.sh @@ -16,7 +16,7 @@ forgejo-curl.sh api_json --data '{"new_branch_name":"zzzz"}' $api/repos/root/exa verify_ref # cron runs once per minute, give it three minutes max before declaring failure -if ! RETRY_DELAYS="30 30 30 30 30 30" forgejo.sh retry test -f /srv/example-cron-volume/DONE ; then +if ! RETRY_DELAYS="30 30 30 30 30 30" forgejo.sh retry test -f /srv/example/cron-volume/DONE ; then cat $FORGEJO_RUNNER_LOGS false fi diff --git a/actions/example-cron/runner-config.yaml b/actions/example-cron/runner-config.yaml deleted file mode 100644 index 119cde4..0000000 --- a/actions/example-cron/runner-config.yaml +++ /dev/null @@ -1,30 +0,0 @@ - -log: - level: info - -runner: - file: .runner - capacity: 1 - env_file: .env - timeout: 3h - insecure: false - fetch_timeout: 5s - fetch_interval: 2s - labels: ["docker:docker://code.forgejo.org/oci/node:16-bullseye"] - -cache: - enabled: false - dir: "" - host: "" - port: 0 - -container: - network: "" - privileged: false - options: - workdir_parent: - valid_volumes: ["/srv/example-cron-volume"] - docker_host: "" - -host: - workdir_parent: diff --git a/actions/example-cron/setup.sh b/actions/example-cron/setup.sh index ee70b92..ed70dec 100755 --- a/actions/example-cron/setup.sh +++ b/actions/example-cron/setup.sh @@ -1,3 +1 @@ -rm -fr /srv/example-cron-volume -mkdir -p /srv/example-cron-volume -FORGEJO_RUNNER_CONFIG=$EXAMPLE_DIR/runner-config.yaml forgejo-runner.sh reload +mkdir -p /srv/example/cron-volume diff --git a/actions/example-cron/teardown.sh b/actions/example-cron/teardown.sh deleted file mode 100755 index b410c51..0000000 --- a/actions/example-cron/teardown.sh +++ /dev/null @@ -1 +0,0 @@ -forgejo-runner.sh reload diff --git a/actions/example-pull-request/.forgejo/workflows/test.yml b/actions/example-pull-request/.forgejo/workflows/test.yml index 90e9fb4..52be20f 100644 --- a/actions/example-pull-request/.forgejo/workflows/test.yml +++ b/actions/example-pull-request/.forgejo/workflows/test.yml @@ -10,7 +10,7 @@ jobs: runs-on: docker container: image: code.forgejo.org/oci/node:20-bookworm - options: "--volume /srv/example-pull-request:/srv/example-pull-request" + options: "--volume /srv/example:/srv/example" steps: - name: setup @@ -115,7 +115,7 @@ jobs: - name: save event run: | - d=/srv/example-pull-request/${{ github.event.pull_request.head.repo.owner.username }}/$GITHUB_EVENT_NAME/${{ github.event.action }} + d=/srv/example/pull-request/${{ github.event.pull_request.head.repo.owner.username }}/$GITHUB_EVENT_NAME/${{ github.event.action }} mkdir -p $d cat > $d/event <<'EOF' ${{ toJSON(github.event) }} diff --git a/actions/example-pull-request/run.sh b/actions/example-pull-request/run.sh index 2a88afd..b6897a2 100755 --- a/actions/example-pull-request/run.sh +++ b/actions/example-pull-request/run.sh @@ -1,9 +1,11 @@ api=$url/api/v1 -export d=/srv/example-pull-request +export d=/srv/example/pull-request PROOF='some proof' function setup() { + mkdir -p $d + forgejo-test-helper.sh push_workflow actions/example-$example $url root example-$example setup-forgejo $token forgejo-curl.sh api_json --data-raw '{"username":"fork-org"}' $api/orgs diff --git a/actions/example-pull-request/setup.sh b/actions/example-pull-request/setup.sh index e93087e..72c13c0 100755 --- a/actions/example-pull-request/setup.sh +++ b/actions/example-pull-request/setup.sh @@ -1,8 +1,2 @@ -if test $(id -u) != 0 ; then - SUDO=sudo -fi +mkdir -p /srv/example/pull-request -$SUDO rm -fr /srv/example-pull-request/{root,fork-org} -rm -fr /srv/example-pull-request -mkdir -p /srv/example-pull-request -FORGEJO_RUNNER_CONFIG=$EXAMPLE_DIR/runner-config.yaml forgejo-runner.sh reload diff --git a/actions/example-pull-request/teardown.sh b/actions/example-pull-request/teardown.sh deleted file mode 100755 index b410c51..0000000 --- a/actions/example-pull-request/teardown.sh +++ /dev/null @@ -1 +0,0 @@ -forgejo-runner.sh reload diff --git a/actions/run.sh b/actions/run.sh index 717682d..a776982 100755 --- a/actions/run.sh +++ b/actions/run.sh @@ -2,11 +2,13 @@ set -e +SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + function run() { local example=$1 export example - export EXAMPLE_DIR=$(pwd)/actions/example-$example + export EXAMPLE_DIR=$SELF_DIR/example-$example if test -f $EXAMPLE_DIR/setup.sh ; then echo "============================ SETUP example-$example ===================" @@ -39,9 +41,24 @@ function examples_v1_22() { examples_v1_21 } +function cleanup_example_volume() { + if ! test -d /srv/example ; then + mkdir -p /srv/example + return + fi + + if test $(id -u) != 0 ; then + SUDO=sudo + fi + + $SUDO rm -fr /srv/example/* +} + function setup() { local binary=$1 forgejo-binary.sh setup root admin1234 $binary + cleanup_example_volume + export FORGEJO_RUNNER_CONFIG=$SELF_DIR/runner-config.yaml forgejo-runner.sh setup } @@ -90,6 +107,7 @@ function main() { false fi echo "======================== END example-$example ===================" + cleanup_example_volume done } diff --git a/actions/example-pull-request/runner-config.yaml b/actions/runner-config.yaml similarity index 89% rename from actions/example-pull-request/runner-config.yaml rename to actions/runner-config.yaml index 5c3a6b3..12019d7 100644 --- a/actions/example-pull-request/runner-config.yaml +++ b/actions/runner-config.yaml @@ -23,7 +23,7 @@ container: privileged: false options: workdir_parent: - valid_volumes: ["/srv/example-pull-request"] + valid_volumes: ["/srv/example"] docker_host: "" host: