Skip to content

Commit 85e7ec9

Browse files
committed
chore(release): use GitHub App token for releases
1 parent f2376f2 commit 85e7ec9

6 files changed

Lines changed: 42 additions & 8 deletions

File tree

.github/scripts/create-release-branch.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ fi
2727
require_missing_remote_branch "${maintenance_branch}"
2828
require_remote_branch "${source_branch}"
2929

30-
configure_git_credentials
3130
git fetch origin "+refs/heads/${source_branch}:refs/remotes/origin/${source_branch}" --tags
3231
git rev-parse --verify --end-of-options "${source_ref}^{commit}" >/dev/null
3332
if ! git merge-base --is-ancestor -- "${source_ref}^{commit}" "origin/${source_branch}"; then
3433
echo "Source ref ${source_ref} is not reachable from origin/${source_branch}."
3534
exit 1
3635
fi
36+
configure_git_credentials
3737
git push origin "${source_ref}^{commit}:refs/heads/${maintenance_branch}"
3838
gh issue comment "${ISSUE_NUMBER}" --body "Created ${maintenance_branch} from ${source_ref}."

.github/scripts/prepare-release.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ require_remote_branch "${target_branch}"
2424
require_missing_remote_branch "${work_branch}"
2525

2626
configure_git_author
27-
configure_git_credentials
2827
git fetch origin "+refs/heads/${target_branch}:refs/remotes/origin/${target_branch}" --tags
2928
git checkout -B "${work_branch}" "origin/${target_branch}"
3029

@@ -34,6 +33,7 @@ git checkout -B "${work_branch}" "origin/${target_branch}"
3433
-Prelease.releaseVersion="${release_version}" \
3534
-Prelease.newVersion="${next_version}"
3635

36+
configure_git_credentials
3737
git push origin "HEAD:refs/heads/${work_branch}"
3838

3939
{

.github/scripts/publish-release.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ fi
6262
gh pr checks "${pr_number}" --required --fail-fast
6363

6464
configure_git_author
65-
configure_git_credentials
6665
git fetch origin \
6766
"+refs/heads/${target_branch}:refs/remotes/origin/${target_branch}" \
6867
"+refs/heads/${work_branch}:refs/remotes/origin/${work_branch}" \
@@ -106,5 +105,6 @@ if [[ "$(git cat-file -t "${tag_name}")" != "tag" ]]; then
106105
exit 1
107106
fi
108107

108+
configure_git_credentials
109109
git push --atomic --follow-tags origin "refs/remotes/origin/${work_branch}:refs/heads/${target_branch}"
110110
gh issue comment "${ISSUE_NUMBER}" --body "Published ${tag_name} to ${target_branch}."

.github/workflows/release-branch.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
types: [labeled]
66

77
permissions:
8-
contents: write
8+
contents: read
99
issues: write
1010

1111
jobs:
@@ -18,7 +18,6 @@ jobs:
1818
GH_TOKEN: ${{ github.token }}
1919
ISSUE_BODY: ${{ github.event.issue.body }}
2020
ISSUE_NUMBER: ${{ github.event.issue.number }}
21-
PUSH_TOKEN: ${{ github.token }}
2221
RELEASE_ACTOR: ${{ github.event.sender.login }}
2322
steps:
2423
- name: Checkout
@@ -28,11 +27,27 @@ jobs:
2827
fetch-tags: true
2928
persist-credentials: false
3029

30+
- name: Authorize release actor
31+
run: bash -c 'source .github/scripts/release-common.sh; require_maintainer'
32+
33+
- name: Create release app token
34+
id: release-app-token
35+
uses: actions/create-github-app-token@67018539274d69449ef7c02e8e71183d1719ab42 # v2.1.4
36+
with:
37+
app-id: ${{ secrets.RELEASE_APP_ID }}
38+
private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }}
39+
owner: ${{ github.repository_owner }}
40+
repositories: ${{ github.event.repository.name }}
41+
3142
- name: Create branch
43+
env:
44+
PUSH_TOKEN: ${{ steps.release-app-token.outputs.token }}
3245
run: |
3346
set -o pipefail
3447
bash .github/scripts/create-release-branch.sh 2>&1 | tee "${RUNNER_TEMP}/release-branch.log"
3548
3649
- name: Comment on failure
3750
if: failure()
51+
env:
52+
PUSH_TOKEN: ${{ steps.release-app-token.outputs.token }}
3853
run: bash .github/scripts/comment-issue-failure.sh "${RUNNER_TEMP}/release-branch.log" "Create release branch"

.github/workflows/release-prepare.yml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ on:
55
types: [labeled]
66

77
permissions:
8-
contents: write
8+
contents: read
99
issues: write
10-
pull-requests: write
1110

1211
jobs:
1312
prepare:
@@ -19,7 +18,6 @@ jobs:
1918
GH_TOKEN: ${{ github.token }}
2019
ISSUE_BODY: ${{ github.event.issue.body }}
2120
ISSUE_NUMBER: ${{ github.event.issue.number }}
22-
PUSH_TOKEN: ${{ github.token }}
2321
RELEASE_ACTOR: ${{ github.event.sender.login }}
2422
steps:
2523
- name: Checkout
@@ -29,6 +27,9 @@ jobs:
2927
fetch-tags: true
3028
persist-credentials: false
3129

30+
- name: Authorize release actor
31+
run: bash -c 'source .github/scripts/release-common.sh; require_maintainer'
32+
3233
- name: Set up JDK
3334
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
3435
with:
@@ -40,13 +41,26 @@ jobs:
4041
with:
4142
validate-wrappers: true
4243

44+
- name: Create release app token
45+
id: release-app-token
46+
uses: actions/create-github-app-token@67018539274d69449ef7c02e8e71183d1719ab42 # v2.1.4
47+
with:
48+
app-id: ${{ secrets.RELEASE_APP_ID }}
49+
private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }}
50+
owner: ${{ github.repository_owner }}
51+
repositories: ${{ github.event.repository.name }}
52+
4353
- name: Prepare release branch
4454
id: release
55+
env:
56+
PUSH_TOKEN: ${{ steps.release-app-token.outputs.token }}
4557
run: |
4658
set -o pipefail
4759
bash .github/scripts/prepare-release.sh 2>&1 | tee "${RUNNER_TEMP}/release-prepare.log"
4860
4961
- name: Open or update release pull request
62+
env:
63+
GH_TOKEN: ${{ steps.release-app-token.outputs.token }}
5064
run: |
5165
set -o pipefail
5266
bash .github/scripts/upsert-release-pr.sh \
@@ -59,4 +73,6 @@ jobs:
5973
6074
- name: Comment on failure
6175
if: failure()
76+
env:
77+
PUSH_TOKEN: ${{ steps.release-app-token.outputs.token }}
6278
run: bash .github/scripts/comment-issue-failure.sh "${RUNNER_TEMP}/release-prepare.log" "Prepare release"

.github/workflows/release-publish.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ jobs:
3030
fetch-tags: true
3131
persist-credentials: false
3232

33+
- name: Authorize release actor
34+
run: bash -c 'source .github/scripts/release-common.sh; require_maintainer'
35+
3336
- name: Create release app token
3437
id: release-app-token
3538
uses: actions/create-github-app-token@67018539274d69449ef7c02e8e71183d1719ab42 # v2.1.4

0 commit comments

Comments
 (0)