Skip to content

Commit

Permalink
GitHub app installation access token.
Browse files Browse the repository at this point in the history
Signed-off-by: Ross Goldberg <484615+rgoldberg@users.noreply.github.com>
  • Loading branch information
rgoldberg committed Dec 25, 2024
1 parent fc04e85 commit 9f39867
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/release-published.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@ jobs:
steps:
- name: 🚰 Apply pr-pull label to custom tap formula bump PR
env:
GH_TOKEN: ${{secrets.HOMEBREW_GITHUB_API_TOKEN}}
TOKEN_APP_ID: ${{secrets.TOKEN_APP_ID}}
TOKEN_APP_INSTALLATION_ID: ${{secrets.TOKEN_APP_INSTALLATION_ID}}
TOKEN_APP_PRIVATE_KEY: ${{secrets.TOKEN_APP_PRIVATE_KEY}}
run: |
export GH_TOKEN="$(script/generate_token)"
unsetopt errexit
bump_url="$(gh release -R "${GITHUB_REPOSITORY}" download "${GITHUB_REF_NAME}" -p bump.url -O - 2>/dev/null)"
found_bump_url="${?}"
setopt errexit
if [[ "${found_bump_url}" -eq 0 ]]; then
[[ -n "${bump_url}" ]] && gh pr edit "${bump_url}" --add-label pr-pull
gh release -R "${GITHUB_REPOSITORY}" delete-asset "${GITHUB_REF_NAME}" bump.url -y
Expand All @@ -33,7 +38,7 @@ jobs:
- name: 🍺 Bump homebrew-core formula
if: ${{!github.event.release.prerelease}}
env:
HOMEBREW_GITHUB_API_TOKEN: ${{secrets.HOMEBREW_GITHUB_API_TOKEN}}
HOMEBREW_GITHUB_API_TOKEN: ${{github.token}}
run: |
brew bump-formula-pr\
--tag "${GITHUB_REF_NAME}"\
Expand Down
11 changes: 10 additions & 1 deletion .github/workflows/tag-pushed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,16 @@ jobs:
- name: 🚰 Bump custom tap formula
env:
HOMEBREW_GITHUB_API_TOKEN: ${{secrets.HOMEBREW_GITHUB_API_TOKEN}}
TOKEN_APP_ID: ${{secrets.TOKEN_APP_ID}}
TOKEN_APP_INSTALLATION_ID: ${{secrets.TOKEN_APP_INSTALLATION_ID}}
TOKEN_APP_PRIVATE_KEY: ${{secrets.TOKEN_APP_PRIVATE_KEY}}
run: |
export HOMEBREW_GITHUB_API_TOKEN="$(script/generate_token)"
echo "${HOMEBREW_GITHUB_API_TOKEN}"
brew tap "${GITHUB_REPOSITORY_OWNER}/tap"
unsetopt errexit
bump_output="$(brew bump-formula-pr\
--tag "${GITHUB_REF_NAME}"\
Expand All @@ -74,8 +81,10 @@ jobs:
2>&1)"
exit_code="${?}"
setopt errexit
printf %s "${bump_output}"
printf %s "${${(f)bump_output}[-1]}" > .build/bump.url
exit "${exit_code}"
- name: 📝 Create draft release
Expand Down
23 changes: 23 additions & 0 deletions script/generate_token
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/zsh -Ndefgku
#
# script/generate_token
# mas
#
# Generates a GitHub App installation access token for GitHub Workflows.
#

. "${0:a:h}/_setup_script"

header=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9
payload="${${$(printf '{"iss":%s,"iat":%s,"exp":%s}' "${TOKEN_APP_ID}" "$(("$(date +%s)" - 60))"\
"$(("$(date +%s)" + 540))" | base64)//[=$'\n']}//\/+/_-}"


# shellcheck disable=SC1009,SC1036,SC1072,SC1073
curl\
-sX POST\
-H "Authorization: Bearer ${header}.${payload}.${${$(printf %s "${header}.${payload}" |
openssl dgst -sha256 -sign =(printf %s "${TOKEN_APP_PRIVATE_KEY}") | base64)//[=$'\n']}//\/+/_-}"\
-H 'Accept: application/vnd.github+json'\
"https://api.github.com/app/installations/${TOKEN_APP_INSTALLATION_ID}/access_tokens" |
jq -r .token

0 comments on commit 9f39867

Please sign in to comment.