Skip to content

Commit eb9dee8

Browse files
committed
Use Github App for pushing commits
1 parent 26b2cde commit eb9dee8

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

.github/workflows/reusable-release.yml

+22-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ name: Scala Library Release Workflow
33
on:
44
workflow_call:
55
inputs:
6+
GITHUB_APP_ID:
7+
description:
8+
"App ID for a GitHub App that is allowed to push directly to the default branch. Eg, App ID on:
9+
https://github.com/organizations/guardian/settings/apps/gu-scala-library-release"
10+
default: '807361' # Only for use by the Guardian!
11+
required: true
12+
type: string
613
SONATYPE_PROFILE_NAME:
714
description: 'Sonatype account profile name, eg "com.gu", "org.xerial", etc (not your Sonatype username)'
815
default: 'com.gu' # Only for use by the Guardian!
@@ -28,6 +35,11 @@ on:
2835
Should be in normal plaintext 'BEGIN PGP PUBLIC KEY BLOCK' (ASCII-armored) format, with no additional BASE64-encoding.
2936
The passphrase can be removed from an existing key using 'gpg --edit-key <key-id> passwd' : https://unix.stackexchange.com/a/550538/46453"
3037
required: true
38+
GITHUB_APP_PRIVATE_KEY:
39+
description:
40+
"See https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/managing-private-keys-for-github-apps#generating-private-keys
41+
Should be in normal plaintext '-----BEGIN RSA PRIVATE KEY-----' format"
42+
required: true
3143
outputs:
3244
RELEASE_VERSION:
3345
description: "The un-prefixed version number of the release, eg '3.0.1'"
@@ -143,9 +155,14 @@ jobs:
143155
release_version: ${{ steps.create-commit.outputs.release_version }}
144156
release_commit_id: ${{ steps.create-commit.outputs.release_commit_id }}
145157
steps:
158+
- id: generate-github-app-token
159+
uses: actions/create-github-app-token@v1
160+
with: { app-id: ${{ inputs.GITHUB_APP_ID }} , private-key: ${{ secrets.GITHUB_APP_PRIVATE_KEY }} }
146161
- uses: actions/checkout@v4
147162
with:
148163
path: repo
164+
token: ${{ steps.generate-github-app-token.outputs.token }}
165+
persist-credentials: true # Allow us to push as the GitHub App, and bypass branch ruleset
149166
- uses: actions/cache/restore@v4
150167
with:
151168
path: repo-with-unsigned-version-update-commits.git
@@ -350,10 +367,12 @@ jobs:
350367
env:
351368
RELEASE_TAG: ${{ needs.push-release-commit.outputs.release_tag }}
352369
RELEASE_VERSION: ${{ needs.push-release-commit.outputs.release_version }}
353-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
354370
GH_REPO: ${{ github.repository }}
355371
GITHUB_REPO_URL: ${{ github.server_url }}/${{ github.repository }}
356372
steps:
373+
- id: generate-github-app-token
374+
uses: actions/create-github-app-token@v1
375+
with: { app-id: ${ { inputs.GITHUB_APP_ID } }, private-key: ${ { secrets.GITHUB_APP_PRIVATE_KEY } } }
357376
- name: Common values
358377
run: |
359378
GITHUB_ACTIONS_PATH="$GITHUB_REPO_URL/actions"
@@ -367,11 +386,13 @@ jobs:
367386
EndOfFile
368387
- name: Create Github Release
369388
if: needs.init.outputs.release_type == 'FULL_MAIN_BRANCH'
389+
env: { GH_TOKEN: ${{ steps.generate-github-app-token.outputs.token }} }
370390
run: |
371391
gh release create $RELEASE_TAG --verify-tag --generate-notes --notes "Release run: $GITHUB_WORKFLOW_RUN_LINK"
372392
echo "GitHub Release notes: [$RELEASE_TAG]($GITHUB_REPO_URL/releases/tag/$RELEASE_TAG)" >> $GITHUB_STEP_SUMMARY
373393
- name: Update PR with comment
374394
if: needs.init.outputs.release_type == 'PREVIEW_FEATURE_BRANCH'
395+
env: { GH_TOKEN: ${{ steps.generate-github-app-token.outputs.token }} }
375396
run: |
376397
cat << EndOfFile > comment_body.txt
377398
@${{github.actor}} has published a preview version of this PR with release workflow run $GITHUB_WORKFLOW_RUN_LINK, based on commit ${{ github.sha }}:

0 commit comments

Comments
 (0)