|
| 1 | +name: Deploy Homebrew Tap |
| 2 | + |
| 3 | +on: |
| 4 | + # Test formula on PRs (audit only, don't deploy) |
| 5 | + pull_request: |
| 6 | + branches: [ master ] |
| 7 | + paths: |
| 8 | + - 'packaging/homebrew/mfc.rb' |
| 9 | + - 'packaging/homebrew/README.md' |
| 10 | + # Deploy to tap on push to master |
| 11 | + push: |
| 12 | + branches: [ master, homebrew-new ] |
| 13 | + paths: |
| 14 | + - 'packaging/homebrew/mfc.rb' |
| 15 | + - 'packaging/homebrew/README.md' |
| 16 | + tags: |
| 17 | + - 'v*.*.*' |
| 18 | + # Allow manual trigger for testing |
| 19 | + workflow_dispatch: |
| 20 | + |
| 21 | +permissions: |
| 22 | + contents: read |
| 23 | + |
| 24 | +jobs: |
| 25 | + deploy-tap: |
| 26 | + name: Audit and deploy formula |
| 27 | + runs-on: macos-14 |
| 28 | + permissions: |
| 29 | + contents: write |
| 30 | + pull-requests: write |
| 31 | + steps: |
| 32 | + - name: Checkout MFC repository |
| 33 | + uses: actions/checkout@v4 |
| 34 | + with: |
| 35 | + fetch-depth: 0 |
| 36 | + |
| 37 | + - name: Determine event metadata |
| 38 | + id: meta |
| 39 | + run: | |
| 40 | + if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then |
| 41 | + VERSION="${GITHUB_REF_NAME#v}" |
| 42 | + URL="https://github.com/${{ github.repository }}/archive/refs/tags/v${VERSION}.tar.gz" |
| 43 | + else |
| 44 | + # Extract URL from current formula to re-audit and sync |
| 45 | + URL="$(grep -Eo 'https://github.com/.*/archive/refs/tags/v[0-9]+\.[0-9]+\.[0-9]+\.tar\.gz' packaging/homebrew/mfc.rb | head -n1)" |
| 46 | + VERSION="$(echo "${URL}" | sed -E 's/.*v([0-9]+\.[0-9]+\.[0-9]+)\.tar\.gz/\1/')" |
| 47 | + fi |
| 48 | + SHASUM="$(curl -sL "${URL}" | shasum -a 256 | awk '{print $1}')" |
| 49 | + echo "version=${VERSION}" >> $GITHUB_OUTPUT |
| 50 | + echo "url=${URL}" >> $GITHUB_OUTPUT |
| 51 | + echo "sha256=${SHASUM}" >> $GITHUB_OUTPUT |
| 52 | + echo "Event: ${{ github.event_name }}" >> $GITHUB_STEP_SUMMARY |
| 53 | + echo "Version: ${VERSION}" >> $GITHUB_STEP_SUMMARY |
| 54 | + if [[ "${{ github.event_name }}" == "pull_request" ]]; then |
| 55 | + echo "Mode: Audit only (PR)" >> $GITHUB_STEP_SUMMARY |
| 56 | + else |
| 57 | + echo "Mode: Audit and deploy" >> $GITHUB_STEP_SUMMARY |
| 58 | + fi |
| 59 | +
|
| 60 | + - name: Update formula (for tag events) |
| 61 | + if: github.ref_type == 'tag' |
| 62 | + run: | |
| 63 | + /usr/bin/sed -i '' "s@^ url \".*\"@ url \"${{ steps.meta.outputs.url }}\"@" packaging/homebrew/mfc.rb |
| 64 | + /usr/bin/sed -i '' "s@^ sha256 \".*\"@ sha256 \"${{ steps.meta.outputs.sha256 }}\"@" packaging/homebrew/mfc.rb |
| 65 | +
|
| 66 | + - name: Setup Homebrew |
| 67 | + uses: Homebrew/actions/setup-homebrew@master |
| 68 | + |
| 69 | + - name: Audit/style formula before pushing |
| 70 | + run: | |
| 71 | + brew style packaging/homebrew/mfc.rb |
| 72 | + # Create temporary tap to audit the formula |
| 73 | + brew tap-new mfc/local |
| 74 | + cp packaging/homebrew/mfc.rb "$(brew --repository)/Library/Taps/mfc/homebrew-local/Formula/mfc.rb" |
| 75 | + brew audit --online --strict --new --except=homepage mfc/local/mfc || brew audit --online mfc/local/mfc |
| 76 | + brew untap mfc/local |
| 77 | +
|
| 78 | + - name: Clone or bootstrap tap repository |
| 79 | + if: github.event_name != 'pull_request' |
| 80 | + env: |
| 81 | + TAP_TOKEN: ${{ secrets.TAP_REPO_TOKEN }} |
| 82 | + run: | |
| 83 | + set -euo pipefail |
| 84 | + REPO="https://x-access-token:${TAP_TOKEN}@github.com/MFlowCode/homebrew-mfc.git" |
| 85 | + if git ls-remote "${REPO}" HEAD >/dev/null 2>&1; then |
| 86 | + git clone "${REPO}" tap-repo |
| 87 | + else |
| 88 | + # Repo exists but might be empty; fall back to bootstrap |
| 89 | + mkdir -p tap-repo |
| 90 | + cd tap-repo |
| 91 | + git init -b main |
| 92 | + git remote add origin "${REPO}" |
| 93 | + touch .keep |
| 94 | + git add .keep |
| 95 | + git -c user.name="github-actions[bot]" -c user.email="github-actions[bot]@users.noreply.github.com" commit -m "Initialize tap" |
| 96 | + git push -u origin main |
| 97 | + fi |
| 98 | +
|
| 99 | + - name: Copy formula and README into tap |
| 100 | + if: github.event_name != 'pull_request' |
| 101 | + run: | |
| 102 | + mkdir -p tap-repo/Formula |
| 103 | + cp packaging/homebrew/mfc.rb tap-repo/Formula/mfc.rb |
| 104 | + cp packaging/homebrew/README.md tap-repo/README.md |
| 105 | +
|
| 106 | + - name: Commit & push if changed |
| 107 | + if: github.event_name != 'pull_request' |
| 108 | + env: |
| 109 | + TAP_TOKEN: ${{ secrets.TAP_REPO_TOKEN }} |
| 110 | + run: | |
| 111 | + cd tap-repo |
| 112 | + git add Formula/mfc.rb README.md |
| 113 | + if git diff --cached --quiet; then |
| 114 | + echo "No changes in Formula/mfc.rb or README.md; skipping push." |
| 115 | + exit 0 |
| 116 | + fi |
| 117 | + git -c user.name="github-actions[bot]" -c user.email="github-actions[bot]@users.noreply.github.com" \ |
| 118 | + commit -m "mfc: v${{ steps.meta.outputs.version }}" |
| 119 | + git push origin HEAD:main |
| 120 | +
|
0 commit comments