Skip to content

Commit 887a74a

Browse files
ci: migrate GH_TOKEN_ADMIN to GitHub App token authentication (#2023)
## Summary - Replace all `GH_TOKEN_ADMIN` (long-lived PAT) usages in CI workflows with short-lived GitHub App installation tokens via `actions/create-github-app-token@v3` - Migrated `build-test-release.yml` (`release` job) and `ta-tests.yml` (`test-addons` job) - Uses existing `GH_APP_CLIENT_ID` and `GH_APP_PRIVATE_KEY` secrets already synced to all repos via `addonfactory-sync-secrets` Made with [Cursor](https://cursor.com)
2 parents 793a346 + 3243a22 commit 887a74a

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

.github/workflows/build-test-release.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,13 @@ jobs:
460460
# Very important: semantic-release won't trigger a tagged
461461
# build if this is not set false
462462
persist-credentials: false
463+
- name: Generate GitHub App Token
464+
id: app-token
465+
uses: actions/create-github-app-token@v3
466+
with:
467+
client-id: ${{ secrets.GH_APP_CLIENT_ID }}
468+
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
469+
owner: ${{ github.repository_owner }}
463470
- uses: actions/setup-python@v6
464471
with:
465472
python-version: "3.9"
@@ -488,7 +495,7 @@ jobs:
488495
extra_plugins: |
489496
semantic-release-replace-plugin
490497
env:
491-
GITHUB_TOKEN: ${{ secrets.GH_TOKEN_ADMIN }}
498+
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
492499
- if: ${{ steps.semantic.outputs.new_release_published == 'true' }}
493500
run: |
494501
poetry build

.github/workflows/ta-tests.yml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,19 @@ jobs:
9595
continue-on-error: true
9696
runs-on: ubuntu-latest
9797
steps:
98+
- name: Generate GitHub App Token
99+
id: app-token
100+
uses: actions/create-github-app-token@v3
101+
with:
102+
client-id: ${{ secrets.GH_APP_CLIENT_ID }}
103+
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
104+
owner: ${{ github.repository_owner }}
98105
- name: Checkout Target Add-on Repository
99106
uses: actions/checkout@v6
100107
with:
101108
repository: ${{ matrix.target_repo }}
102109
path: TA
103-
token: ${{ secrets.GH_TOKEN_ADMIN }}
110+
token: ${{ steps.app-token.outputs.token }}
104111
ref: ${{ github.event.inputs.target_branch }}
105112

106113
- name: Set up Python
@@ -134,8 +141,8 @@ jobs:
134141
set -x
135142
136143
# https://github.com/python-poetry/poetry/issues/7491#issuecomment-1423763839
137-
git config --global --add url."https://${{ secrets.GH_TOKEN_ADMIN }}@github.com".insteadOf https://github.com
138-
git config --global --add url."https://${{ secrets.GH_TOKEN_ADMIN }}@github.com".insteadOf ssh://git@github.com
144+
git config --global --add url."https://x-access-token:${{ steps.app-token.outputs.token }}@github.com".insteadOf https://github.com
145+
git config --global --add url."https://x-access-token:${{ steps.app-token.outputs.token }}@github.com".insteadOf ssh://git@github.com
139146
140147
# Use the special branch
141148
if [[ "${{ github.event.inputs.run_pipelines }}" == "true" ]]; then
@@ -268,7 +275,7 @@ jobs:
268275
if: success() && github.event.inputs.run_pipelines == 'true'
269276
working-directory: TA
270277
env:
271-
GH_TOKEN: ${{ secrets.GH_TOKEN_ADMIN }}
278+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
272279
run: |
273280
echo "Creating a new draft PR from branch $GIT_BRANCH to ${{ github.event.inputs.target_branch }}"
274281
gh pr create -R ${{ matrix.target_repo }} --title "CI: UCC build for ${{ github.event_name }} event" \
@@ -278,7 +285,7 @@ jobs:
278285
if: success() && github.event.inputs.run_pipelines == 'true'
279286
id: get-workflow-run-id
280287
env:
281-
GH_TOKEN: ${{ secrets.GH_TOKEN_ADMIN }}
288+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
282289
run: |
283290
echo "Waiting for the workflow run to be created..."
284291
sleep 30 # Wait for a while to ensure the workflow run is created
@@ -310,7 +317,7 @@ jobs:
310317
if: success()
311318
id: wait-for-workflow
312319
env:
313-
GH_TOKEN: ${{ secrets.GH_TOKEN_ADMIN }}
320+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
314321
run: |
315322
if [[ -z "$WORKFLOW_RUN_ID" ]]; then
316323
echo "No workflow run ID found, skipping wait"
@@ -343,7 +350,7 @@ jobs:
343350
if: always() && github.event.inputs.run_pipelines == 'true'
344351
working-directory: TA
345352
env:
346-
GH_TOKEN: ${{ secrets.GH_TOKEN_ADMIN }}
353+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
347354
run: |
348355
echo "Deleting temporary branch $GIT_BRANCH"
349356
gh api -X DELETE repos/${{ matrix.target_repo }}/git/refs/heads/$GIT_BRANCH || true

0 commit comments

Comments
 (0)