Skip to content

Commit f69605f

Browse files
committed
GitHub app installation access token.
Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
1 parent fc04e85 commit f69605f

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

.github/workflows/release-published.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,17 @@ jobs:
1717
steps:
1818
- name: 🚰 Apply pr-pull label to custom tap formula bump PR
1919
env:
20-
GH_TOKEN: ${{secrets.HOMEBREW_GITHUB_API_TOKEN}}
20+
TOKEN_APP_ID: ${{secrets.TOKEN_APP_ID}}
21+
TOKEN_APP_INSTALLATION_ID: ${{secrets.TOKEN_APP_INSTALLATION_ID}}
22+
TOKEN_APP_PRIVATE_KEY: ${{secrets.TOKEN_APP_PRIVATE_KEY}}
2123
run: |
24+
export GH_TOKEN="$(script/generate_token)"
25+
2226
unsetopt errexit
2327
bump_url="$(gh release -R "${GITHUB_REPOSITORY}" download "${GITHUB_REF_NAME}" -p bump.url -O - 2>/dev/null)"
2428
found_bump_url="${?}"
2529
setopt errexit
30+
2631
if [[ "${found_bump_url}" -eq 0 ]]; then
2732
[[ -n "${bump_url}" ]] && gh pr edit "${bump_url}" --add-label pr-pull
2833
gh release -R "${GITHUB_REPOSITORY}" delete-asset "${GITHUB_REF_NAME}" bump.url -y
@@ -33,7 +38,7 @@ jobs:
3338
- name: 🍺 Bump homebrew-core formula
3439
if: ${{!github.event.release.prerelease}}
3540
env:
36-
HOMEBREW_GITHUB_API_TOKEN: ${{secrets.HOMEBREW_GITHUB_API_TOKEN}}
41+
HOMEBREW_GITHUB_API_TOKEN: ${{github.token}}
3742
run: |
3843
brew bump-formula-pr\
3944
--tag "${GITHUB_REF_NAME}"\

.github/workflows/tag-pushed.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,16 @@ jobs:
5858
5959
- name: 🚰 Bump custom tap formula
6060
env:
61-
HOMEBREW_GITHUB_API_TOKEN: ${{secrets.HOMEBREW_GITHUB_API_TOKEN}}
61+
TOKEN_APP_ID: ${{secrets.TOKEN_APP_ID}}
62+
TOKEN_APP_INSTALLATION_ID: ${{secrets.TOKEN_APP_INSTALLATION_ID}}
63+
TOKEN_APP_PRIVATE_KEY: ${{secrets.TOKEN_APP_PRIVATE_KEY}}
6264
run: |
65+
export HOMEBREW_GITHUB_API_TOKEN="$(script/generate_token)"
66+
67+
echo "${HOMEBREW_GITHUB_API_TOKEN}"
68+
6369
brew tap "${GITHUB_REPOSITORY_OWNER}/tap"
70+
6471
unsetopt errexit
6572
bump_output="$(brew bump-formula-pr\
6673
--tag "${GITHUB_REF_NAME}"\
@@ -74,8 +81,10 @@ jobs:
7481
2>&1)"
7582
exit_code="${?}"
7683
setopt errexit
84+
7785
printf %s "${bump_output}"
7886
printf %s "${${(f)bump_output}[-1]}" > .build/bump.url
87+
7988
exit "${exit_code}"
8089
8190
- name: 📝 Create draft release

script/generate_token

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/zsh -Ndefgku
2+
#
3+
# script/generate_token
4+
# mas
5+
#
6+
# Generates a GitHub App installation access token for GitHub Workflows.
7+
#
8+
9+
. "${0:a:h}/_setup_script"
10+
11+
header=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9
12+
payload="${${$(printf '{"iss":%s,"iat":%s,"exp":%s}' "${TOKEN_APP_ID}" "$(("$(date +%s)" - 60))"\
13+
"$(("$(date +%s)" + 540))" | base64)//[=$'\n']}//\/+/_-}"
14+
15+
16+
# shellcheck disable=SC1009,SC1036,SC1072,SC1073
17+
curl\
18+
-sX POST\
19+
-H "Authorization: Bearer ${header}.${payload}.${${$(printf %s "${header}.${payload}" |
20+
openssl dgst -sha256 -sign =(printf %s "${TOKEN_APP_PRIVATE_KEY}") | base64)//[=$'\n']}//\/+/_-}"\
21+
-H 'Accept: application/vnd.github+json'\
22+
"https://api.github.com/app/installations/${TOKEN_APP_INSTALLATION_ID}/access_tokens" |
23+
jq -r .token

0 commit comments

Comments
 (0)