|
| 1 | +name: homebrew-publish |
| 2 | + |
| 3 | +# Tell the Homebrew tap (mcpp-community/homebrew-mcpp) that a release is out. |
| 4 | +# |
| 5 | +# The tap owns the formula rewrite — it reads the .sha256 sidecars from the |
| 6 | +# release and commits the new url/version itself. All this workflow does is |
| 7 | +# fire the starting gun, so nothing here needs to know what a formula is. |
| 8 | +# |
| 9 | +# Triggers on COMPLETION of the `release` workflow rather than on |
| 10 | +# `release: published`, for the same reason aur-publish.yml does: release.yml |
| 11 | +# creates the GitHub Release in its first job but uploads the macOS / aarch64 |
| 12 | +# assets in later jobs, and the tap needs every sidecar to exist. |
| 13 | +# |
| 14 | +# Requires one repository secret: |
| 15 | +# HOMEBREW_TAP_TOKEN — fine-grained PAT scoped to mcpp-community/homebrew-mcpp |
| 16 | +# with "Contents: read and write" (repository_dispatch |
| 17 | +# is a write-level API). |
| 18 | +# |
| 19 | +# The secret is OPTIONAL. Without it this workflow logs a notice and exits 0; |
| 20 | +# the tap runs the same bump on a daily schedule, so a missing token costs |
| 21 | +# freshness (up to 24h), not correctness. That keeps a release from failing |
| 22 | +# over a credential the release itself doesn't need. |
| 23 | + |
| 24 | +on: |
| 25 | + workflow_run: |
| 26 | + workflows: [release] |
| 27 | + types: [completed] |
| 28 | + workflow_dispatch: |
| 29 | + inputs: |
| 30 | + version: |
| 31 | + description: "Version to publish (default: [package].version in mcpp.toml)" |
| 32 | + required: false |
| 33 | + |
| 34 | +concurrency: |
| 35 | + group: homebrew-publish |
| 36 | + cancel-in-progress: false |
| 37 | + |
| 38 | +jobs: |
| 39 | + notify-tap: |
| 40 | + runs-on: ubuntu-latest |
| 41 | + # On the workflow_run trigger, only proceed if the release actually |
| 42 | + # succeeded (skip failed/cancelled release runs). |
| 43 | + if: >- |
| 44 | + github.event_name == 'workflow_dispatch' || |
| 45 | + github.event.workflow_run.conclusion == 'success' |
| 46 | + steps: |
| 47 | + - name: Checkout released commit |
| 48 | + uses: actions/checkout@v4 |
| 49 | + with: |
| 50 | + # workflow_run: the exact commit the release was built from. |
| 51 | + # workflow_dispatch: default ref (HEAD of the branch). |
| 52 | + ref: ${{ github.event.workflow_run.head_sha || github.ref }} |
| 53 | + |
| 54 | + - name: Resolve version |
| 55 | + id: resolve |
| 56 | + run: | |
| 57 | + VER="${{ github.event.inputs.version }}" |
| 58 | + if [ -z "$VER" ]; then |
| 59 | + # mcpp.toml at the released commit carries the right version. |
| 60 | + VER=$(grep -m1 -E '^\s*version\s*=' mcpp.toml | sed -E 's/.*"([^"]+)".*/\1/') |
| 61 | + fi |
| 62 | + [ -n "$VER" ] || { echo "cannot resolve version"; exit 1; } |
| 63 | + echo "version=$VER" >> "$GITHUB_OUTPUT" |
| 64 | + echo ":: version $VER" |
| 65 | +
|
| 66 | + - name: Ping the tap |
| 67 | + env: |
| 68 | + TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }} |
| 69 | + VER: ${{ steps.resolve.outputs.version }} |
| 70 | + run: | |
| 71 | + set -eu |
| 72 | + if [ -z "${TAP_TOKEN}" ]; then |
| 73 | + echo "::notice::HOMEBREW_TAP_TOKEN is not configured; skipping the ping. mcpp-community/homebrew-mcpp bumps itself on a daily schedule, so ${VER} reaches the tap within 24h." |
| 74 | + exit 0 |
| 75 | + fi |
| 76 | + curl -fsS -X POST \ |
| 77 | + -H "Authorization: Bearer ${TAP_TOKEN}" \ |
| 78 | + -H "Accept: application/vnd.github+json" \ |
| 79 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 80 | + https://api.github.com/repos/mcpp-community/homebrew-mcpp/dispatches \ |
| 81 | + -d "{\"event_type\":\"mcpp-release\",\"client_payload\":{\"version\":\"${VER}\"}}" |
| 82 | + echo ":: dispatched mcpp-release ${VER} to mcpp-community/homebrew-mcpp" |
| 83 | + echo "Pinged the Homebrew tap for **${VER}**." >> "$GITHUB_STEP_SUMMARY" |
0 commit comments