Skip to content

Commit

Permalink
chore: automatically release brew for both ARM and AMD builds (#5062)
Browse files Browse the repository at this point in the history
* chore: automatically release brew for both ARM and AMD builds

Brings the template into the garden repo so any changes to the process only need to go through here and will always be consistent.

* fix: run release in ubuntu

* fix: ensure we grab things relative to the github workspace

* debug: help

* fix: checkout current branch instead of main

* fix: remaining templates

* chore: test failing of hashing

* chore: fail when binary cannot be fetched

* chore: test failing again

* chore: error handling removed because of bash

* chore: maybe fail now?

* chore: maybe error now?

* chore: properly error when binaries cannot be fetched

* fix: linter

* chore: remove redundant message

* chore: pin actions with commit hash

* chore: remove redundant templates
  • Loading branch information
TimBeyer authored Sep 13, 2023
1 parent 0b7d092 commit 6a5e995
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 29 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/manually-create-homebrew-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ jobs:
with:
release-version: ${{ inputs.release-version }}
commit-message: |
Bump {{formulaName}} to {{version}}.
This PR has been generated by the "Manually release Garden to Homebrew" workflow.
@${{ github.triggering_actor }} Please review this PR carefully and merge once Garden {{version}} should be released to Homebrew.
@${{ github.triggering_actor }} Please review this PR carefully and merge once Garden should be released to Homebrew.
secrets: inherit
4 changes: 1 addition & 3 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ jobs:
release-condition: ${{ github.event.release.prerelease != true }}
release-version: ${{ github.event.release.tag_name }}
commit-message: |
Bump {{formulaName}} to {{version}}.
This PR has been generated by the publish-release workflow after the new release
@${{ github.triggering_actor }} Please review this PR carefully and merge once Garden {{version}} should be released to Homebrew.
@${{ github.triggering_actor }} Please review this PR carefully and merge once Garden should be released to Homebrew.
secrets: inherit
102 changes: 86 additions & 16 deletions .github/workflows/reusable-create-homebrew-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,107 @@ on:
type: string
description: "Commit message for homebrew repository."
default: |
Bump {{formulaName}} to {{version}}.
For more info: https://github.com/garden-io/garden
permissions:
contents: read

jobs:
homebrew-create-pr:
runs-on: macos-latest
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: |
set -o pipefail
if ! checksum=$(curl -sSL --fail ${{ env.ARM_TARBALL_URL }} | shasum -a 256 | cut -d ' ' -f 1);
then
echo "Failed to fetch binary from ${{ env.ARM_TARBALL_URL }}"
exit 1
fi
echo "sha256=$checksum" >> "$GITHUB_OUTPUT"
- name: Fetch amd sha256
id: fetch-amd-sha256
if: inputs.release-condition != 'false'
run: |
set -o pipefail
if ! checksum=$(curl -sSL --fail ${{ env.AMD_TARBALL_URL }} | shasum -a 256 | cut -d ' ' -f 1);
then
echo "Failed to fetch binary from ${{ env.AMD_TARBALL_URL }}"
exit 1
fi
echo "sha256=$checksum" >> "$GITHUB_OUTPUT"
homebrew-create-pr:
runs-on: ubuntu-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@3df4ab11eba7bda6032a0b82a6bb43b11571feac # 4.0.0
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
commit-message: ${{ inputs.commit-message }}
env:
COMMITTER_TOKEN: ${{ secrets.COMMITTER_TOKEN }}
repository: garden-io/garden
path: garden

- name: Checkout homebrew repo
if: inputs.release-condition != 'false'
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # 4.0.0
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/jinja2-action@3fa06acb38601d3caea4c5ce0416e268a8799d71 # 1.2.1
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@153407881ec5c347639a548ade7d8ad1d6740e38 # 5.0.2
with:
path: ${{ github.workspace }}/homebrew-garden
token: ${{ secrets.COMMITTER_TOKEN }}
commit-message: |
Bump garden-cli.rb to ${{ inputs.release-version }}
${{ inputs.commit-message }}
title: Bump garden-cli to ${{ inputs.release-version }}
body: |
Bump garden-cli.rb to ${{ inputs.release-version }}
${{ 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
6 changes: 2 additions & 4 deletions .github/workflows/test-create-homebrew-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,20 @@ jobs:
test:
uses: ./.github/workflows/reusable-create-homebrew-pr.yml
with:
release-version: edge
release-version: edge-bonsai
commit-message: |
This is just a test. DO NOT MERGE
You can safely close this PR. This is a test PR created by https://github.com/${{ github.repository }}/pull/${{ github.event.number }}
TEST: Bump {{formulaName}} to {{version}}.
@${{ github.triggering_actor }} Please close this pull request.
secrets: inherit

test-skip:
uses: ./.github/workflows/reusable-create-homebrew-pr.yml
with:
release-condition: false
release-version: edge
release-version: edge-bonsai
commit-message: |
Do not merge. This PR should not exist.
Expand Down
16 changes: 13 additions & 3 deletions support/homebrew-formula.rb → support/homebrew-formula.rb.j2
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
class GardenCli < Formula
desc "Development engine for Kubernetes"
homepage "https://garden.io"
url "{{{tarballUrl}}}"

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

depends_on "rsync"

# 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"
libexec.install "garden", "fsevents.node", "static"
bin.install_symlink libexec/"garden"
end

Expand Down

0 comments on commit 6a5e995

Please sign in to comment.