From cd1a0f5076c34ad203036c806c4c2d452e1487fa Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Sun, 6 Jul 2025 12:15:38 +0000 Subject: [PATCH] chore: add assertions for the forge context and use it instead of github where relevant (#748) Refs forgejo/act#37 Reviewed-on: https://code.forgejo.org/forgejo/end-to-end/pulls/748 Reviewed-by: Michael Kriese Co-authored-by: Earl Warren Co-committed-by: Earl Warren --- .forgejo/workflows/end-to-end.yml | 4 ++-- .../example-context/.forgejo/workflows/test.yml | 17 +++++++++++++++++ .../action-for-context/action.yml | 2 ++ .../.forgejo/workflows/test.yml | 4 ++-- .../.forgejo/workflows/test.yml | 8 ++++---- 5 files changed, 27 insertions(+), 8 deletions(-) diff --git a/.forgejo/workflows/end-to-end.yml b/.forgejo/workflows/end-to-end.yml index 3ab7a47b..d535d37d 100644 --- a/.forgejo/workflows/end-to-end.yml +++ b/.forgejo/workflows/end-to-end.yml @@ -108,7 +108,7 @@ jobs: actions-docs: needs: [build] runs-on: lxc-bookworm - if: github.ref == 'refs/heads/main' + if: forge.ref == 'refs/heads/main' strategy: matrix: info: @@ -135,7 +135,7 @@ jobs: uses: https://data.forgejo.org/actions/cascading-pr@v2.1 with: origin-url: ${{ env.GITHUB_SERVER_URL }} - origin-repo: ${{ github.repository }} + origin-repo: ${{ forge.repository }} origin-token: ${{ secrets.CASCADE_DOCS_ORIGIN_TOKEN }} origin-ref: refs/heads/main destination-url: https://codeberg.org diff --git a/actions/example-context/.forgejo/workflows/test.yml b/actions/example-context/.forgejo/workflows/test.yml index a894bfd2..0f9db31b 100644 --- a/actions/example-context/.forgejo/workflows/test.yml +++ b/actions/example-context/.forgejo/workflows/test.yml @@ -21,6 +21,7 @@ jobs: echo "$GITHUB_ACTION" | grep -E '^[0-9]+$' test "$GITHUB_ACTION" = "${{ env.GITHUB_ACTION }}" test "$GITHUB_ACTION" = "${{ github.ACTION }}" + test "$GITHUB_ACTION" = "${{ forge.ACTION }}" # See also actions/example-local-action/.forgejo/local-action/action.yml - name: GITHUB_ACTION_PATH @@ -29,6 +30,7 @@ jobs: test -z "$GITHUB_ACTION_PATH" test "$GITHUB_ACTION_PATH" = "${{ env.GITHUB_ACTION_PATH }}" test "$GITHUB_ACTION_PATH" = "${{ github.ACTION_PATH }}" + test "$GITHUB_ACTION_PATH" = "${{ forge.ACTION_PATH }}" - name: when running an action if: ${{ env.GITHUB_ACTIONS }} @@ -54,6 +56,7 @@ jobs: test "$GITHUB_ACTOR" test "$GITHUB_ACTOR" = "${{ env.GITHUB_ACTOR }}" test "$GITHUB_ACTOR" = "${{ github.ACTOR }}" + test "$GITHUB_ACTOR" = "${{ forge.ACTOR }}" - name: GITHUB_API_URL shell: bash @@ -62,6 +65,7 @@ jobs: [[ "$GITHUB_API_URL" =~ /api/v1$ ]] test "$GITHUB_API_URL" = "${{ env.GITHUB_API_URL }}" test "$GITHUB_API_URL" = "${{ github.API_URL }}" + test "$GITHUB_API_URL" = "${{ forge.API_URL }}" # See also actions/example-pull-request/.forgejo/workflows/test.yml - name: GITHUB_BASE_REF @@ -70,6 +74,7 @@ jobs: test -z "$GITHUB_BASE_REF" test "$GITHUB_BASE_REF" = "${{ env.GITHUB_BASE_REF }}" test "$GITHUB_BASE_REF" = "${{ github.BASE_REF }}" + test "$GITHUB_BASE_REF" = "${{ forge.BASE_REF }}" # See also actions/example-pull-request/.forgejo/workflows/test.yml - name: GITHUB_HEAD_REF @@ -78,6 +83,7 @@ jobs: test -z "$GITHUB_HEAD_REF" test "$GITHUB_HEAD_REF" = "${{ env.GITHUB_HEAD_REF }}" test "$GITHUB_HEAD_REF" = "${{ github.HEAD_REF }}" + test "$GITHUB_HEAD_REF" = "${{ forge.HEAD_REF }}" - name: GITHUB_ENV run: | @@ -91,6 +97,7 @@ jobs: test "$GITHUB_EVENT_NAME" = push test "$GITHUB_EVENT_NAME" = "${{ env.GITHUB_EVENT_NAME }}" test "$GITHUB_EVENT_NAME" = "${{ github.EVENT_NAME }}" + test "$GITHUB_EVENT_NAME" = "${{ forge.EVENT_NAME }}" - name: GITHUB_JOB run: | @@ -98,6 +105,7 @@ jobs: test "$GITHUB_JOB" = test test "$GITHUB_JOB" = "${{ env.GITHUB_JOB }}" test "$GITHUB_JOB" = "${{ github.JOB }}" + test "$GITHUB_JOB" = "${{ forge.JOB }}" - name: GITHUB_OUTPUT run: | @@ -118,6 +126,7 @@ jobs: [[ "$GITHUB_REF" =~ ^refs/ ]] test "$GITHUB_REF" = "${{ env.GITHUB_REF }}" test "$GITHUB_REF" = "${{ github.REF }}" + test "$GITHUB_REF" = "${{ forge.REF }}" - name: GITHUB_REF_NAME shell: bash @@ -126,6 +135,7 @@ jobs: ! [[ "$GITHUB_REF_NAME" =~ ^refs/ ]] test "$GITHUB_REF_NAME" = "${{ env.GITHUB_REF_NAME }}" test "$GITHUB_REF_NAME" = "${{ github.REF_NAME }}" + test "$GITHUB_REF_NAME" = "${{ forge.REF_NAME }}" - name: GITHUB_REPOSITORY run: | @@ -133,6 +143,7 @@ jobs: test "$GITHUB_REPOSITORY" = root/example-context test "$GITHUB_REPOSITORY" = "${{ env.GITHUB_REPOSITORY }}" test "$GITHUB_REPOSITORY" = "${{ github.REPOSITORY }}" + test "$GITHUB_REPOSITORY" = "${{ forge.REPOSITORY }}" - name: GITHUB_REPOSITORY_OWNER run: | @@ -140,6 +151,7 @@ jobs: test "$GITHUB_REPOSITORY_OWNER" = root test "$GITHUB_REPOSITORY_OWNER" = "${{ env.GITHUB_REPOSITORY_OWNER }}" test "$GITHUB_REPOSITORY_OWNER" = "${{ github.REPOSITORY_OWNER }}" + test "$GITHUB_REPOSITORY_OWNER" = "${{ forge.REPOSITORY_OWNER }}" - name: GITHUB_RUN_NUMBER run: | @@ -147,6 +159,7 @@ jobs: echo "$GITHUB_RUN_NUMBER" | grep -E '^[0-9]+$' test "$GITHUB_RUN_NUMBER" = "${{ env.GITHUB_RUN_NUMBER }}" test "$GITHUB_RUN_NUMBER" = "${{ github.RUN_NUMBER }}" + test "$GITHUB_RUN_NUMBER" = "${{ forge.RUN_NUMBER }}" - name: GITHUB_SERVER_URL shell: bash @@ -155,6 +168,7 @@ jobs: [[ "$GITHUB_SERVER_URL" =~ ^http ]] test "$GITHUB_SERVER_URL" = "${{ env.GITHUB_SERVER_URL }}" test "$GITHUB_SERVER_URL" = "${{ github.SERVER_URL }}" + test "$GITHUB_SERVER_URL" = "${{ forge.SERVER_URL }}" - name: GITHUB_SHA run: | @@ -162,6 +176,7 @@ jobs: test "$GITHUB_SHA" test "$GITHUB_SHA" = "${{ env.GITHUB_SHA }}" test "$GITHUB_SHA" = "${{ github.SHA }}" + test "$GITHUB_SHA" = "${{ forge.SHA }}" - name: GITHUB_STEP_SUMMARY run: | @@ -176,6 +191,7 @@ jobs: test "$GITHUB_TOKEN" test "$GITHUB_TOKEN" = "${{ env.GITHUB_TOKEN }}" test "$GITHUB_TOKEN" = "${{ github.TOKEN }}" + test "$GITHUB_TOKEN" = "${{ forge.TOKEN }}" - name: GITHUB_WORKSPACE run: | @@ -183,6 +199,7 @@ jobs: test -d "$GITHUB_WORKSPACE" test "$GITHUB_WORKSPACE" = "${{ env.GITHUB_WORKSPACE }}" test "$GITHUB_WORKSPACE" = "${{ github.WORKSPACE }}" + test "$GITHUB_WORKSPACE" = "${{ forge.WORKSPACE }}" - name: RUNNER_ARCH run: | diff --git a/actions/example-context/action-for-context/action.yml b/actions/example-context/action-for-context/action.yml index dcb8f2b7..c1c33843 100644 --- a/actions/example-context/action-for-context/action.yml +++ b/actions/example-context/action-for-context/action.yml @@ -12,6 +12,7 @@ runs: test "$GITHUB_ACTION_REPOSITORY" = root/action-for-context test "$GITHUB_ACTION_REPOSITORY" = "${{ env.GITHUB_ACTION_REPOSITORY }}" test "$GITHUB_ACTION_REPOSITORY" = "${{ github.ACTION_REPOSITORY }}" + test "$GITHUB_ACTION_REPOSITORY" = "${{ forge.ACTION_REPOSITORY }}" touch /srv/example/example-context/GITHUB_ACTION_REPOSITORY - name: GITHUB_ACTION_PATH @@ -20,4 +21,5 @@ runs: set -x [[ "$GITHUB_ACTION_PATH" =~ action-for-context@main$ ]] test "$GITHUB_ACTION_PATH" = "${{ github.ACTION_PATH }}" + test "$GITHUB_ACTION_PATH" = "${{ forge.ACTION_PATH }}" touch /srv/example/example-context/GITHUB_ACTION_PATH diff --git a/actions/example-docker-action/.forgejo/workflows/test.yml b/actions/example-docker-action/.forgejo/workflows/test.yml index 6bc63c6d..cec2c9db 100644 --- a/actions/example-docker-action/.forgejo/workflows/test.yml +++ b/actions/example-docker-action/.forgejo/workflows/test.yml @@ -9,11 +9,11 @@ jobs: # - uses: https://data.forgejo.org/forgejo/test-setup-forgejo-docker@main with: - args: ${{ github.workspace }}/SOMEFILE + args: ${{ forge.workspace }}/SOMEFILE # # ... which then also exists in the job workspace # because both docker containers are automatically # sharing the volume that contains it. # - run: | - test -f ${{ github.workspace }}/SOMEFILE + test -f ${{ forge.workspace }}/SOMEFILE diff --git a/actions/example-pull-request/.forgejo/workflows/test.yml b/actions/example-pull-request/.forgejo/workflows/test.yml index 829d9221..2b864cb6 100644 --- a/actions/example-pull-request/.forgejo/workflows/test.yml +++ b/actions/example-pull-request/.forgejo/workflows/test.yml @@ -18,7 +18,7 @@ jobs: run: | set -x test $GITHUB_TOKEN = ${{ env.GITHUB_TOKEN }} - test $GITHUB_TOKEN = ${{ github.token }} + test $GITHUB_TOKEN = ${{ forge.token }} export DEBIAN_FRONTEND=noninteractive ; apt-get -qq update ; apt-get install -y -qq curl git >& /dev/null curl -sS -o /usr/local/bin/forgejo-curl.sh https://code.forgejo.org/forgejo/forgejo-curl/raw/branch/main/forgejo-curl.sh && chmod +x /usr/local/bin/forgejo-curl.sh forgejo-curl.sh --token "$GITHUB_TOKEN" login $GITHUB_SERVER_URL @@ -27,7 +27,7 @@ jobs: - name: determine if the PR is from a fork id: forked run: | - if test ${{ github.event.pull_request.base.repo.full_name }} = ${{ github.event.pull_request.head.repo.full_name }} ; then + if test ${{ forge.event.pull_request.base.repo.full_name }} = ${{ forge.event.pull_request.head.repo.full_name }} ; then echo value=false >> $GITHUB_OUTPUT else echo value=true >> $GITHUB_OUTPUT @@ -95,7 +95,7 @@ jobs: # # create an issue # - base_repo=${{ github.event.pull_request.base.repo.full_name }} + base_repo=${{ forge.event.pull_request.base.repo.full_name }} forgejo-curl.sh api_json --data-raw '{"title":"ISSUE"}' $GITHUB_SERVER_URL/api/v1/repos/$base_repo/issues url=$(echo $GITHUB_SERVER_URL | sed -e "s|://|://$GITHUB_TOKEN@|") git clone $url/$base_repo base @@ -133,7 +133,7 @@ jobs: - name: save event run: | - d=/srv/example/pull-request/contexts/${{ github.event.pull_request.head.repo.owner.username }}/$GITHUB_EVENT_NAME + d=/srv/example/pull-request/contexts/${{ forge.event.pull_request.head.repo.owner.username }}/$GITHUB_EVENT_NAME mkdir -p $d cat > $d/github <<'EOF' ${{ toJSON(github) }}