Homebrew Formula #1
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: Homebrew Formula | |
| on: | |
| release: | |
| types: | |
| - published | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: "Release tag to publish (for example v0.1.0). Defaults to latest tag on current ref." | |
| required: false | |
| type: string | |
| permissions: | |
| contents: read | |
| jobs: | |
| generate-formula: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| tag: ${{ steps.meta.outputs.tag }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Resolve tag | |
| id: meta | |
| shell: bash | |
| env: | |
| RELEASE_TAG: ${{ github.event.release.tag_name }} | |
| INPUT_TAG: ${{ github.event.inputs.tag }} | |
| REF_NAME: ${{ github.ref_name }} | |
| run: | | |
| set -euo pipefail | |
| if [ -n "${RELEASE_TAG:-}" ]; then | |
| tag="${RELEASE_TAG}" | |
| elif [ -n "${INPUT_TAG:-}" ]; then | |
| tag="${INPUT_TAG}" | |
| else | |
| tag="${REF_NAME}" | |
| fi | |
| case "${tag}" in | |
| v*) ;; | |
| *) | |
| echo "Tag must start with 'v' (got: ${tag})" >&2 | |
| exit 1 | |
| ;; | |
| esac | |
| echo "tag=${tag}" >> "$GITHUB_OUTPUT" | |
| echo "version=${tag#v}" >> "$GITHUB_OUTPUT" | |
| - name: Build formula from release assets | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| tag="${{ steps.meta.outputs.tag }}" | |
| version="${{ steps.meta.outputs.version }}" | |
| source_repo="iamyxsh/fishnet" | |
| base_url="https://github.com/${source_repo}/releases/download/${tag}" | |
| mac_arm_archive="fishnet-aarch64-apple-darwin.tar.gz" | |
| mac_x64_archive="fishnet-x86_64-apple-darwin.tar.gz" | |
| linux_x64_archive="fishnet-x86_64-unknown-linux-gnu.tar.gz" | |
| mac_arm_sha="$(curl -fsSL "${base_url}/${mac_arm_archive}.sha256" | awk '{print $1; exit}')" | |
| mac_x64_sha="$(curl -fsSL "${base_url}/${mac_x64_archive}.sha256" | awk '{print $1; exit}')" | |
| linux_x64_sha="$(curl -fsSL "${base_url}/${linux_x64_archive}.sha256" | awk '{print $1; exit}')" | |
| mkdir -p dist | |
| scripts/generate-homebrew-formula.sh \ | |
| "${version}" \ | |
| "${base_url}/${mac_arm_archive}" "${mac_arm_sha}" \ | |
| "${base_url}/${mac_x64_archive}" "${mac_x64_sha}" \ | |
| "${base_url}/${linux_x64_archive}" "${linux_x64_sha}" \ | |
| > dist/fishnet.rb | |
| - name: Upload generated formula | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: homebrew-formula-${{ steps.meta.outputs.tag }} | |
| path: dist/fishnet.rb | |
| publish-to-tap: | |
| if: ${{ vars.HOMEBREW_TAP_REPOSITORY != '' }} | |
| needs: generate-formula | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check tap token | |
| id: check-token | |
| run: | | |
| if [ -n "${TAP_TOKEN}" ]; then | |
| echo "has_token=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "has_token=false" >> "$GITHUB_OUTPUT" | |
| echo "::warning::HOMEBREW_TAP_TOKEN not configured — skipping tap publish." | |
| fi | |
| env: | |
| TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }} | |
| - name: Download formula artifact | |
| if: steps.check-token.outputs.has_token == 'true' | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: homebrew-formula-${{ needs.generate-formula.outputs.tag }} | |
| path: dist | |
| - name: Publish formula to tap repository | |
| if: steps.check-token.outputs.has_token == 'true' | |
| shell: bash | |
| env: | |
| TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }} | |
| TAP_REPO: ${{ vars.HOMEBREW_TAP_REPOSITORY }} | |
| RELEASE_TAG: ${{ needs.generate-formula.outputs.tag }} | |
| run: | | |
| set -euo pipefail | |
| git clone "https://x-access-token:${TAP_TOKEN}@github.com/${TAP_REPO}.git" tap | |
| mkdir -p tap/Formula | |
| cp dist/fishnet.rb tap/Formula/fishnet.rb | |
| cd tap | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git add Formula/fishnet.rb | |
| if git diff --cached --quiet; then | |
| echo "No formula changes detected." | |
| exit 0 | |
| fi | |
| git commit -m "fishnet: update formula for ${RELEASE_TAG}" | |
| git push origin HEAD |