From fc548f5117204f629253c929b38ee4bf652872fa Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Fri, 29 Sep 2023 16:35:59 +0200 Subject: [PATCH 1/6] add example of artifact usage --- .forgejo/workflows/integration.yml | 2 +- README.md | 3 ++- .../.forgejo/workflows/many.yml | 22 +++++++++++++++++ .../.forgejo/workflows/one.yml | 24 +++++++++++++++++++ 4 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 testdata/example-artifacts/.forgejo/workflows/many.yml create mode 100644 testdata/example-artifacts/.forgejo/workflows/one.yml diff --git a/.forgejo/workflows/integration.yml b/.forgejo/workflows/integration.yml index a7eb22c..9d7ad78 100644 --- a/.forgejo/workflows/integration.yml +++ b/.forgejo/workflows/integration.yml @@ -8,7 +8,7 @@ jobs: info: - version: "1.21.0-1-rc0" image: codeberg.org/forgejo-experimental/forgejo - tests: "echo cron pull-request service container expression local-action docker-action if if-fail" + tests: "echo cron artifacts pull-request service container expression local-action docker-action if if-fail" - version: "1.20" image: codeberg.org/forgejo/forgejo tests: "echo service container expression local-action docker-action if if-fail" diff --git a/README.md b/README.md index 81cd769..2da9cb1 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,7 @@ because the tests run as root, but they do not need to run as root. * `export example=pull-request` * `export EXAMPLE_DIR=$(pwd)/testdata/example-$example` * `$EXAMPLE_DIR/setup.sh` # if it exists -* `$EXAMPLE_DIR/run.sh` +* `$EXAMPLE_DIR/run.sh` or +* `forgejo-test-helper.sh run_workflow testdata/example-$example http://root:admin1234@$(cat forgejo-ip):3000 root example-$example setup-forgejo $(cat forgejo-token)` * `forgejo-runner.sh teardown` * `forgejo.sh teardown` diff --git a/testdata/example-artifacts/.forgejo/workflows/many.yml b/testdata/example-artifacts/.forgejo/workflows/many.yml new file mode 100644 index 0000000..52b0d9a --- /dev/null +++ b/testdata/example-artifacts/.forgejo/workflows/many.yml @@ -0,0 +1,22 @@ +on: [push] +jobs: + upload: + runs-on: docker + steps: + - run: mkdir -p artifacts + + - run: touch artifacts/ONE artifacts/TWO + + - uses: actions/upload-artifact@v3 + with: + name: many-artifacts + path: artifacts/ + + download: + runs-on: docker + steps: + - uses: actions/download-artifact@v3 + + - run: | + test -f many-artifacts/ONE + test -f many-artifacts/TWO diff --git a/testdata/example-artifacts/.forgejo/workflows/one.yml b/testdata/example-artifacts/.forgejo/workflows/one.yml new file mode 100644 index 0000000..3d61853 --- /dev/null +++ b/testdata/example-artifacts/.forgejo/workflows/one.yml @@ -0,0 +1,24 @@ +on: [push] +jobs: + upload: + runs-on: docker + steps: + - run: mkdir -p path/to/artifact + + - run: echo hello > path/to/artifact/world.txt + + - uses: actions/upload-artifact@v3 + with: + name: my-artifact + path: path/to/artifact/world.txt + + download: + runs-on: docker + steps: + - run: "! test -f world.txt" + + - uses: actions/download-artifact@v3 + with: + name: my-artifact + + - run: "test -f world.txt" From cafd1de763dc320d4195d0c9996dbfdc16e89e50 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Fri, 29 Sep 2023 17:56:11 +0200 Subject: [PATCH 2/6] cron will linger, give it an insolated run --- .forgejo/workflows/integration.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.forgejo/workflows/integration.yml b/.forgejo/workflows/integration.yml index 9d7ad78..11313ac 100644 --- a/.forgejo/workflows/integration.yml +++ b/.forgejo/workflows/integration.yml @@ -8,7 +8,10 @@ jobs: info: - version: "1.21.0-1-rc0" image: codeberg.org/forgejo-experimental/forgejo - tests: "echo cron artifacts pull-request service container expression local-action docker-action if if-fail" + tests: "cron" + - version: "1.21.0-1-rc0" + image: codeberg.org/forgejo-experimental/forgejo + tests: "echo artifacts pull-request service container expression local-action docker-action if if-fail" - version: "1.20" image: codeberg.org/forgejo/forgejo tests: "echo service container expression local-action docker-action if if-fail" From 06709db2c586a1f242697ac68807dbd21366455c Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Fri, 29 Sep 2023 19:17:38 +0200 Subject: [PATCH 3/6] use code.forgejo.org/oci as an OCI registry --- forgejo-runner.sh | 2 +- testdata/example-cron/.forgejo/workflows/test.yml | 2 +- testdata/example-cron/runner-config.yaml | 2 +- testdata/example-pull-request/.forgejo/workflows/test.yml | 2 +- testdata/example-pull-request/runner-config.yaml | 2 +- testdata/example-service/.forgejo/workflows/postgresql.yml | 4 ++-- testdata/example-service/.forgejo/workflows/volume.yml | 6 +++--- testdata/example-service/runner-config.yaml | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/forgejo-runner.sh b/forgejo-runner.sh index 228a1bb..dd9de5d 100755 --- a/forgejo-runner.sh +++ b/forgejo-runner.sh @@ -24,7 +24,7 @@ function download() { function register() { local forgejo="$1" docker exec --user 1000 forgejo forgejo actions generate-runner-token > forgejo-runner-token - timeout --signal=KILL 30 forgejo-runner register --no-interactive --instance "$forgejo" --name runner --token $(cat forgejo-runner-token) --labels docker:docker://node:16-bullseye,ubuntu-latest:docker://node:16-buster,self-hosted + timeout --signal=KILL 30 forgejo-runner register --no-interactive --instance "$forgejo" --name runner --token $(cat forgejo-runner-token) --labels docker:docker://code.forgejo.org/oci/node:16-bullseye,ubuntu-latest:docker://code.forgejo.org/oci/node:16-buster,self-hosted } function run() { diff --git a/testdata/example-cron/.forgejo/workflows/test.yml b/testdata/example-cron/.forgejo/workflows/test.yml index e1c2b87..c81b017 100644 --- a/testdata/example-cron/.forgejo/workflows/test.yml +++ b/testdata/example-cron/.forgejo/workflows/test.yml @@ -6,7 +6,7 @@ jobs: test: runs-on: docker container: - image: debian:bookworm + image: code.forgejo.org/oci/debian:bookworm options: "--volume /srv/example-cron-volume:/srv/example-cron-volume" steps: diff --git a/testdata/example-cron/runner-config.yaml b/testdata/example-cron/runner-config.yaml index bc5d862..119cde4 100644 --- a/testdata/example-cron/runner-config.yaml +++ b/testdata/example-cron/runner-config.yaml @@ -10,7 +10,7 @@ runner: insecure: false fetch_timeout: 5s fetch_interval: 2s - labels: [] + labels: ["docker:docker://code.forgejo.org/oci/node:16-bullseye"] cache: enabled: false diff --git a/testdata/example-pull-request/.forgejo/workflows/test.yml b/testdata/example-pull-request/.forgejo/workflows/test.yml index 1e6ad0b..a05f961 100644 --- a/testdata/example-pull-request/.forgejo/workflows/test.yml +++ b/testdata/example-pull-request/.forgejo/workflows/test.yml @@ -9,7 +9,7 @@ jobs: test: runs-on: docker container: - image: debian:bookworm + image: code.forgejo.org/oci/debian:bookworm options: "--volume /srv/example-pull-request:/srv/example-pull-request" steps: diff --git a/testdata/example-pull-request/runner-config.yaml b/testdata/example-pull-request/runner-config.yaml index 7f7d9cc..e9f4aeb 100644 --- a/testdata/example-pull-request/runner-config.yaml +++ b/testdata/example-pull-request/runner-config.yaml @@ -10,7 +10,7 @@ runner: insecure: false fetch_timeout: 5s fetch_interval: 2s - labels: [] + labels: ["docker:docker://code.forgejo.org/oci/node:16-bullseye"] cache: enabled: false diff --git a/testdata/example-service/.forgejo/workflows/postgresql.yml b/testdata/example-service/.forgejo/workflows/postgresql.yml index f600b17..9d9d30e 100644 --- a/testdata/example-service/.forgejo/workflows/postgresql.yml +++ b/testdata/example-service/.forgejo/workflows/postgresql.yml @@ -4,11 +4,11 @@ jobs: test: runs-on: docker container: - image: debian:bookworm + image: code.forgejo.org/oci/debian:bookworm services: pgsql: - image: postgres:15 + image: code.forgejo.org/oci/postgres:15 env: POSTGRES_DB: test POSTGRES_PASSWORD: postgres diff --git a/testdata/example-service/.forgejo/workflows/volume.yml b/testdata/example-service/.forgejo/workflows/volume.yml index e3c240e..0649f50 100644 --- a/testdata/example-service/.forgejo/workflows/volume.yml +++ b/testdata/example-service/.forgejo/workflows/volume.yml @@ -7,7 +7,7 @@ jobs: volume-on-step: runs-on: docker container: - image: debian:bookworm + image: code.forgejo.org/oci/debian:bookworm options: "--volume /srv/example-service-volume-valid:/srv/example-service-volume-valid --volume /srv/example-service-volume-invalid:/srv/example-service-volume-invalid" steps: @@ -21,12 +21,12 @@ jobs: volume-on-service: runs-on: docker container: - image: debian:bookworm + image: code.forgejo.org/oci/debian:bookworm options: "--volume /srv/example-service-volume-valid:/srv/example-service-volume-valid" services: myservice: - image: debian:bookworm + image: code.forgejo.org/oci/debian:bookworm options: "--volume /srv/example-service-volume-valid:/srv/example-service-volume-valid" cmd: ["bash", "-c", "echo -n SUCCESS > /srv/example-service-volume-valid ; sleep infinity"] diff --git a/testdata/example-service/runner-config.yaml b/testdata/example-service/runner-config.yaml index 95ea4cb..4606852 100644 --- a/testdata/example-service/runner-config.yaml +++ b/testdata/example-service/runner-config.yaml @@ -10,7 +10,7 @@ runner: insecure: false fetch_timeout: 5s fetch_interval: 2s - labels: [] + labels: ["docker:docker://code.forgejo.org/oci/node:16-bullseye"] cache: enabled: false From fdd4ccf4c306d9f87597d94de9c9d8882002a43f Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Fri, 29 Sep 2023 20:19:00 +0200 Subject: [PATCH 4/6] use vars to control the jobs --- .forgejo/workflows/integration.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.forgejo/workflows/integration.yml b/.forgejo/workflows/integration.yml index 11313ac..dc3b06f 100644 --- a/.forgejo/workflows/integration.yml +++ b/.forgejo/workflows/integration.yml @@ -8,16 +8,14 @@ jobs: info: - version: "1.21.0-1-rc0" image: codeberg.org/forgejo-experimental/forgejo - tests: "cron" - - version: "1.21.0-1-rc0" - image: codeberg.org/forgejo-experimental/forgejo - tests: "echo artifacts pull-request service container expression local-action docker-action if if-fail" + tests: "${{ vars.V121_TESTS || 'echo artifacts pull-request service container expression local-action docker-action if if-fail cron' }}" - version: "1.20" image: codeberg.org/forgejo/forgejo - tests: "echo service container expression local-action docker-action if if-fail" + tests: "${{ vars.V120_TESTS || 'echo service container expression local-action docker-action if if-fail' }}" steps: - uses: actions/checkout@v3 - - run: | + - if: matrix.info.tests != 'none' + run: | set -x LXC_IP_PREFIX=10.0.10 ./forgejo-dependencies.sh export PATH=$(pwd):$PATH From 64e3b2e23e54d04a1fc10f9cc6364282d29942a5 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Fri, 29 Sep 2023 22:57:05 +0200 Subject: [PATCH 5/6] show all statuses on failure --- forgejo-test-helper.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/forgejo-test-helper.sh b/forgejo-test-helper.sh index adc5d18..64e160a 100755 --- a/forgejo-test-helper.sh +++ b/forgejo-test-helper.sh @@ -44,12 +44,20 @@ function build_runner() { forgejo-runner --version } +function get_status() { + local url="$1" + local repo="$2" + local sha="$3" + + forgejo-curl.sh api_json $url/api/v1/repos/$repo/commits/$sha/status +} + function check_status() { local url="$1" local repo="$2" local sha="$3" - local state=$(forgejo-curl.sh api_json $url/api/v1/repos/$repo/commits/$sha/status | jq --raw-output .state) + local state=$(get_status $url $repo $sha | jq --raw-output .state) echo $state test "$state" != "" -a "$state" != "pending" -a "$state" != "running" -a "$state" != "null" } @@ -67,8 +75,8 @@ function wait_success() { sleep $LOOP_DELAY done if ! test "$(check_status "$url" "$repo" "$sha")" = "success" ; then + get_status $url $repo $sha | jq .statuses test "$FORGEJO_RUNNER_LOGS" && cat $FORGEJO_RUNNER_LOGS - forgejo-curl.sh api_json $url/api/v1/repos/$repo/commits/$sha/status | jq . return 1 fi } From 3b72d00aadfdb92ff0ddd763c76f9c22b3fe2396 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Sat, 30 Sep 2023 00:21:45 +0200 Subject: [PATCH 6/6] dedicated environment for the non-trivial tests --- .forgejo/workflows/integration.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.forgejo/workflows/integration.yml b/.forgejo/workflows/integration.yml index dc3b06f..7208ff0 100644 --- a/.forgejo/workflows/integration.yml +++ b/.forgejo/workflows/integration.yml @@ -8,7 +8,16 @@ jobs: info: - version: "1.21.0-1-rc0" image: codeberg.org/forgejo-experimental/forgejo - tests: "${{ vars.V121_TESTS || 'echo artifacts pull-request service container expression local-action docker-action if if-fail cron' }}" + tests: "service" + - version: "1.21.0-1-rc0" + image: codeberg.org/forgejo-experimental/forgejo + tests: "artifacts" + - version: "1.21.0-1-rc0" + image: codeberg.org/forgejo-experimental/forgejo + tests: "cron" + - version: "1.21.0-1-rc0" + image: codeberg.org/forgejo-experimental/forgejo + tests: "${{ vars.V121_TESTS || 'echo pull-request container expression local-action docker-action if if-fail' }}" - version: "1.20" image: codeberg.org/forgejo/forgejo tests: "${{ vars.V120_TESTS || 'echo service container expression local-action docker-action if if-fail' }}"