1313 paths :
1414 - ' packaging/homebrew/mfc.rb'
1515 - ' packaging/homebrew/README.md'
16- # Deploy to tap when a tag is created (no paths filter on tag creation)
17- create :
16+ # Note: tag releases are deployed to the tap by homebrew-release.yml, not here.
1817 workflow_dispatch :
1918
2019permissions :
2423 deploy-tap :
2524 name : Audit and deploy formula
2625 runs-on : macos-14
27- if : github.event_name != 'create' || github.event.ref_type == 'tag'
2826 permissions :
2927 contents : write
3028 pull-requests : write
4442 EVENT_NAME="${{ github.event_name }}"
4543 REF_NAME="${{ github.ref_name }}"
4644
47- if [[ "${EVENT_NAME}" == "create" ]]; then
48- # Tag creation event
49- VERSION="${REF_NAME#v}"
50- URL="https://github.com/${{ github.repository }}/archive/refs/tags/v${VERSION}.tar.gz"
51- elif [[ "${GITHUB_REF_TYPE:-}" == "tag" ]]; then
52- # Tag push event
45+ if [[ "${GITHUB_REF_TYPE:-}" == "tag" ]]; then
46+ # Manual dispatch from a tag ref
5347 VERSION="${REF_NAME#v}"
5448 URL="https://github.com/${{ github.repository }}/archive/refs/tags/v${VERSION}.tar.gz"
5549 else
7165 fi
7266
7367 - name : Update formula (for tag events)
74- if : github.event_name == 'create' || github. ref_type == 'tag'
68+ if : github.ref_type == 'tag'
7569 run : |
7670 /usr/bin/sed -i '' "s@^ url \".*\"@ url \"${{ steps.meta.outputs.url }}\"@" packaging/homebrew/mfc.rb
7771 /usr/bin/sed -i '' "s@^ sha256 \".*\"@ sha256 \"${{ steps.meta.outputs.sha256 }}\"@" packaging/homebrew/mfc.rb
@@ -110,22 +104,41 @@ jobs:
110104 fi
111105
112106 - name : Copy formula and README into tap
107+ id : merge
113108 if : github.event_name != 'pull_request'
114109 run : |
115110 set -euo pipefail
116111 mkdir -p tap-repo/Formula
117- # If the release URL is unchanged, keep the tap's existing bottle block so a
118- # formula-only push to master doesn't delete bottles already built for this version.
119- NEW_URL="$(grep -E '^ url ' packaging/homebrew/mfc.rb || true)"
120- OLD_URL="$(grep -E '^ url ' tap-repo/Formula/mfc.rb 2>/dev/null || true)"
121- if [[ -n "${NEW_URL}" && "${NEW_URL}" == "${OLD_URL}" ]] && grep -q '^ bottle do' tap-repo/Formula/mfc.rb; then
122- awk '/^ bottle do/,/^ end$/' tap-repo/Formula/mfc.rb > /tmp/bottle.block
123- awk '{ print } /^ head / { print ""; while ((getline line < "/tmp/bottle.block") > 0) print line }' \
124- packaging/homebrew/mfc.rb > tap-repo/Formula/mfc.rb
125- else
126- cp packaging/homebrew/mfc.rb tap-repo/Formula/mfc.rb
112+ SRC=packaging/homebrew/mfc.rb
113+ TAP=tap-repo/Formula/mfc.rb
114+ get_ver() { grep -Eo '/archive/refs/tags/v[0-9]+\.[0-9]+\.[0-9]+\.tar\.gz' "$1" | head -n 1 | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+'; }
115+ MERGED="$(mktemp)"
116+ cp "${SRC}" "${MERGED}"
117+ if [[ -f "${TAP}" ]]; then
118+ SRC_VER="$(get_ver "${SRC}" || true)"
119+ TAP_VER="$(get_ver "${TAP}" || true)"
120+ # homebrew-release.yml bumps the tap directly on releases, so the in-repo
121+ # formula can lag behind. Never downgrade: if the tap pins a newer release,
122+ # keep the tap's url/sha256 while still syncing the rest of the formula.
123+ if [[ -n "${SRC_VER}" && -n "${TAP_VER}" && "${SRC_VER}" != "${TAP_VER}" ]] \
124+ && [[ "$(printf '%s\n%s\n' "${SRC_VER}" "${TAP_VER}" | sort -V | tail -n 1)" == "${TAP_VER}" ]]; then
125+ TAP_URL_LINE="$(grep -E '^ url ' "${TAP}")"
126+ TAP_SHA_LINE="$(grep -E '^ sha256 "' "${TAP}" | head -n 1)"
127+ awk -v url="${TAP_URL_LINE}" -v sha="${TAP_SHA_LINE}" \
128+ '/^ url / { print url; next } /^ sha256 "/ { print sha; next } { print }' \
129+ "${SRC}" > "${MERGED}"
130+ fi
131+ # If the pinned release is unchanged, keep the tap's existing bottle block so a
132+ # formula-only push to master doesn't delete bottles already built for this version.
133+ if [[ "$(grep -E '^ url ' "${MERGED}")" == "$(grep -E '^ url ' "${TAP}")" ]] && grep -q '^ bottle do' "${TAP}"; then
134+ awk '/^ bottle do/,/^ end$/' "${TAP}" > /tmp/bottle.block
135+ awk '{ print } /^ head / { print ""; while ((getline line < "/tmp/bottle.block") > 0) print line }' \
136+ "${MERGED}" > "${MERGED}.tmp" && mv "${MERGED}.tmp" "${MERGED}"
137+ fi
127138 fi
139+ mv "${MERGED}" "${TAP}"
128140 cp packaging/homebrew/README.md tap-repo/README.md
141+ echo "version=$(get_ver "${TAP}" || true)" >> "$GITHUB_OUTPUT"
129142
130143 - name : Commit & push if changed
131144 if : github.event_name != 'pull_request'
@@ -139,6 +152,6 @@ jobs:
139152 exit 0
140153 fi
141154 git -c user.name="github-actions[bot]" -c user.email="github-actions[bot]@users.noreply.github.com" \
142- commit -m "mfc: v${{ steps.meta.outputs.version }}"
155+ commit -m "mfc: v${{ steps.merge.outputs.version || steps. meta.outputs.version }}"
143156 git push origin HEAD:main
144157
0 commit comments