-
Notifications
You must be signed in to change notification settings - Fork 171
198 lines (169 loc) · 7.81 KB
/
Copy pathhomebrew-release.yml
File metadata and controls
198 lines (169 loc) · 7.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
name: Update Homebrew Formula on Release
# Triggers when a new version tag is pushed
on:
push:
tags:
- 'v*'
pull_request:
branches: [master]
paths:
- '.github/workflows/homebrew-release.yml'
workflow_dispatch:
inputs:
version:
description: 'Version to release (without v prefix, e.g., 5.2.0)'
required: true
type: string
dry_run:
description: 'Dry run (skip push to homebrew-mfc)'
required: false
type: boolean
default: false
# Least-privilege default: no job in this workflow writes to the repo.
permissions:
contents: read
jobs:
update-homebrew-tap:
name: Update homebrew-mfc tap
runs-on: ubuntu-latest
environment:
name: homebrew
url: https://github.com/MFlowCode/homebrew-mfc
steps:
- name: Determine version
id: version
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
VERSION="${{ inputs.version }}"
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
# Use existing version for PR testing
VERSION="5.2.0"
echo "::notice::PR test mode - using version $VERSION"
else
# Extract version from tag (remove 'v' prefix)
VERSION="${GITHUB_REF#refs/tags/v}"
fi
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::error::Invalid version format: $VERSION (expected X.Y.Z)"
exit 1
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Version: $VERSION"
- name: Compute SHA256 of release tarball
id: sha256
run: |
VERSION="${{ steps.version.outputs.version }}"
URL="https://github.com/MFlowCode/MFC/archive/refs/tags/v${VERSION}.tar.gz"
echo "Downloading tarball from: $URL"
# Verify URL is reachable
HTTP_CODE=$(curl -sI -w "%{http_code}" -o /dev/null "$URL")
if [[ "$HTTP_CODE" != "200" && "$HTTP_CODE" != "302" ]]; then
echo "::error::Release tarball not found at $URL (HTTP $HTTP_CODE)"
echo "::error::Make sure the tag v${VERSION} exists and the release is published"
exit 1
fi
# Compute SHA256
SHA256=$(curl -sL "$URL" | sha256sum | awk '{print $1}')
if [[ -z "$SHA256" || "$SHA256" == "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" ]]; then
echo "::error::Failed to compute SHA256 (empty file or download failed)"
exit 1
fi
echo "sha256=$SHA256" >> "$GITHUB_OUTPUT"
echo "SHA256: $SHA256"
- name: PR test summary
if: ${{ github.event_name == 'pull_request' }}
run: |
echo "## PR Test Mode" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Validated:" >> $GITHUB_STEP_SUMMARY
echo "- Version parsing: v${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "- SHA256 computation: \`${{ steps.sha256.outputs.sha256 }}\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Skipped (secrets not available for fork PRs):" >> $GITHUB_STEP_SUMMARY
echo "- Checkout homebrew-mfc" >> $GITHUB_STEP_SUMMARY
echo "- Update formula" >> $GITHUB_STEP_SUMMARY
echo "- Push to tap" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "The full workflow will run when a \`v*\` tag is pushed after merge." >> $GITHUB_STEP_SUMMARY
- name: Checkout homebrew-mfc tap
if: ${{ github.event_name != 'pull_request' }}
uses: actions/checkout@v5
with:
repository: MFlowCode/homebrew-mfc
token: ${{ secrets.TAP_REPO_TOKEN }}
path: homebrew-mfc
- name: Update formula
if: ${{ github.event_name != 'pull_request' }}
run: |
VERSION="${{ steps.version.outputs.version }}"
SHA256="${{ steps.sha256.outputs.sha256 }}"
FORMULA="homebrew-mfc/Formula/mfc.rb"
echo "Updating formula to v${VERSION}..."
# Update URL (match any GitHub archive URL, not just MFlowCode/MFC,
# in case the formula temporarily points at a fork during testing)
sed -i "s|url \"https://github.com/[^\"]*/archive/[^\"]*\.tar\.gz\"|url \"https://github.com/MFlowCode/MFC/archive/refs/tags/v${VERSION}.tar.gz\"|" "$FORMULA"
# Update SHA256 (the one right after url, not bottle SHAs)
# This uses awk to only update the first sha256 after the url line
awk -v newsha="$SHA256" '
/^ url "https:\/\/github.com\// { found_url=1 }
found_url && /^ sha256 "/ && !updated {
sub(/sha256 "[^"]*"/, "sha256 \"" newsha "\"")
updated=1
}
{ print }
' "$FORMULA" > "$FORMULA.tmp" && mv "$FORMULA.tmp" "$FORMULA"
# Remove existing bottle block (new bottles will be built by bottle.yml)
# This removes everything between "bottle do" and the matching "end"
awk '
/^ bottle do/ { in_bottle=1; next }
in_bottle && /^ end/ { in_bottle=0; next }
!in_bottle { print }
' "$FORMULA" > "$FORMULA.tmp" && mv "$FORMULA.tmp" "$FORMULA"
echo "Updated formula:"
head -30 "$FORMULA"
- name: Validate updated formula
if: ${{ github.event_name != 'pull_request' }}
run: |
cd homebrew-mfc
echo "Checking Ruby syntax..."
ruby -c Formula/mfc.rb
echo "Verifying URL and SHA256 were updated..."
grep -q "v${{ steps.version.outputs.version }}.tar.gz" Formula/mfc.rb || (echo "::error::URL not updated"; exit 1)
grep -q "${{ steps.sha256.outputs.sha256 }}" Formula/mfc.rb || (echo "::error::SHA256 not updated"; exit 1)
echo "Formula validation passed!"
- name: Commit and push to homebrew-mfc
if: ${{ github.event_name != 'pull_request' && github.event.inputs.dry_run != 'true' }}
run: |
cd homebrew-mfc
VERSION="${{ steps.version.outputs.version }}"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add Formula/mfc.rb
if git diff --cached --quiet; then
echo "::notice::Formula already up to date for v${VERSION} — nothing to push."
else
git commit -m "Update MFC to v${VERSION}"
echo "Pushing to homebrew-mfc..."
git push origin main
echo "Successfully pushed formula update!"
echo "The bottle.yml workflow in homebrew-mfc will now build bottles automatically."
fi
- name: Dry run summary
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.dry_run == 'true' }}
run: |
echo "::notice::DRY RUN - skipped push to homebrew-mfc"
echo ""
echo "Would have committed the following changes:"
cd homebrew-mfc
git diff Formula/mfc.rb
- name: Summary
if: ${{ github.event_name != 'pull_request' }}
run: |
VERSION="${{ steps.version.outputs.version }}"
echo "## Homebrew Formula Updated" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Version:** v${VERSION}" >> $GITHUB_STEP_SUMMARY
echo "- **SHA256:** \`${{ steps.sha256.outputs.sha256 }}\`" >> $GITHUB_STEP_SUMMARY
echo "- **Tap:** [MFlowCode/homebrew-mfc](https://github.com/MFlowCode/homebrew-mfc)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "The [bottle.yml](https://github.com/MFlowCode/homebrew-mfc/actions/workflows/bottle.yml) workflow will now build bottles for this release." >> $GITHUB_STEP_SUMMARY