| 1 | name: sync-homebrew-tap |
| 2 | |
| 3 | on: |
| 4 | release: |
| 5 | types: |
| 6 | - published |
| 7 | workflow_dispatch: |
| 8 | inputs: |
| 9 | tag: |
| 10 | description: "HFS release tag to sync (e.g. v3.0.3). Leave empty for current/latest." |
| 11 | required: false |
| 12 | type: string |
| 13 | |
| 14 | permissions: |
| 15 | contents: read |
| 16 | |
| 17 | jobs: |
| 18 | dispatch: |
| 19 | runs-on: ubuntu-latest |
| 20 | steps: |
| 21 | - name: Resolve release tag |
| 22 | id: release |
| 23 | env: |
| 24 | INPUT_TAG: ${{ github.event.inputs.tag }} |
| 25 | RELEASE_TAG: ${{ github.event.release.tag_name }} |
| 26 | run: | |
| 27 | set -euo pipefail |
| 28 | tag="${INPUT_TAG:-}" |
| 29 | [ -n "${RELEASE_TAG:-}" ] && tag="${tag:-$RELEASE_TAG}" |
| 30 | if [ -z "$tag" ]; then |
| 31 | tag="$(curl -fsSL https://api.github.com/repos/rejetto/hfs/releases/latest | jq -r '.tag_name')" |
| 32 | fi |
| 33 | [ "$tag" != "null" ] && [ -n "$tag" ] || { echo "Unable to resolve release tag"; exit 1; } |
| 34 | case "$tag" in |
| 35 | v*) ;; |
| 36 | *) tag="v$tag" ;; |
| 37 | esac |
| 38 | echo "tag=$tag" >> "$GITHUB_OUTPUT" |
| 39 | echo "Dispatching Homebrew sync for $tag" |
| 40 | |
| 41 | - name: Dispatch update to tap repository |
| 42 | env: |
| 43 | GH_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }} |
| 44 | TAG: ${{ steps.release.outputs.tag }} |
| 45 | SOURCE_REPO: ${{ github.repository }} |
| 46 | SOURCE_RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |
| 47 | run: | |
| 48 | set -euo pipefail |
| 49 | if [ -z "${GH_TOKEN:-}" ]; then |
| 50 | echo "Missing secret HOMEBREW_TAP_TOKEN" |
| 51 | exit 1 |
| 52 | fi |
| 53 | payload="$(jq -n \ |
| 54 | --arg tag "$TAG" \ |
| 55 | --arg source_repo "$SOURCE_REPO" \ |
| 56 | --arg source_run_url "$SOURCE_RUN_URL" \ |
| 57 | '{event_type:"hfs-release", client_payload:{tag:$tag, source_repo:$source_repo, source_run_url:$source_run_url}}')" |
| 58 | curl -fsSL -X POST \ |
| 59 | -H "Authorization: Bearer $GH_TOKEN" \ |
| 60 | -H "Accept: application/vnd.github+json" \ |
| 61 | https://api.github.com/repos/rejetto/homebrew-hfs/dispatches \ |
| 62 | -d "$payload" |