Skip to content
New issue

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

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

Already on GitHub? # to your account

GHA to update homebrew on release #353

Merged
merged 1 commit into from
Sep 8, 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
20 changes: 7 additions & 13 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ on:
branches:
- main
- release/**
pull_request:
branches:
- release/**
tags:
- v[0-9]+.[0-9]+.[0-9]+-?**

defaults:
run:
Expand Down Expand Up @@ -57,13 +56,13 @@ jobs:
- name: Extract version
shell: bash
run: |
[[ $GITHUB_REF =~ ^refs\/heads\/release\/(.*)$ ]] && version=${BASH_REMATCH[1]} || version=${{ github.sha }}
[[ $GITHUB_REF =~ ^refs\/tags\/v(.*)$ ]] && version=${BASH_REMATCH[1]} || version=${{ github.sha }}
echo "VERSION=${version}" >> $GITHUB_ENV
- name: Build
id: build
run: |
mkdir kp-binaries

build() {
OS=$1
ARCH=$2
Expand All @@ -73,7 +72,7 @@ jobs:
-o kp-binaries/kp-$OS-$ARCH-${{ env.VERSION }} \
./cmd/kp
}

build darwin amd64
build darwin arm64
build linux amd64
Expand All @@ -90,7 +89,7 @@ jobs:
needs:
- unit
- build
if: ${{ startsWith(github.ref, 'refs/heads/release/') }}
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -99,18 +98,13 @@ jobs:
- name: Validate release version
run: |
echo "GITHUB_REF=${GITHUB_REF}"
[[ $GITHUB_REF =~ ^refs\/heads\/release\/(.*)$ ]] && version=${BASH_REMATCH[1]}
[[ $GITHUB_REF =~ ^refs\/tags\/v(.*)$ ]] && version=${BASH_REMATCH[1]}
if [[ -z "${version}" ]]; then
echo "ERROR: version not detected."
exit 1
fi
echo "VERSION=${version}" >> $GITHUB_ENV

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'

- name: Download artifacts
uses: actions/download-artifact@v3

Expand Down
91 changes: 91 additions & 0 deletions .github/workflows/homebrew.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: update homebrew

on:
release:
types:
- released

jobs:
update-tap:
runs-on: ubuntu-latest
steps:
- name: Parse release version
run: |
echo "GITHUB_REF=${GITHUB_REF}"
[[ $GITHUB_REF =~ ^refs\/tags\/v(.*)$ ]] && version=${BASH_REMATCH[1]}
if [[ -z "${version}" ]]; then
echo "ERROR: version not detected."
exit 1
fi
echo "VERSION=${version}" >> $GITHUB_ENV

- uses: actions/checkout@v4
with:
repository: buildpacks-community/homebrew-kpack-cli
path: homebrew-kpack-cli
token: ${{ secrets.KP_HOMEBREW_GITHUB_TOKEN }}

- name: Download checksums
id: checksums
run: |
linux_amd64_url="https://github.com/buildpacks-community/kpack-cli/releases/download/v${{ env.VERSION }}/kp-linux-amd64-${{ env.VERSION }}.sha256"
echo "linux_amd64=$(curl -sSL "$linux_amd64_url" | cut -d ' ' -f1)" >> $GITHUB_OUTPUT

linux_arm64_url="https://github.com/buildpacks-community/kpack-cli/releases/download/v${{ env.VERSION }}/kp-linux-arm64-${{ env.VERSION }}.sha256"
echo "linux_arm64=$(curl -sSL "$linux_arm64_url" | cut -d ' ' -f1)" >> $GITHUB_OUTPUT

darwin_amd64_url="https://github.com/buildpacks-community/kpack-cli/releases/download/v${{ env.VERSION }}/kp-darwin-amd64-${{ env.VERSION }}.sha256"
echo "darwin_amd64=$(curl -sSL "$darwin_amd64_url" | cut -d ' ' -f1)" >> $GITHUB_OUTPUT

darwin_arm64_url="https://github.com/buildpacks-community/kpack-cli/releases/download/v${{ env.VERSION }}/kp-darwin-arm64-${{ env.VERSION }}.sha256"
echo "darwin_arm64=$(curl -sSL "$darwin_arm64_url" | cut -d ' ' -f1)" >> $GITHUB_OUTPUT

- name: Update kp.rb
run: |
cd homebrew-kpack-cli

cat <<EOF > kp.rb
class Kp < Formula
desc "A command line interface for interacting with kpack."
homepage "https://github.com/buildpacks-community/kpack-cli"
version "${{ env.VERSION }}"
license "Apache-2.0"

if OS.mac?
if Hardware::CPU.intel?
url "https://github.com/buildpacks-community/kpack-cli/releases/download/v${{ env.VERSION }}/kp-darwin-amd64-${{ env.VERSION }}"
sha256 "${{ steps.checksums.outputs.darwin_amd64 }}"
elsif Hardware::CPU.arm?
url "https://github.com/buildpacks-community/kpack-cli/releases/download/v${{ env.VERSION }}/kp-darwin-arm64-${{ env.VERSION }}"
sha256 "${{ steps.checksums.outputs.darwin_arm64 }}"
end
elsif OS.linux?
if Hardware::CPU.intel?
url "https://github.com/buildpacks-community/kpack-cli/releases/download/v${{ env.VERSION }}/kp-linux-amd64-${{ env.VERSION }}"
sha256 "${{ steps.checksums.outputs.linux_amd64 }}"
elsif Hardware::CPU.arm?
url "https://github.com/buildpacks-community/kpack-cli/releases/download/v${{ env.VERSION }}/kp-linux-arm64-${{ env.VERSION }}"
sha256 "${{ steps.checksums.outputs.linux_arm64 }}"
end
end

def install
bin.install stable.url.split("/")[-1] => "kp"
end

test do
system "#{bin}/kp", "version"
end
end
EOF

- run: cat homebrew-kpack-cli/kp.rb
- name: Commit changes
run: |
git config --global user.email "<>"
git config --global user.name "kpack-bot"

cd homebrew-kpack-cli
git add kp.rb
git commit -m "Update Kpack CLI to ${{ env.VERSION }}"
git push
14 changes: 8 additions & 6 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
name: unit test

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
branches:
- main
- release/**

jobs:

test:
unit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -26,4 +25,7 @@ jobs:
fi

- name: Test
run: go test -v ./pkg/...
run: go test -v ./pkg/...

- name: Report coverage
uses: codecov/codecov-action@v3.1.4