Skip to content

Commit 3d07399

Browse files
committed
[ci] use GitHub app token to create pull request
This modifies the cherry-pick workflow to use a lowRISC-managed GitHub token minter to generate an access token with ability to create pull_requests as the "lowrisc-ci" app. This allows GitHub action to trigger and bypass the restriction that actions performed by GitHub actions cannot itself trigger another GitHub actions (as a recursion prevention measure), and therefore allows CI to run on cherry-picked pull requests. Signed-off-by: Gary Guo <[email protected]>
1 parent b9010b9 commit 3d07399

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

.github/workflows/cherrypick.yml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ jobs:
2222
# default token. We should in the future move to a PAT owned by lowrisc-bot and create pull request
2323
# on its behalf.
2424
permissions:
25+
# Needed for authentication.
26+
id-token: write
2527
# Needed for the action to create branch.
2628
contents: write
27-
# Needed for the action to create a pull request.
28-
pull-requests: write
2929

3030
name: Cherry-pick Pull Request
3131
if: github.event.pull_request.merged == true && (github.event_name != 'labeled' || startsWith('CherryPick:', github.event.label.name))
@@ -35,23 +35,30 @@ jobs:
3535
with:
3636
ref: ${{ github.event.pull_request.head.sha }}
3737

38+
- name: Obtain token to create PR
39+
id: pr_token
40+
run: |
41+
# Obtain OIDC token from GitHub
42+
ID_TOKEN=$(curl -sSf -H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=https://ca.lowrisc.org" | jq -r .value)
43+
echo "::add-mask::$ID_TOKEN"
44+
# Exchange for a token to create PR
45+
PR_TOKEN=$(curl -sSf -X POST -H "Authorization: Bearer $ID_TOKEN" "https://ca.lowrisc.org/api/github/repos/${{ github.repository }}/token")
46+
echo "::add-mask::$PR_TOKEN"
47+
echo "pr_token=$PR_TOKEN" >> "$GITHUB_OUTPUT"
48+
3849
- name: Create backport PRs
3950
id: backport
4051
uses: korthout/backport-action@e8161d6a0dbfa2651b7daa76cbb75bc7c925bbf3 # v2.4.1
4152
with:
4253
label_pattern: "^CherryPick:([^ ]+)$"
4354
pull_title: "Cherry-pick to ${target_branch}: ${pull_title}"
55+
github_token: ${{ steps.pr_token.outputs.pr_token }}
4456
pull_description: |
4557
This is an automatic cherry-pick of #${pull_number} to branch `${target_branch}`.
4658
47-
> [!IMPORTANT]
48-
> This automated pull request cannot trigger CI tests itself.
49-
>
50-
> Please close and re-open the pull request manually to start CI.
51-
5259
- name: Apply label for manually cherry picking
5360
if: ${{ steps.backport.outputs.was_successful == 'false' }}
5461
env:
55-
GH_TOKEN: ${{ github.token }}
62+
GH_TOKEN: ${{ steps.pr_token.outputs.pr_token }}
5663
run: |
5764
gh pr edit ${{ github.event.pull_request.number }} --add-label 'Manually CherryPick'

0 commit comments

Comments
 (0)