From b9dd7fd7009c53b8e12f6c625995920c158748ce Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Thu, 30 Mar 2023 16:11:04 +0200 Subject: [PATCH] set FORGEJO_TOKEN in test workflows --- .forgejo/workflows/integration.yml | 4 ++-- README.md | 9 ++++++--- forgejo-test-helper.sh | 8 +++++--- testdata/sanity-checks/.forgejo/workflows/test.yml | 1 + 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.forgejo/workflows/integration.yml b/.forgejo/workflows/integration.yml index 46cf158..5822b44 100644 --- a/.forgejo/workflows/integration.yml +++ b/.forgejo/workflows/integration.yml @@ -10,7 +10,7 @@ jobs: ./forgejo.sh setup root admin1234 codeberg.org/forgejo/forgejo:1.19 ./forgejo-runner.sh setup export FORGEJO_RUNNER_LOGS=forgejo-runner.log - ./forgejo-test-helper.sh run_workflow testdata/demo http://root:admin1234@$(cat forgejo-ip):3000 root demo setup-forgejo > /tmp/output + ./forgejo-test-helper.sh run_workflow testdata/demo http://root:admin1234@$(cat forgejo-ip):3000 root demo setup-forgejo $(cat forgejo-token) > /tmp/output grep '^sha=' /tmp/output ./forgejo-test-helper.sh push_self_action http://root:admin1234@$(cat forgejo-ip):3000 root setup-forgejo vTest - ./forgejo-test-helper.sh run_workflow testdata/sanity-checks http://root:admin1234@$(cat forgejo-ip):3000 root sanity-check setup-forgejo + ./forgejo-test-helper.sh run_workflow testdata/sanity-checks http://root:admin1234@$(cat forgejo-ip):3000 root sanity-check setup-forgejo $(cat forgejo-token) diff --git a/README.md b/README.md index 1b220cb..a63e1c8 100644 --- a/README.md +++ b/README.md @@ -8,17 +8,20 @@ Setup Forgejo and a runner. The forgejo-test-helper.sh script is available to help test and debug actions. `forgejo=http://root:admin1234@${{ steps.forgejo.outputs.host-port }}` +`token=${{ steps.forgejo.outputs.token }}` * `forgejo-test-helper.sh push_self_action $forgejo root myaction vTest` Creates the repository `$forgejo/root/myaction` and populate it with the content of the repository under test, except for the `.forgejo` directory (it would otherwise create an infinite recursion loop). The tag `vTest` is set to the SHA under test. -* `forgejo-test-helper.sh run_workflow testrepo $forgejo root testrepo myaction` +* `forgejo-test-helper.sh run_workflow testrepo $forgejo root testrepo myaction $token` Create the repository `$forgejo/root/testrepo` and populate it with the content of the `testrepo` directory. All occurrences of `SELF` in `testrepo/.forgejo/workflows/*.yml` are replaced with `$forgejo/root/myaction`. -* `forgejo-test-helper.sh push testrepo $forgejo root testrepo` + All occurrences of `FORGEJO_TOKEN` `testrepo/.forgejo/workflows/*.yml` + are replaced with `$token`. +* `forgejo-test-helper.sh push testrepo $forgejo root testrepo $token` Create the repository `$forgejo/root/testrepo` and populate it with the content of the `testrepo` directory. The SHA of the tip of the repository is in the output, starting with `sha=`. @@ -67,7 +70,7 @@ jobs: steps: - uses: actions/checkout@v3 - id: forgejo - uses: setup-forgejo@v1 + uses: actions/setup-forgejo@v1 with: image-version: 1.19 - run: | diff --git a/forgejo-test-helper.sh b/forgejo-test-helper.sh index e2cd4b0..64ee849 100755 --- a/forgejo-test-helper.sh +++ b/forgejo-test-helper.sh @@ -45,6 +45,7 @@ function push() { local owner="$3" local project="$4" local self_action="$5" + local token="$6" local dir="$DIR/$project" rsync -a $directory/ $dir/ @@ -52,8 +53,8 @@ function push() { local workflows=$dir/.forgejo/workflows/*.yml if test "$(echo $workflows)" != "$workflows"; then sed -i \ - -e "s|SELF|$url/$owner/$self_action|" \ - -e "s|FORGEJO_URL|$url|" \ + -e "s|SELF|$url/$owner/$self_action|g" \ + -e "s|FORGEJO_TOKEN|$token|g" \ $dir/.forgejo/workflows/*.yml fi ( @@ -78,8 +79,9 @@ function run_workflow() { local owner="$3" local project="$4" local self_action="$5" + local token="$6" - push "$directory" "$url" "$owner" "$project" "$self_action" + push "$directory" "$url" "$owner" "$project" "$self_action" "$token" wait_success "$url" "$owner/$project" $(cat $DIR/$project/SHA) } diff --git a/testdata/sanity-checks/.forgejo/workflows/test.yml b/testdata/sanity-checks/.forgejo/workflows/test.yml index 6308bee..e8ab33e 100644 --- a/testdata/sanity-checks/.forgejo/workflows/test.yml +++ b/testdata/sanity-checks/.forgejo/workflows/test.yml @@ -13,5 +13,6 @@ jobs: - run: | set -ex test "${{ steps.forgejo.outputs.token }}" + test "FORGEJO_TOKEN" -a "FORGEJO_TOKEN" != F'O'RGEJO_TOKEN curl ${{ steps.forgejo.outputs.url }}/api/forgejo/v1/version | grep 1.19