Skip to content

Commit ceee0ac

Browse files
committed
improve and deploy
1 parent a24630e commit ceee0ac

File tree

5 files changed

+446
-46
lines changed

5 files changed

+446
-46
lines changed

.github/workflows/deploy-tap.yml

Lines changed: 72 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,97 @@
1-
name: Deploy to Homebrew Tap
1+
name: Deploy Homebrew Tap
22

33
on:
44
push:
5-
branches:
6-
- master
5+
branches: [ main, master, homebrew-formula ]
76
paths:
87
- 'packaging/homebrew/mfc.rb'
8+
push:
9+
tags:
10+
- 'v*.*.*'
911
workflow_dispatch:
1012

1113
permissions:
12-
contents: write
14+
contents: read
1315

1416
jobs:
1517
deploy-tap:
16-
name: Deploy Formula to Tap
17-
runs-on: ubuntu-latest
18+
name: Sync/bump formula in tap
19+
runs-on: macos-14
20+
permissions:
21+
contents: write
22+
pull-requests: write
1823
steps:
1924
- name: Checkout MFC repository
2025
uses: actions/checkout@v4
2126
with:
2227
fetch-depth: 0
23-
24-
- name: Checkout tap repository
25-
uses: actions/checkout@v4
26-
with:
27-
repository: MFlowCode/homebrew-mfc
28-
token: ${{ secrets.GITHUB_TOKEN }}
29-
path: tap-repo
30-
31-
- name: Setup Git
28+
29+
- name: Determine event metadata
30+
id: meta
3231
run: |
33-
git config --global user.name "github-actions[bot]"
34-
git config --global user.email "github-actions[bot]@users.noreply.github.com"
35-
36-
- name: Copy formula to tap
32+
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
33+
VERSION="${GITHUB_REF_NAME#v}"
34+
URL="https://github.com/${{ github.repository }}/archive/refs/tags/v${VERSION}.tar.gz"
35+
else
36+
# Extract URL from current formula to re-audit and sync
37+
URL="$(grep -Eo 'https://github.com/.*/archive/refs/tags/v[0-9]+\.[0-9]+\.[0-9]+\.tar\.gz' packaging/homebrew/mfc.rb | head -n1)"
38+
VERSION="$(echo "${URL}" | sed -E 's/.*v([0-9]+\.[0-9]+\.[0-9]+)\.tar\.gz/\1/')"
39+
fi
40+
SHASUM="$(curl -sL "${URL}" | shasum -a 256 | awk '{print $1}')"
41+
echo "version=${VERSION}" >> $GITHUB_OUTPUT
42+
echo "url=${URL}" >> $GITHUB_OUTPUT
43+
echo "sha256=${SHASUM}" >> $GITHUB_OUTPUT
44+
45+
- name: Update formula (for tag events)
46+
if: github.ref_type == 'tag'
3747
run: |
38-
mkdir -p tap-repo/Formula
39-
cp packaging/homebrew/mfc.rb tap-repo/Formula/mfc.rb
40-
41-
- name: Check for changes
42-
id: check-changes
48+
/usr/bin/sed -i '' "s@^ url \".*\"@ url \"${{ steps.meta.outputs.url }}\"@" packaging/homebrew/mfc.rb
49+
/usr/bin/sed -i '' "s@^ sha256 \".*\"@ sha256 \"${{ steps.meta.outputs.sha256 }}\"@" packaging/homebrew/mfc.rb
50+
51+
- name: Setup Homebrew
52+
uses: Homebrew/actions/setup-homebrew@master
53+
54+
- name: Audit/style formula before pushing
4355
run: |
44-
cd tap-repo
45-
if git ls-files --error-unmatch Formula/mfc.rb >/dev/null 2>&1; then
46-
# File exists in repo, check if it changed
47-
if git diff --quiet HEAD -- Formula/mfc.rb; then
48-
echo "changed=false" >> $GITHUB_OUTPUT
49-
else
50-
echo "changed=true" >> $GITHUB_OUTPUT
51-
fi
56+
brew style packaging/homebrew/mfc.rb
57+
brew audit --online --strict --formula --new --except=homepage packaging/homebrew/mfc.rb || brew audit --online packaging/homebrew/mfc.rb
58+
59+
- name: Clone or bootstrap tap repository
60+
env:
61+
TAP_TOKEN: ${{ secrets.TAP_REPO_TOKEN }}
62+
run: |
63+
set -euo pipefail
64+
REPO="https://x-access-token:${TAP_TOKEN}@github.com/MFlowCode/homebrew-mfc.git"
65+
if git ls-remote "${REPO}" HEAD >/dev/null 2>&1; then
66+
git clone "${REPO}" tap-repo
5267
else
53-
# File doesn't exist in repo, it's a new file
54-
echo "changed=true" >> $GITHUB_OUTPUT
68+
# Repo exists but might be empty; fall back to bootstrap
69+
mkdir -p tap-repo
70+
cd tap-repo
71+
git init -b main
72+
git remote add origin "${REPO}"
73+
touch .keep
74+
git add .keep
75+
git -c user.name="github-actions[bot]" -c user.email="github-actions[bot]@users.noreply.github.com" commit -m "Initialize tap"
76+
git push -u origin main
5577
fi
56-
57-
- name: Commit and push to tap
58-
if: steps.check-changes.outputs.changed == 'true'
78+
79+
- name: Copy formula into tap
5980
run: |
60-
cd tap-repo
61-
git add Formula/mfc.rb
62-
git commit -m "Update mfc formula from MFC repository
81+
mkdir -p tap-repo/Formula
82+
cp packaging/homebrew/mfc.rb tap-repo/Formula/mfc.rb
6383
64-
Auto-deployed from MFlowCode/MFC@${{ github.sha }}"
65-
git push
66-
67-
- name: No changes detected
68-
if: steps.check-changes.outputs.changed == 'false'
84+
- name: Commit & push if changed
85+
env:
86+
TAP_TOKEN: ${{ secrets.TAP_REPO_TOKEN }}
6987
run: |
70-
echo "No changes detected in formula. Skipping deployment."
88+
cd tap-repo
89+
git add Formula/mfc.rb
90+
if git diff --cached --quiet; then
91+
echo "No changes in Formula/mfc.rb; skipping push."
92+
exit 0
93+
fi
94+
git -c user.name="github-actions[bot]" -c user.email="github-actions[bot]@users.noreply.github.com" \
95+
commit -m "mfc: v${{ steps.meta.outputs.version }}"
96+
git push origin HEAD:main
7197
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# Homebrew Tap Deployment Checklist
2+
3+
Use this checklist to complete the Homebrew tap deployment setup.
4+
5+
## ✅ Completed (in this PR)
6+
7+
- [x] Updated `.github/workflows/deploy-tap.yml` with improved CD strategy
8+
- [x] Added formula validation (`brew audit` and `brew style`)
9+
- [x] Added support for version tag bumps
10+
- [x] Added tap repository bootstrap logic
11+
- [x] Changed runner to macOS (required for Homebrew tools)
12+
- [x] Updated `HOMEBREW.md` with deployment details
13+
- [x] Created `SETUP_INSTRUCTIONS.md` with step-by-step guide
14+
- [x] Created `TAP_REPO_SETUP.md` with tap repository configuration
15+
- [x] Created `PR_SUMMARY.md` with overview of changes
16+
17+
## 🔲 Next Steps (after PR merge)
18+
19+
### 1. Add Repository Secret
20+
21+
**In the main repository** (sbryngelson/MFC or MFlowCode/MFC after PR merge):
22+
23+
- [ ] Go to GitHub → (your repository) → Settings → Secrets and variables → Actions
24+
- [ ] Click "New repository secret"
25+
- [ ] Name: `TAP_REPO_TOKEN`
26+
- [ ] Value: Create a Personal Access Token:
27+
1. GitHub → Settings → Developer settings → Personal access tokens → Tokens (classic)
28+
2. Click "Generate new token (classic)"
29+
3. Scopes: Check `repo`
30+
4. Copy the generated token
31+
5. Paste into the secret value
32+
- [ ] Click "Add secret"
33+
34+
**Detailed instructions**: See `SETUP_INSTRUCTIONS.md` section 1-2
35+
36+
### 2. Initialize Tap Repository
37+
38+
**At https://github.com/MFlowCode/homebrew-mfc**:
39+
40+
Choose one:
41+
- [ ] **Option A**: Click "Add a README" in GitHub UI to create first commit
42+
- [ ] **Option B**: Let the workflow bootstrap automatically on first run
43+
44+
### 3. Configure Tap Repository
45+
46+
**At https://github.com/MFlowCode/homebrew-mfc/settings/actions**:
47+
48+
- [ ] Under "Workflow permissions":
49+
- [ ] Select "Read and write permissions"
50+
- [ ] Check "Allow GitHub Actions to create and approve pull requests"
51+
- [ ] Click "Save"
52+
53+
### 4. Add Bottle Workflow to Tap
54+
55+
**Create `.github/workflows/bottle.yml` in the tap repository**:
56+
57+
- [ ] Copy the workflow from `TAP_REPO_SETUP.md` (section "Bottling Workflow")
58+
- [ ] Commit to the tap repository's `main` branch
59+
60+
Alternatively, let the first formula sync complete, then add the workflow for subsequent updates.
61+
62+
### 5. Test the Deployment
63+
64+
**Test formula sync**:
65+
- [ ] Edit `packaging/homebrew/mfc.rb` (make a trivial change)
66+
- [ ] Push to your branch
67+
- [ ] Check Actions tab - workflow should run and sync to tap
68+
- [ ] Verify formula appears at https://github.com/MFlowCode/homebrew-mfc/blob/main/Formula/mfc.rb
69+
70+
**Test version bump** (optional):
71+
- [ ] Create a test tag: `git tag v5.1.0-test && git push origin v5.1.0-test`
72+
- [ ] Check that workflow updates URL and sha256
73+
- [ ] Delete test tag if not needed
74+
75+
### 6. Verify Installation
76+
77+
**Test end-to-end installation**:
78+
```bash
79+
# Add tap
80+
brew tap MFlowCode/mfc
81+
82+
# Install MFC
83+
brew install MFlowCode/mfc/mfc
84+
85+
# Verify
86+
mfc --help
87+
which pre_process simulation post_process
88+
```
89+
90+
## 📋 Reference Documentation
91+
92+
- **Setup Guide**: `SETUP_INSTRUCTIONS.md` - Complete setup walkthrough
93+
- **Tap Configuration**: `TAP_REPO_SETUP.md` - Tap repository setup and bottle workflow
94+
- **PR Overview**: `PR_SUMMARY.md` - Summary of changes and rationale
95+
- **User Guide**: `HOMEBREW.md` - End-user installation and usage documentation
96+
97+
## 🔧 Troubleshooting
98+
99+
### Workflow fails with "Permission denied"
100+
- Verify `TAP_REPO_TOKEN` secret is set in the main repository
101+
- Check that the token has `repo` scope
102+
- Ensure the token hasn't expired
103+
104+
### Formula fails audit
105+
- Read the error message in the Actions log
106+
- Common fixes:
107+
- Update sha256 checksum if source tarball changed
108+
- Fix Ruby syntax errors
109+
- Add missing dependencies
110+
111+
### Tap repository not found
112+
- Initialize the tap repository (Step 2 above)
113+
- Check repository name is exactly `MFlowCode/homebrew-mfc`
114+
115+
### Bottles don't build
116+
- Verify Actions are enabled in tap repository (Step 3 above)
117+
- Check that `.github/workflows/bottle.yml` exists in tap
118+
- Review Actions logs in the tap repository
119+
120+
## 🎉 Success Criteria
121+
122+
You'll know everything is working when:
123+
- ✅ Formula syncs automatically when you push changes
124+
- ✅ Version tags trigger automatic formula bumps
125+
- ✅ Bottles build for macOS 13 (x86_64) and macOS 14 (arm64)
126+
- ✅ Users can install with: `brew install MFlowCode/mfc/mfc`
127+
- ✅ Installation is fast (uses pre-built bottles, not compilation)
128+
129+
## 📞 Need Help?
130+
131+
See the documentation files in `packaging/homebrew/`:
132+
- Start with `SETUP_INSTRUCTIONS.md` for step-by-step guidance
133+
- Check `TAP_REPO_SETUP.md` for tap-specific configuration
134+
- Review `PR_SUMMARY.md` for implementation details
135+

packaging/homebrew/HOMEBREW.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,17 @@ The tap is automatically updated whenever the formula changes in the main MFC re
403403
The tap repository contains:
404404
- `Formula/mfc.rb` - The Homebrew formula file (automatically synced from the main repository)
405405
- Automatic deployment via GitHub Actions when the formula is updated
406+
- Automatic bottle building for both macOS architectures (arm64 and x86_64)
407+
408+
### Deployment Details
409+
410+
The formula is automatically deployed from the main MFC repository using GitHub Actions:
411+
- Changes to `packaging/homebrew/mfc.rb` trigger automatic sync to the tap
412+
- Version tags (e.g., `v5.2.0`) automatically update the formula with new URLs and checksums
413+
- The workflow validates the formula with `brew audit` and `brew style` before deployment
414+
- A `TAP_REPO_TOKEN` secret (Personal Access Token with repo scope) is required in the main repository to push to the tap
415+
416+
See `TAP_REPO_SETUP.md` in this directory for complete tap repository configuration.
406417

407418
## Platform Support
408419

0 commit comments

Comments
 (0)