S3 - Publish Homebrew (Cask + Formula) #6
This file contains hidden or 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
| name: S3 - Publish Homebrew (Cask + Formula) | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: "Release tag (e.g., 3.0.1)" | |
| required: true | |
| type: string | |
| env: | |
| TAP_REPO: zaai-com/homebrew-tap | |
| FORMULA_NAME: git-same-cli | |
| CASK_NAME: git-same | |
| permissions: | |
| contents: read | |
| jobs: | |
| publish-homebrew: | |
| name: Publish Cask + Formula to Tap | |
| runs-on: macos-latest | |
| steps: | |
| - uses: actions/checkout@v7 | |
| with: | |
| persist-credentials: false | |
| - name: Get version from tag | |
| id: version | |
| run: | | |
| TAG="${{ inputs.tag }}" | |
| if [ -z "$TAG" ]; then | |
| TAG="${GITHUB_REF#refs/tags/}" | |
| fi | |
| if [ -z "$TAG" ] || [ "$TAG" = "${GITHUB_REF}" ]; then | |
| echo "Invalid tag. Provide workflow_dispatch input 'tag' (e.g., 3.0.1)." | |
| exit 1 | |
| fi | |
| if ! [[ "$TAG" =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]]; then | |
| echo "Tag must be strict semver only, no leading zeros (e.g., 3.0.1). Got: $TAG" | |
| exit 1 | |
| fi | |
| echo "tag=$TAG" >> "$GITHUB_OUTPUT" | |
| echo "version=$TAG" >> "$GITHUB_OUTPUT" | |
| - name: Download release assets | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| mkdir -p assets | |
| VERSION="${{ steps.version.outputs.version }}" | |
| gh release download "${{ steps.version.outputs.tag }}" \ | |
| --pattern "git-same-${VERSION}-x86_64-unknown-linux-gnu.tar.gz" \ | |
| --pattern "git-same-${VERSION}-aarch64-unknown-linux-gnu.tar.gz" \ | |
| --pattern "git-same-${VERSION}-x86_64-apple-darwin.tar.gz" \ | |
| --pattern "git-same-${VERSION}-aarch64-apple-darwin.tar.gz" \ | |
| --pattern "git-same-${VERSION}-x86_64.dmg" \ | |
| --pattern "git-same-${VERSION}-aarch64.dmg" \ | |
| --dir assets | |
| - name: Compute SHA256 hashes | |
| id: sha | |
| run: | | |
| VERSION="${{ steps.version.outputs.version }}" | |
| LINUX_X86="assets/git-same-${VERSION}-x86_64-unknown-linux-gnu.tar.gz" | |
| LINUX_ARM="assets/git-same-${VERSION}-aarch64-unknown-linux-gnu.tar.gz" | |
| MAC_X86="assets/git-same-${VERSION}-x86_64-apple-darwin.tar.gz" | |
| MAC_ARM="assets/git-same-${VERSION}-aarch64-apple-darwin.tar.gz" | |
| CASK_MAC_X86="assets/git-same-${VERSION}-x86_64.dmg" | |
| CASK_MAC_ARM="assets/git-same-${VERSION}-aarch64.dmg" | |
| echo "linux_x86_64=$(shasum -a 256 "$LINUX_X86" | cut -d' ' -f1)" >> "$GITHUB_OUTPUT" | |
| echo "linux_aarch64=$(shasum -a 256 "$LINUX_ARM" | cut -d' ' -f1)" >> "$GITHUB_OUTPUT" | |
| echo "macos_x86_64=$(shasum -a 256 "$MAC_X86" | cut -d' ' -f1)" >> "$GITHUB_OUTPUT" | |
| echo "macos_aarch64=$(shasum -a 256 "$MAC_ARM" | cut -d' ' -f1)" >> "$GITHUB_OUTPUT" | |
| echo "cask_macos_x86_64=$(shasum -a 256 "$CASK_MAC_X86" | cut -d' ' -f1)" >> "$GITHUB_OUTPUT" | |
| echo "cask_macos_aarch64=$(shasum -a 256 "$CASK_MAC_ARM" | cut -d' ' -f1)" >> "$GITHUB_OUTPUT" | |
| - name: Render formula-cli | |
| run: | | |
| TAG="${{ steps.version.outputs.tag }}" | |
| REPO_URL="https://github.com/zaai-com/git-same/releases/download/${TAG}" | |
| bash toolkit/homebrew/render-formula.sh \ | |
| "${{ steps.version.outputs.version }}" \ | |
| --url "${REPO_URL}" \ | |
| --sha-macos-arm "${{ steps.sha.outputs.macos_aarch64 }}" \ | |
| --sha-macos-intel "${{ steps.sha.outputs.macos_x86_64 }}" \ | |
| --sha-linux-arm "${{ steps.sha.outputs.linux_aarch64 }}" \ | |
| --sha-linux-intel "${{ steps.sha.outputs.linux_x86_64 }}" \ | |
| --out formula-cli.rb | |
| - name: Render cask | |
| run: | | |
| bash toolkit/homebrew/render-cask.sh \ | |
| "${{ steps.version.outputs.version }}" \ | |
| --sha-arm "${{ steps.sha.outputs.cask_macos_aarch64 }}" \ | |
| --sha-intel "${{ steps.sha.outputs.cask_macos_x86_64 }}" \ | |
| --out cask.rb | |
| - name: Verify rendered cask + formula against a temp tap | |
| run: | | |
| bash toolkit/homebrew/verify-tap.sh \ | |
| --cask cask.rb \ | |
| --formula-cli formula-cli.rb | |
| - name: Checkout tap repository | |
| uses: actions/checkout@v7 | |
| with: | |
| repository: ${{ env.TAP_REPO }} | |
| token: ${{ secrets.HOMEBREW_TAP_REPO_COMMIT_TOKEN }} | |
| path: tap | |
| fetch-depth: 0 | |
| - name: Stage rendered files into tap | |
| run: | | |
| mkdir -p tap/Formula tap/Casks | |
| cp formula-cli.rb "tap/Formula/${FORMULA_NAME}.rb" | |
| cp cask.rb "tap/Casks/${CASK_NAME}.rb" | |
| - name: Commit and push to tap | |
| run: | | |
| cd tap | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add \ | |
| "Formula/${FORMULA_NAME}.rb" \ | |
| "Casks/${CASK_NAME}.rb" | |
| if git diff --cached --quiet; then | |
| echo "Cask + formula unchanged, skipping commit" | |
| else | |
| git commit -m "Update git-same to ${{ steps.version.outputs.version }} (cask + formula-cli)" | |
| git push origin HEAD | |
| fi |