Skip to content

Commit cc0bb65

Browse files
committed
ci: support per-user PAT for staging PR authorship
The staging PR opened by github-actions-on-label-create.yml is currently authored by the bot account behind STAGING_GITHUB_TOKEN, hiding the real contributor on the staging side. Add a token-resolution step that, when the PR author has stored a personal access token as repository secret PAT_<LOGIN> (uppercase, '-' -> '_'), uses it to call the PR-creation API so the staging PR is authored by them. Falls back to the bot token when no per-user PAT is configured, preserving today's behavior. Signed-off-by: Matt Liberty <mliberty@precisioninno.com>
1 parent cabb23d commit cc0bb65

1 file changed

Lines changed: 27 additions & 1 deletion

File tree

.github/workflows/github-actions-on-label-create.yml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,37 @@ jobs:
5151
deployToken: ${{ secrets.STAGING_GITHUB_TOKEN }}
5252
force: true
5353

54+
- id: resolve_key
55+
name: Compute per-user secret key
56+
env:
57+
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
58+
run: |
59+
key=$(echo "$PR_AUTHOR" | tr 'a-z-' 'A-Z_')
60+
echo "key=$key" >> "$GITHUB_OUTPUT"
61+
62+
- id: resolve_token
63+
name: Pick per-user PAT or fall back to bot token
64+
env:
65+
USER_PAT: ${{ secrets[format('PAT_{0}', steps.resolve_key.outputs.key)] }}
66+
BOT_TOKEN: ${{ secrets.STAGING_GITHUB_TOKEN }}
67+
run: |
68+
if [ -n "$USER_PAT" ]; then
69+
echo "::add-mask::$USER_PAT"
70+
echo "token=$USER_PAT" >> "$GITHUB_OUTPUT"
71+
echo "source=user-pat" >> "$GITHUB_OUTPUT"
72+
echo "Using per-user PAT for PR creation"
73+
else
74+
echo "::add-mask::$BOT_TOKEN"
75+
echo "token=$BOT_TOKEN" >> "$GITHUB_OUTPUT"
76+
echo "source=bot-fallback" >> "$GITHUB_OUTPUT"
77+
echo "No per-user PAT found; falling back to bot token"
78+
fi
79+
5480
- id: send_pr
5581
name: Create PR if needed.
5682
uses: The-OpenROAD-Project/actions/send_pr@main
5783
env:
58-
STAGING_GITHUB_TOKEN: ${{ secrets.STAGING_GITHUB_TOKEN }}
84+
STAGING_GITHUB_TOKEN: ${{ steps.resolve_token.outputs.token }}
5985

6086
- name: Linking to PR using deployment.
6187
uses: The-OpenROAD-Project/actions/link_pr@main

0 commit comments

Comments
 (0)