|
| 1 | +# Some workflows depend on the base branch of the PR, but changing the base branch is not included in the default trigger events, which would be `opened`, `synchronize` or `reopened`. |
| 2 | +# Instead it causes an `edited` event. |
| 3 | +# Since `edited` is also triggered when PR title/body is changed, we use this wrapper workflow, to run the other workflows conditionally only. |
| 4 | +# There are already feature requests for adding a `base_changed` event: |
| 5 | +# - https://github.com/orgs/community/discussions/35058 |
| 6 | +# - https://github.com/orgs/community/discussions/64119 |
| 7 | +# |
| 8 | +# Instead of adding this to each workflow's pull_request_target event, we trigger this in a separate workflow. |
| 9 | +# This has the advantage, that we can actually skip running those jobs for simple edits like changing the title or description. |
| 10 | +# The actual trigger happens by closing and re-opening the pull request, which triggers the default pull_request_target events. |
| 11 | +# This is much simpler and reliable than other approaches. |
| 12 | + |
| 13 | +name: "Edited base branch" |
| 14 | + |
| 15 | +on: |
| 16 | + pull_request_target: |
| 17 | + types: [edited] |
| 18 | + |
| 19 | +permissions: {} |
| 20 | + |
| 21 | +jobs: |
| 22 | + base: |
| 23 | + name: Trigger jobs |
| 24 | + runs-on: ubuntu-24.04 |
| 25 | + if: github.event.changes.base.ref.from && github.event.changes.base.ref.from != github.event.pull_request.base.ref |
| 26 | + steps: |
| 27 | + # Use a GitHub App to create the PR so that CI gets triggered |
| 28 | + # The App is scoped to Repository > Contents and Pull Requests: write for Nixpkgs |
| 29 | + # We only need Pull Requests: write here, but the app is also used for backports. |
| 30 | + - uses: actions/create-github-app-token@df432ceedc7162793a195dd1713ff69aefc7379e # v2.0.6 |
| 31 | + id: app-token |
| 32 | + with: |
| 33 | + app-id: ${{ vars.NIXPKGS_CI_APP_ID }} |
| 34 | + private-key: ${{ secrets.NIXPKGS_CI_APP_PRIVATE_KEY }} |
| 35 | + permission-pull-requests: write |
| 36 | + |
| 37 | + - env: |
| 38 | + GH_TOKEN: ${{ steps.app-token.outputs.token }} |
| 39 | + REPOSITORY: ${{ github.repository }} |
| 40 | + NUMBER: ${{ github.event.number }} |
| 41 | + run: | |
| 42 | + gh api \ |
| 43 | + --method PATCH \ |
| 44 | + /repos/"$REPOSITORY"/pulls/"$NUMBER" \ |
| 45 | + -f "state=closed" |
| 46 | + gh api \ |
| 47 | + --method PATCH \ |
| 48 | + /repos/"$REPOSITORY"/pulls/"$NUMBER" \ |
| 49 | + -f "state=open" |
0 commit comments