Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: automatically release brew for both ARM and AMD builds #5062

Merged
merged 17 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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