-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GA: Script to update homebrew tap on release publish event
- Loading branch information
1 parent
abfe788
commit 28fbe8d
Showing
4 changed files
with
143 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
export SALAMI_VERSION="${1}" | ||
TAP_FILE="./.github/scripts/salami_tap_template.rb}" | ||
TAP_FILE="$(realpath "${TAP_FILE}")" | ||
|
||
cd "$(mktemp -d)" | ||
|
||
>&2 echo "::info Generating Homebrew Tap..." | ||
>&2 echo "::group::Download release assets" | ||
>&2 gh release download --repo petrgazarov/salami "v${SALAMI_VERSION}" -p 'salami*darwin*.tar.gz' -p 'salami*linux*.tar.gz' --skip-existing | ||
>&2 echo "::endgroup::" | ||
|
||
for i in \ | ||
"darwin x64 SALAMI_DARWIN_X64" \ | ||
"darwin arm64 SALAMI_DARWIN_ARM64" \ | ||
"linux x64 SALAMI_LINUX_X64" \ | ||
"linux arm64 SALAMI_LINUX_ARM64" \ | ||
; do | ||
# shellcheck disable=SC2086 # intentional, we want to split the strings | ||
set -- $i # read loop strings as args | ||
OS="$1" | ||
ARCH="$2" | ||
ENV_VAR="$3" | ||
SHA256="$(sha256sum "salami-${SALAMI_VERSION}-${OS}-${ARCH}.tar.gz" | cut -f1 -d' ')" | ||
|
||
SHA256_VAR="${ENV_VAR}_SHA256" | ||
URL_VAR="${ENV_VAR}_URL" | ||
printf -v "${SHA256_VAR}" "%s" "${SHA256}" | ||
printf -v "${URL_VAR}" "%s" "https://github.com/petrgazarov/salami/releases/download/${SALAMI_VERSION}/salami-${SALAMI_VERSION}-${OS}-${ARCH}.tar.gz" | ||
|
||
export "${SHA256_VAR?}" | ||
export "${URL_VAR?}" | ||
>&2 echo "${OS}-${ARCH} SHA256: " "${!SHA256_VAR}" | ||
>&2 echo "${OS}-${ARCH} URL: " "${!URL_VAR}" | ||
done | ||
|
||
# shellcheck disable=SC2016 # intentional, envsubst requires us to pass variable names with $ prefixes. | ||
envsubst '$SALAMI_VERSION,$SALAMI_DARWIN_X64_URL,$SALAMI_DARWIN_X64_SHA256,$SALAMI_DARWIN_ARM64_URL,$SALAMI_DARWIN_ARM64_SHA256,$SALAMI_LINUX_X64_URL,$SALAMI_LINUX_X64_SHA256,$SALAMI_LINUX_ARM64_URL,$SALAMI_LINUX_ARM64_SHA256' < "${TAP_FILE}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# frozen_string_literal: true | ||
|
||
# This file was generated by https://github.com/salami/salami/blob/master/.github/scripts/generate-homebrew-tap | ||
class Salami < Formula | ||
desc "Salami - Infrastructure as Natural Language" | ||
homepage "https://github.com/petrgazarov/salami" | ||
version "${SALAMI_VERSION}" | ||
license "Apache-2.0" | ||
|
||
on_macos do | ||
if Hardware::CPU.intel? | ||
url "${SALAMI_DARWIN_X64_URL}" | ||
sha256 "${SALAMI_DARWIN_X64_SHA256}" | ||
end | ||
|
||
if Hardware::CPU.arm? | ||
url "${SALAMI_DARWIN_ARM64_URL}" | ||
sha256 "${SALAMI_DARWIN_ARM64_SHA256}" | ||
end | ||
|
||
def install | ||
bin.install Dir["*"] | ||
end | ||
end | ||
|
||
on_linux do | ||
if Hardware::CPU.arm? && Hardware::CPU.is_64_bit? | ||
url "${SALAMI_LINUX_ARM64_URL}" | ||
sha256 "${SALAMI_LINUX_ARM64_SHA256}" | ||
end | ||
|
||
if Hardware::CPU.intel? | ||
url "${SALAMI_LINUX_X64_URL}" | ||
sha256 "${SALAMI_LINUX_X64_SHA256}" | ||
end | ||
|
||
def install | ||
bin.install Dir["*"] | ||
end | ||
end | ||
|
||
test do | ||
system "#{bin}/salami version" | ||
end | ||
end |
2 changes: 1 addition & 1 deletion
2
.github/workflows/create_release.yml → .github/workflows/create_gh_release.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: Create release | ||
name: Create GH release | ||
|
||
on: | ||
push: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
name: Release Homebrew tap | ||
|
||
on: | ||
release: | ||
types: | ||
- published | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
update-homebrew-salami: | ||
name: Update Homebrew Tap | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Salami repo | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ github.event.release.target_commitish }} | ||
path: salami | ||
|
||
- name: Checkout Salami homebrew repo | ||
uses: actions/checkout@v3 | ||
with: | ||
repository: petrgazarov/homebrew-salami | ||
path: homebrew-salami | ||
token: ${{ secrets.HOMEBREW_SALAMI_GITHUB_TOKEN }} | ||
|
||
- name: Update Homebrew Tap | ||
run: | | ||
set -euo pipefail | ||
# Can simulate this by cloning petrgazarov/salami & petrgazarov/homebrew-salami to adacent directories | ||
# and running from their parent: | ||
./salami/.github/scripts/generate-homebrew-salami.sh \ | ||
"${SALAMI_VERSION}" ./salami/.github/scripts/salami-tap-template.rb \ | ||
> ./homebrew-salami/Formula/salami.rb | ||
- name: Commit updated formula | ||
working-directory: homebrew-salami | ||
run: | | ||
set -euo pipefail | ||
git config user.name petrgazarov | ||
git config user.email [email protected] | ||
git add Formula/salami.rb | ||
echo "::group::git diff" | ||
git --no-pager diff | ||
echo "::endgroup::" | ||
git commit -m "Brew formula update for Salami version ${SALAMI_VERSION}" | ||
- name: Push formula | ||
working-directory: homebrew-salami | ||
run: | | ||
set -euo pipefail | ||
git push origin HEAD:main |