Skip to content

Commit fa46c9f

Browse files
authored
Merge pull request #37 from dualentry/yuriis/sre-149-replace-homebrew_tap_token-with-a-github-app-for-dualentry
Use a GitHub App token to update the Homebrew tap
2 parents a3a9178 + 52d0d63 commit fa46c9f

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,29 @@ jobs:
5555
gh release upload "${{ github.event.release.tag_name }}" "$f" --repo "${{ github.repository }}"
5656
done
5757
58+
# GITHUB_TOKEN cannot write to another repository. Use a GitHub App
59+
# installation token to update the Homebrew tap.
5860
update-tap:
5961
needs: upload
6062
runs-on: ubuntu-latest
63+
permissions: {}
6164
steps:
65+
- name: Create GitHub App token
66+
id: app-token
67+
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
68+
with:
69+
client-id: ${{ vars.DUALENTRY_CI_APP_CLIENT_ID }}
70+
private-key: ${{ secrets.DUALENTRY_CI_APP_PRIVATE_KEY }}
71+
owner: ${{ github.repository_owner }}
72+
repositories: homebrew-tap
73+
permission-contents: write
74+
permission-pull-requests: write
75+
6276
- name: Update Homebrew tap
63-
if: ${{ env.TAP_TOKEN != '' }}
6477
env:
65-
TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
78+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
6679
run: |
80+
set -euo pipefail
6781
VERSION="${GITHUB_REF_NAME#v}"
6882
BASE_URL="https://github.com/${{ github.repository }}/releases/download/${{ github.event.release.tag_name }}"
6983
@@ -112,7 +126,7 @@ jobs:
112126
sed -i "s|SHA_LINUX_PLACEHOLDER|$SHA_LINUX|g" /tmp/dualentry.rb
113127
sed -i 's/^ //' /tmp/dualentry.rb
114128
115-
git clone "https://x-access-token:${TAP_TOKEN}@github.com/dualentry/homebrew-tap.git" /tmp/tap
129+
git clone "https://x-access-token:${GH_TOKEN}@github.com/dualentry/homebrew-tap.git" /tmp/tap
116130
mkdir -p /tmp/tap/Formula
117131
cp /tmp/dualentry.rb /tmp/tap/Formula/dualentry.rb
118132
cd /tmp/tap
@@ -125,9 +139,7 @@ jobs:
125139
git commit -m "Update dualentry to $VERSION"
126140
git push origin "$BRANCH"
127141
128-
# main is a protected branch on the tap repo (PR required), so push a
129-
# branch and PR it instead of pushing straight to main.
130-
export GH_TOKEN="$TAP_TOKEN"
142+
# Push a branch and open a PR; main may require review.
131143
PR_URL=$(gh pr create --repo dualentry/homebrew-tap \
132144
--title "Update dualentry to $VERSION" \
133145
--body "Automated formula update for dualentry $VERSION." \
@@ -141,3 +153,4 @@ jobs:
141153
else
142154
echo "::warning::Could not merge or enable auto-merge for $PR_URL — merge it manually."
143155
fi
156+

0 commit comments

Comments
 (0)