diff --git a/.forgejo/cascading-forgejo b/.forgejo/cascading-forgejo new file mode 100755 index 00000000..a85a53b0 --- /dev/null +++ b/.forgejo/cascading-forgejo @@ -0,0 +1,37 @@ +#!/bin/bash + +set -ex + +forgejo=$1 +forgejo_pr=$2 +runner=$3 +runner_pr_or_ref=$4 + +# +# Get information from the runner +# +cd $runner +# +# code.forgejo.org/forgejo/runner/vN may be +# upgraded to code.forgejo.org/forgejo/runner/vN+1 +# +module=$(cat go.mod | head -1 | cut -d' ' -f2) +test "$module" +sha=$(git -C $runner show --no-patch --format=%H) +test "$sha" + +# +# Update Forgejo to use the runner at $runner_pr_or_ref +# +cd $forgejo +# +# Update the runner major version if needed +# +find * -name '*.go' -o -name 'go.mod' | xargs sed -i -E -e "s|code.forgejo.org/forgejo/runner/v[0-9]+|$module|" +# +# add a "replace code.forgejo.org/forgejo/runner/v?? $sha" line to the forgejo go.mod +# so that it uses the branch or pull request from which the cascade is run. +# +sed -i -e "\|replace $module|d" go.mod +echo "replace $module => $module $sha" >>go.mod +go mod tidy diff --git a/.forgejo/workflows/cascade-forgejo.yml b/.forgejo/workflows/cascade-forgejo.yml new file mode 100644 index 00000000..350af17b --- /dev/null +++ b/.forgejo/workflows/cascade-forgejo.yml @@ -0,0 +1,88 @@ +# Copyright 2025 The Forgejo Authors +# SPDX-License-Identifier: MIT +# +# FORGEJO_CASCADING_PR_ORIGIN_TOKEN is a token from the https://code.forgejo.org/cascading-pr user +# with scope write:issue read:repository read:user +# FORGEJO_CASCADING_PR_DESTINATION_TOKEN is a token from the https://codeberg.org/forgejo-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: + push: + branches: + - 'main' + - 'wip-cascade' + pull_request_target: + types: + - synchronize + - labeled + +enable-email-notifications: true + +jobs: + 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' + ${{ toJSON(forge.event) }} + EOF + + forgejo: + if: > + vars.ROLE == 'forgejo-coding' && ( + forge.ref_name == 'main' || + forge.ref_name == 'wip-cascade' || + contains(github.event.pull_request.labels.*.name, 'run-forgejo-tests') + ) + + runs-on: docker + container: + image: data.forgejo.org/oci/node:22-bookworm + steps: + - uses: https://data.forgejo.org/actions/checkout@v4 + with: + fetch-depth: '0' + show-progress: 'false' + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + - uses: https://data.forgejo.org/actions/cascading-pr@v2.2.1 + with: + origin-url: ${{ forge.server_url }} + origin-repo: ${{ forge.repository }} + origin-token: ${{ secrets.FORGEJO_CASCADING_PR_ORIGIN_TOKEN }} + origin-pr: ${{ forge.event.pull_request.number }} + origin-ref: ${{ forge.event_name == 'push' && forge.event.ref || '' }} + destination-url: https://codeberg.org + destination-fork-repo: forgejo-cascading-pr/forgejo + destination-repo: forgejo/forgejo + destination-branch: forgejo + destination-token: ${{ secrets.FORGEJO_CASCADING_PR_DESTINATION_TOKEN }} + prefix: runner + close-merge: true + verbose: ${{ vars.VERBOSE == 'yes' }} + debug: ${{ vars.DEBUG == 'yes' }} + update: .forgejo/cascading-forgejo