1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-09-15 18:57:01 +00:00

chore: unify cascade-setup-forgejo with cascade-forgejo (#919)

Tested out of the wip-cascade branch:

- https://code.forgejo.org/forgejo/runner/actions/runs/8746
- https://code.forgejo.org/actions/setup-forgejo/pulls/646
- https://code.forgejo.org/forgejo/end-to-end/pulls/984

----

Instead of always running end-to-end tests, only run them when the
run-end-to-end-tests label is set. They are heavy duty and should not
be run when a new contributor sends their first pull request.

- fix bug: close-merge is close
- add instructions for debug
- identify the origin of the tokens
- do not needlessly run setup-forgejo integration tests
- copy/paste from cascade-forgejo.yml with the following exceptions:
  - do not trigger on main
  - use run-end-to-end-test instead of run-forgejo-test

<!--start release-notes-assistant-->
<!--URL:https://code.forgejo.org/forgejo/runner-->
- other
  - [PR](https://code.forgejo.org/forgejo/runner/pulls/919): <!--number 919 --><!--line 0 --><!--description Y2hvcmU6IHVuaWZ5IGNhc2NhZGUtc2V0dXAtZm9yZ2VqbyB3aXRoIGNhc2NhZGUtZm9yZ2Vqbw==-->chore: unify cascade-setup-forgejo with cascade-forgejo<!--description-->
<!--end release-notes-assistant-->

Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/919
Reviewed-by: Mathieu Fenniak <mfenniak@noreply.code.forgejo.org>
Co-authored-by: Earl Warren <contact@earl-warren.org>
Co-committed-by: Earl Warren <contact@earl-warren.org>
This commit is contained in:
Earl Warren 2025-08-29 08:45:53 +00:00 committed by earl-warren
parent bbb2cdd9f7
commit 04801dedd5
No known key found for this signature in database
GPG key ID: F128CBE6AB3A7201
4 changed files with 102 additions and 26 deletions

View file

@ -1,16 +0,0 @@
#!/bin/bash
set -ex
setup_forgejo=$1
setup_forgejo_pr=$2
runner=$3
runner_pr=$4
url=$(jq --raw-output .head.repo.html_url < $runner_pr)
test "$url" != null
branch=$(jq --raw-output .head.ref < $runner_pr)
test "$branch" != null
cd $setup_forgejo
./utils/upgrade-runner.sh $url @$branch
date > last-upgrade

View file

@ -0,0 +1,24 @@
#!/bin/bash
set -ex
setup_forgejo=$1
setup_forgejo_pr=$2
runner=$3
runner_pr_or_ref=$4
if test -f "$runner_pr_or_ref"; then
url=$(jq --raw-output .head.repo.html_url <$runner_pr)
test "$url" != null
branch=$(jq --raw-output .head.ref <$runner_pr)
else
url=https://code.forgejo.org/forgejo/runner
branch=${runner_pr_or_ref#refs/heads/}
fi
test "$url"
test "$branch"
test "$branch" != null
cd $setup_forgejo
./utils/upgrade-runner.sh $url @$branch
rm -f .forgejo/workflows/integration*.yml
date >last-upgrade

View file

@ -1,31 +1,99 @@
# Copyright 2025 The Forgejo Authors
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
#
# CASCADING_PR_ORIGIN is a token from the https://code.forgejo.org/cascading-pr user
# with scope write:issue read:repository read:user
# CASCADING_PR_DESTINATION is a token from the https://code.forgejo.org/cascading-pr user
# with scope write:issue write:repository read:user
#
# To modify this workflow:
#
# - push it to the wip-cascade branch on the repository
# otherwise it will not have access to the secrets required to push
# the cascading PR
#
# - once it works, open a pull request for the sake of keeping track
# of the change even if the PR won't run it because it will use
# whatever is in the default branch instead
#
# - after it is merged, double check it works by setting the
# label on a pull request (any pull request will do)
#
name: cascade
on: on:
push:
branches:
- 'wip-cascade'
pull_request_target: pull_request_target:
types: types:
- opened
- synchronize - synchronize
- labeled
- closed - closed
enable-email-notifications: true enable-email-notifications: true
jobs: jobs:
cascade: debug:
if: >
vars.DEBUG == 'yes'
runs-on: docker
container:
image: data.forgejo.org/oci/node:22-bookworm
steps:
- name: event
run: |
cat <<'EOF'
${{ toJSON(forge.event.pull_request.labels.*.name) }}
EOF
cat <<'EOF'
push => ${{ forge.event_name == 'push' && ( forge.ref_name == 'wip-cascade') }}
pull_request_target synchornized => ${{ ( forge.event.action == 'synchronized' && contains(forge.event.pull_request.labels.*.name, 'run-end-to-end-tests') ) }}
pull_request_target label_updated => ${{ ( forge.event.action == 'label_updated' && forge.event.label.name == 'run-end-to-end-tests' ) }}
contains => ${{ contains(forge.event.pull_request.labels.*.name, 'run-end-to-end-tests') }}
contains boolean => ${{ contains(forge.event.pull_request.labels.*.name, 'run-end-to-end-tests') == true }}
EOF
cat <<'EOF'
${{ toJSON(forge) }}
EOF
end-to-end:
#
# Always run when a commit is pushed to the wip-cascade branch
# If this is a pull request, run
# - when the `run-end-to-end-tests` label is set (label_updated) (but not if another label is set or if a label is removed)
# - when a new commit is pushed to the pull request (synchronized) if the `run-end-to-end-tests` is already present
# - when the pull request is closed, which also happens when it is merged, so that the setup-forgejo & end-to-end pull requests are closed
#
if: >
vars.ROLE == 'forgejo-coding' && (
(
forge.event_name == 'push' && ( forge.ref_name == 'wip-cascade' )
) || (
forge.event_name == 'pull_request_target' && (
forge.event.action == 'closed' ||
( forge.event.action == 'synchronized' && contains(forge.event.pull_request.labels.*.name, 'run-end-to-end-tests') ) ||
( forge.event.action == 'label_updated' && forge.event.label.name == 'run-end-to-end-tests' )
)
)
)
runs-on: docker runs-on: docker
container: container:
image: 'code.forgejo.org/oci/node:22-bookworm' image: 'code.forgejo.org/oci/node:22-bookworm'
if: >
! contains(forge.event.pull_request.title, '[skip cascade]')
steps: steps:
- uses: https://code.forgejo.org/actions/cascading-pr@v2.2.1 - uses: https://code.forgejo.org/actions/cascading-pr@v2.2.1
with: with:
origin-url: ${{ env.FORGEJO_SERVER_URL }} origin-url: ${{ forge.server_url }}
origin-repo: forgejo/runner origin-repo: ${{ forge.repository }}
origin-token: ${{ secrets.CASCADING_PR_ORIGIN }} origin-token: ${{ secrets.CASCADING_PR_ORIGIN }}
origin-pr: ${{ forge.event.pull_request.number }} origin-pr: ${{ forge.event.pull_request.number }}
destination-url: ${{ env.FORGEJO_SERVER_URL }} origin-ref: ${{ forge.event_name == 'push' && forge.event.ref || '' }}
destination-url: ${{ forge.server_url }}
destination-repo: actions/setup-forgejo destination-repo: actions/setup-forgejo
destination-fork-repo: cascading-pr/setup-forgejo destination-fork-repo: cascading-pr/setup-forgejo
destination-branch: main destination-branch: main
destination-token: ${{ secrets.CASCADING_PR_DESTINATION }} destination-token: ${{ secrets.CASCADING_PR_DESTINATION }}
close-merge: true close: true
update: .forgejo/cascading-pr-setup-forgejo verbose: ${{ vars.VERBOSE == 'yes' }}
debug: ${{ vars.DEBUG == 'yes' }}
update: .forgejo/cascading-setup-forgejo

View file

@ -9,6 +9,6 @@
"separateMinorPatch": true "separateMinorPatch": true
} }
], ],
"labels": ["Kind/Chore"], "labels": ["Kind/Chore", "run-end-to-end-tests"],
"ignorePaths": ["**/testdata/**", "**/node_modules/**"] "ignorePaths": ["**/testdata/**", "**/node_modules/**"]
} }