Skip to content

Commit

Permalink
Fix updating of homebrew tap (AMD64 and ARM64)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamazeem committed Dec 17, 2024
1 parent 2f8d443 commit 90fb45e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 22 deletions.
23 changes: 19 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ jobs:
runs-on: ${{ matrix.os }}
timeout-minutes: 30

outputs:
TAG: ${{ needs.tag.outputs.TAG }}

env:
TAG: ${{ needs.tag.outputs.TAG }}

Expand Down Expand Up @@ -325,12 +328,24 @@ jobs:
if: startsWith(github.ref, 'refs/tags/v')
run: ./scripts/ci-upload-release-artifacts.sh

- name: Update homebrew tap (liquidaty/homebrew-zsv)
if: ${{ startsWith(github.ref, 'refs/tags/v') && matrix.os == 'macos-13' }}
update-homebrew-tap:
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
needs: ci-macos
runs-on: ubuntu-22.04

env:
TAG: ${{ needs.ci-macos.outputs.TAG }}

steps:
- name: Checkout
uses: actions/checkout@v4
with:
sparse-checkout: |
scripts/ci-update-homebrew-tap.sh
- name: Update
env:
HOMEBREW_TAP_DEPLOY_KEY: ${{ secrets.HOMEBREW_TAP_DEPLOY_KEY }}
TAG: ${{ env.TAG }}
TRIPLET: ${{ env.AMD64_MACOSX_GCC }}
run: ./scripts/ci-update-homebrew-tap.sh

ci-bsd:
Expand Down
45 changes: 27 additions & 18 deletions scripts/ci-update-homebrew-tap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ set -e

echo "[INF] Running $0"

if [ "$HOMEBREW_TAP_DEPLOY_KEY" = "" ] || [ "$TAG" = "" ] || [ "$TRIPLET" = "" ]; then
if [ "$HOMEBREW_TAP_DEPLOY_KEY" = "" ] || [ "$TAG" = "" ]; then
echo "[ERR] One or more environment variable(s) are not set!"
echo "[ERR] Set HOMEBREW_TAP_DEPLOY_KEY, TAG, and TRIPLET before running $0 script."
echo "[ERR] Set HOMEBREW_TAP_DEPLOY_KEY and TAG before running $0 script."
exit 1
fi

TAR="zsv-$TAG-$TRIPLET.tar.gz"
TAR_URL="https://github.com/liquidaty/zsv/releases/download/v$TAG/$TAR"
AMD64_ZIP="zsv-$TAG-amd64-macosx-gcc.zip"
AMD64_URL="https://github.com/liquidaty/zsv/releases/download/v$TAG/$AMD64_ZIP"
ARM64_ZIP="zsv-$TAG-arm64-macosx-gcc.zip"
ARM64_URL="https://github.com/liquidaty/zsv/releases/download/v$TAG/$AMD64_ZIP"

HOMEBREW_TAP_REPO="[email protected]:liquidaty/homebrew-zsv.git"
HOMEBREW_TAP_DIR="homebrew-zsv"
HOMEBREW_TAP_FORMULA="formula/zsv.rb"
Expand All @@ -21,20 +24,25 @@ echo "[INF] Updating homebrew tap"

echo "[INF] PWD: $PWD"
echo "[INF] TAG: $TAG"
echo "[INF] TAR: $TAR"
echo "[INF] TAR_URL: $TAR_URL"
echo "[INF] AMD64_ZIP: $AMD64_ZIP"
echo "[INF] AMD64_URL: $AMD64_URL"
echo "[INF] ARM64_ZIP: $ARM64_ZIP"
echo "[INF] ARM64_URL: $ARM64_URL"
echo "[INF] HOMEBREW_TAP_REPO: $HOMEBREW_TAP_REPO"
echo "[INF] HOMEBREW_TAP_DIR: $HOMEBREW_TAP_DIR"
echo "[INF] HOMEBREW_TAP_FORMULA: $HOMEBREW_TAP_FORMULA"

echo "[INF] Downloading release tar file [$TAR_URL]"
wget -q "$TAR_URL"
ls -hl "$TAR"
echo "[INF] Downloading release archives [$AMD64_URL, $ARM64_URL]"
wget -q "$AMD64_URL" "$ARM64_URL"
ls -hl "$AMD64_ZIP" "$ARM64_ZIP"

echo "[INF] Calculating SHA256 hashes [$AMD64_ZIP, $ARM64_ZIP]"
AMD64_HASH=$(openssl dgst -sha256 "$AMD64_ZIP" | cut -d ' ' -f2 | tr -d '\n')
ARM64_HASH=$(openssl dgst -sha256 "$ARM64_ZIP" | cut -d ' ' -f2 | tr -d '\n')
rm -f "$AMD64_ZIP" "$ARM64_ZIP"

echo "[INF] Calculating SHA256 of $TAR"
SHA256=$(openssl dgst -sha256 "$TAR" | cut -d ' ' -f2 | tr -d '\n')
echo "[INF] SHA256: $SHA256"
rm -f "$TAR"
echo "[INF] AMD64_HASH: $AMD64_HASH"
echo "[INF] ARM64_HASH: $ARM64_HASH"

echo "[INF] Setting up GitHub credentials"
echo "$HOMEBREW_TAP_DEPLOY_KEY" >$HOMEBREW_TAP_DEPLOY_KEY_FILE
Expand All @@ -48,13 +56,14 @@ rm -rf "$HOMEBREW_TAP_DIR"
git clone "$HOMEBREW_TAP_REPO"
cd "$HOMEBREW_TAP_DIR"

echo "[INF] Replacing 'url' and 'sha256' fields [$HOMEBREW_TAP_FORMULA]"
sed -i -e "s|url .*|url '$TAR_URL'|" $HOMEBREW_TAP_FORMULA
sed -i -e "s|sha256 .*|sha256 '$SHA256'|" $HOMEBREW_TAP_FORMULA
echo "[INF] Updating URLs and SHA256 hashes [$HOMEBREW_TAP_FORMULA]"
sed -i -e "s|AMD64_URL = .*|AMD64_URL = '$AMD64_URL'|" "$HOMEBREW_TAP_FORMULA"
sed -i -e "s|AMD64_HASH = .*|AMD64_HASH = '$AMD64_HASH'|" "$HOMEBREW_TAP_FORMULA"
sed -i -e "s|ARM64_URL = .*|ARM64_URL = '$AMD64_URL'|" "$HOMEBREW_TAP_FORMULA"
sed -i -e "s|ARM64_HASH = .*|ARM64_HASH = '$AMD64_HASH'|" "$HOMEBREW_TAP_FORMULA"

DIFF=$(git diff "$HOMEBREW_TAP_FORMULA")
if [ "$DIFF" = "" ]; then
echo "[INF] 'url' and 'sha256' fields are the same."
echo "[INF] Homebrew tap formula is already updated."
echo "[INF] No changes required. Exiting!"
exit 0
Expand All @@ -64,7 +73,7 @@ echo "[INF] --- git diff $HOMEBREW_TAP_FORMULA STARTS ---"
echo "$DIFF"
echo "[INF] ---- git diff $HOMEBREW_TAP_FORMULA ENDS ----"

echo "[INF] Commiting and pushing changes"
echo "[INF] Committing and pushing changes"
git add "$HOMEBREW_TAP_FORMULA"
git commit -m "Automatic bump version to v$TAG."
git push origin main
Expand Down

0 comments on commit 90fb45e

Please sign in to comment.