Skip to content

Commit

Permalink
chore: automatically release brew for both ARM and AMD builds
Browse files Browse the repository at this point in the history
Brings the template into the garden repo so any changes to the process only need to go through here and will always be consistent.
  • Loading branch information
TimBeyer committed Sep 11, 2023
1 parent b2974d3 commit dff8547
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 14 deletions.
77 changes: 65 additions & 12 deletions .github/workflows/reusable-create-homebrew-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,82 @@ permissions:
contents: read

jobs:
fetch-release-checksums:
runs-on: ubuntu-latest
env:
ARM_TARBALL_URL: https://download.garden.io/core/${{ inputs.release-version }}/garden-${{ inputs.release-version }}-macos-arm64.tar.gz
AMD_TARBALL_URL: https://download.garden.io/core/${{ inputs.release-version }}/garden-${{ inputs.release-version }}-macos-amd64.tar.gz
outputs:
arm-sha256: ${{ steps.fetch-arm-sha256.outputs.sha256 }}
amd-sha256: ${{ steps.fetch-amd-sha256.outputs.sha256 }}
arm-tarball-url: ${{ env.ARM_TARBALL_URL }}
amd-tarball-url: ${{ env.AMD_TARBALL_URL }}
steps:
- name: Fetch arm sha256
id: fetch-arm-sha256
if: inputs.release-condition != 'false'
run: |
echo "sha256=$(curl -sSL ${{ env.ARM_TARBALL_URL }} | shasum -a 256 | cut -d ' ' -f 1)" >> "$GITHUB_OUTPUT"
- name: Fetch amd sha256
id: fetch-amd-sha256
if: inputs.release-condition != 'false'
run: |
echo "sha256=$(curl -sSL ${{ env.AMD_TARBALL_URL }} | shasum -a 256 | cut -d ' ' -f 1)" >> "$GITHUB_OUTPUT"
homebrew-create-pr:
runs-on: macos-latest

needs: fetch-release-checksums
steps:
- name: Checks release pre-condition
if: inputs.release-condition == 'false'
run: |
echo The release-condition evaluated to false.
echo Skipping all the next steps.
- name: Create PR on Homebrew Formula repository
- name: Checkout garden repo
if: inputs.release-condition != 'false'
uses: stefreak/bump-homebrew-formula-action@82352c3cbbc2acdec5a064502447b555f18496fc
uses: actions/checkout@v4
with:
tag-name: ${{ inputs.release-version }}
formula-name: garden-cli
formula-path: Formula/garden-cli.rb
homebrew-tap: garden-io/homebrew-garden
base-branch: main
create-pullrequest: true
download-url: https://download.garden.io/core/${{ inputs.release-version }}/garden-${{ inputs.release-version }}-macos-amd64.tar.gz
repository: garden-io/garden
ref: main
path: garden
token: ${{ secrets.COMMITTER_TOKEN }}

- name: Checkout homebrew repo
if: inputs.release-condition != 'false'
uses: actions/checkout@v4
with:
repository: garden-io/homebrew-garden
ref: main
path: homebrew-garden
token: ${{ secrets.COMMITTER_TOKEN }}

- name: Template Homebrew Formula
if: inputs.release-condition != 'false'
uses: cuchi/[email protected]
with:
template: garden/support/homebrew-formula.rb.j2
output_file: homebrew-garden/Formula/garden-cli.rb
strict: true
variables: |
version=${{ inputs.release-version }}}
armTarballUrl=${{ needs.fetch-release-checksums.outputs.arm-tarball-url }}
amdTarballUrl=${{ needs.fetch-release-checksums.outputs.amd-tarball-url }}
armSha256=${{ needs.fetch-release-checksums.outputs.arm-sha256 }}
amdSha256=${{ needs.fetch-release-checksums.outputs.amd-sha256 }}
- name: Create PR on Homebrew Repository
if: inputs.release-condition != 'false'
uses: peter-evans/create-pull-request@v5
with:
path: homebrew-garden
token: ${{ secrets.COMMITTER_TOKEN }}
commit-message: ${{ inputs.commit-message }}
env:
COMMITTER_TOKEN: ${{ secrets.COMMITTER_TOKEN }}
title: Bump garden-cli to ${{ inputs.release-version }}
body: ${{ inputs.commit-message}}
branch: garden-cli-${{ inputs.release-version }}
reviewers: ${{ github.triggering_actor }}

- name: Adding markdown summary
if: inputs.release-condition != 'false'
run: |
Expand Down
12 changes: 10 additions & 2 deletions support/homebrew-formula.rb → support/homebrew-formula.rb.j2
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
class GardenCli < Formula
desc "Development engine for Kubernetes"
homepage "https://garden.io"
url "{{{tarballUrl}}}"

version "{{version}}"
sha256 "{{sha256}}"

# Determine architecture
if Hardware::CPU.arm?
url "{{armTarballUrl}}"
sha256 "{{armSha256}}"
else
url "{{amdTarballUrl}}"
sha256 "{{amdSha256}}"
end

def install
libexec.install "garden", "fsevents.node", "static", "pty.node"
Expand Down

0 comments on commit dff8547

Please sign in to comment.