Skip to content

Commit 9c9d035

Browse files
authored
feat: automate updating homebrew tap formula (#9412)
1 parent c6f4f0f commit 9c9d035

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

.github/workflows/release.yaml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,85 @@ jobs:
328328
event-type: coder-release
329329
client-payload: '{"coder_version": "${{ steps.version.outputs.version }}"}'
330330

331+
publish-homebrew:
332+
name: Publish to Homebrew tap
333+
runs-on: ubuntu-latest
334+
needs: release
335+
if: ${{ !inputs.dry_run }}
336+
337+
steps:
338+
# TODO: skip this if it's not a new release (i.e. a backport). This is
339+
# fine right now because it just makes a PR that we can close.
340+
- name: Update homebrew
341+
env:
342+
# Variables used by the `gh` command
343+
GH_REPO: coder/homebrew-coder
344+
GH_TOKEN: ${{ secrets.CDRCI_GITHUB_TOKEN }}
345+
run: |
346+
# Keep version number around for reference, removing any potential leading v
347+
coder_version="$(echo "${{ needs.release.outputs.version }}" | tr -d v)"
348+
349+
set -euxo pipefail
350+
351+
# Setup Git
352+
git config --global user.email "ci@coder.com"
353+
git config --global user.name "Coder CI"
354+
git config --global credential.helper "store"
355+
356+
temp_dir="$(mktemp -d)"
357+
cd "$temp_dir"
358+
359+
# Download checksums
360+
checksums_url="$(gh release view --repo coder/coder v2.1.4 --json assets \
361+
| jq -r ".assets | map(.url) | .[]" \
362+
| grep -e ".checksums.txt\$")"
363+
wget "$checksums_url" -O checksums.txt
364+
365+
# Get the SHAs
366+
darwin_arm_sha="$(cat checksums.txt | grep "darwin_arm64.zip" | awk '{ print $1 }')"
367+
darwin_intel_sha="$(cat checksums.txt | grep "darwin_amd64.zip" | awk '{ print $1 }')"
368+
linux_sha="$(cat checksums.txt | grep "linux_amd64.tar.gz" | awk '{ print $1 }')"
369+
370+
echo "macOS arm64: $darwin_arm_sha"
371+
echo "macOS amd64: $darwin_intel_sha"
372+
echo "Linux amd64: $linux_sha"
373+
374+
# Check out the homebrew repo
375+
git clone "https://github.com/$GH_REPO" homebrew-coder
376+
brew_branch="auto-release/$coder_version"
377+
cd homebrew-coder
378+
379+
# Check if a PR already exists.
380+
pr_count="$(gh pr list --search "head:$brew_branch" --json id,closed | jq -r ".[] | select(.closed == false) | .id" | wc -l)"
381+
if [[ "$pr_count" > 0 ]]; then
382+
echo "Bailing out as PR already exists" 2>&1
383+
exit 0
384+
fi
385+
386+
# Set up cdrci credentials for pushing to homebrew-coder
387+
echo "https://x-access-token:$GH_TOKEN@github.com" >> ~/.git-credentials
388+
# Update the formulae and push
389+
git checkout -b "$brew_branch"
390+
./scripts/update-v2.sh "$coder_version" "$darwin_arm_sha" "$darwin_intel_sha" "$linux_sha"
391+
git add .
392+
git commit -m "coder $coder_version"
393+
git push -u origin -f "$brew_branch"
394+
395+
# Create PR
396+
gh pr create \
397+
-B master -H "$brew_branch" \
398+
-t "coder $coder_version" \
399+
-b "" \
400+
-r "${{ github.actor }}" \
401+
-a "${{ github.actor }}" \
402+
-b "This automatic PR was triggered by the release of Coder v$coder_version"
403+
331404
publish-winget:
332405
name: Publish to winget-pkgs
333406
runs-on: windows-latest
334407
needs: release
335408
if: ${{ !inputs.dry_run }}
409+
336410
steps:
337411
- name: Checkout
338412
uses: actions/checkout@v3
@@ -412,6 +486,7 @@ jobs:
412486
runs-on: windows-latest
413487
needs: release
414488
if: ${{ !inputs.dry_run }}
489+
415490
steps:
416491
- name: Checkout
417492
uses: actions/checkout@v3

0 commit comments

Comments
 (0)