From 90fb45e6cab5f4c81ebc730cd23cd8d165345b74 Mon Sep 17 00:00:00 2001 From: Azeem Sajid Date: Tue, 17 Dec 2024 19:09:59 +0500 Subject: [PATCH] Fix updating of homebrew tap (AMD64 and ARM64) --- .github/workflows/ci.yml | 23 +++++++++++++--- scripts/ci-update-homebrew-tap.sh | 45 ++++++++++++++++++------------- 2 files changed, 46 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 10003471..ca3eb28a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -263,6 +263,9 @@ jobs: runs-on: ${{ matrix.os }} timeout-minutes: 30 + outputs: + TAG: ${{ needs.tag.outputs.TAG }} + env: TAG: ${{ needs.tag.outputs.TAG }} @@ -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: diff --git a/scripts/ci-update-homebrew-tap.sh b/scripts/ci-update-homebrew-tap.sh index d0ab0a36..39fd0925 100755 --- a/scripts/ci-update-homebrew-tap.sh +++ b/scripts/ci-update-homebrew-tap.sh @@ -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="git@github.com:liquidaty/homebrew-zsv.git" HOMEBREW_TAP_DIR="homebrew-zsv" HOMEBREW_TAP_FORMULA="formula/zsv.rb" @@ -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 @@ -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 @@ -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