Skip to content

Commit 004e2ba

Browse files
authored
Update GitHub Actions workflow for bottle management
1 parent 18ccb8e commit 004e2ba

1 file changed

Lines changed: 58 additions & 48 deletions

File tree

.github/workflows/bottle.yml

Lines changed: 58 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ jobs:
2525
- name: Set up Homebrew
2626
uses: Homebrew/actions/setup-homebrew@master
2727

28+
- name: Ensure no conflicting taps provide mfc
29+
shell: bash
30+
run: |
31+
set -euo pipefail
32+
brew untap mflowcode/mfc >/dev/null 2>&1 || true
33+
brew untap mflowcode/local >/dev/null 2>&1 || true
34+
2835
- name: Test tarball download
2936
run: |
3037
curl -I "https://github.com/MFlowCode/MFC/archive/refs/tags/v5.1.5.tar.gz"
@@ -238,79 +245,82 @@ jobs:
238245
echo "Bottles ready for upload:"
239246
ls -1 bottles/*.bottle.*
240247
241-
- name: Tap this checkout as mflowcode/local (so brew can find mflowcode/local/mfc)
248+
- name: Ensure no conflicting taps provide mfc (merge job)
242249
shell: bash
243250
run: |
244251
set -euo pipefail
245-
246-
# Ensure a clean state if a previous run left the tap installed
252+
brew untap mflowcode/mfc >/dev/null 2>&1 || true
247253
brew untap mflowcode/local >/dev/null 2>&1 || true
248254
249-
# Tap the checked-out repository as a local tap
250-
brew tap mflowcode/local "${GITHUB_WORKSPACE}"
255+
- name: Create temp tap for merge and copy formula into it
256+
shell: bash
257+
run: |
258+
set -euo pipefail
259+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
260+
git config --global user.name "github-actions[bot]"
251261
252-
# Verify the tap exists (brew tap with no args lists taps)
253-
brew tap | grep -q '^mflowcode/local$'
262+
brew tap-new mflowcode/local
263+
TAP_DIR="$(brew --repository)/Library/Taps/mflowcode/homebrew-local"
264+
mkdir -p "${TAP_DIR}/Formula"
265+
cp Formula/mfc.rb "${TAP_DIR}/Formula/mfc.rb"
254266

255-
# Verify the formula resolves
256267
brew info mflowcode/local/mfc
257268

258-
- name: Merge bottle metadata into formula
259-
id: merge
260-
run: |
261-
set -euo pipefail
269+
- name: Merge bottle metadata into formula
270+
id: merge
271+
shell: bash
272+
run: |
273+
set -euo pipefail
262274
263-
JSON_BOTTLES=(bottles/*.bottle*.json)
264-
if [[ ! -e "${JSON_BOTTLES[0]}" ]]; then
265-
echo "No bottle metadata (*.bottle*.json) found in bottles/"
266-
ls -la bottles/
267-
exit 1
268-
fi
275+
JSON_BOTTLES=(bottles/*.bottle*.json)
276+
if [[ ! -e "${JSON_BOTTLES[0]}" ]]; then
277+
echo "No bottle metadata (*.bottle*.json) found in bottles/"
278+
ls -la bottles/
279+
exit 1
280+
fi
269281

270-
echo "Merging bottle metadata from:"
271-
printf '%s\n' "${JSON_BOTTLES[@]}"
282+
TAP_DIR="$(brew --repository)/Library/Taps/mflowcode/homebrew-local"
272283

273-
BEFORE_SHA=$(git rev-parse HEAD)
274-
echo "HEAD before merge: ${BEFORE_SHA}"
284+
echo "Merging bottle metadata from:"
285+
printf '%s\n' "${JSON_BOTTLES[@]}"
275286

276-
brew bottle --merge --write --root-url="${{ steps.meta.outputs.root_url }}" "${JSON_BOTTLES[@]}"
287+
brew bottle --merge --write --root-url="${{ steps.meta.outputs.root_url }}" "${JSON_BOTTLES[@]}"
277288

278-
AFTER_SHA=$(git rev-parse HEAD)
279-
echo "HEAD after merge: ${AFTER_SHA}"
289+
# Copy the updated formula back into this checkout so git add works here
290+
cp "${TAP_DIR}/Formula/mfc.rb" Formula/mfc.rb
280291

281-
if [[ "${BEFORE_SHA}" != "${AFTER_SHA}" ]]; then
282-
echo "✅ New bottle commit created by brew bottle --write"
283-
echo "bottle_updated=true" >> "$GITHUB_OUTPUT"
284-
else
285-
echo "ℹ️ No new commit (bottles unchanged or already present)"
286-
echo "bottle_updated=false" >> "$GITHUB_OUTPUT"
287-
fi
292+
if git diff --quiet -- Formula/mfc.rb; then
293+
echo "bottle_updated=false" >> "$GITHUB_OUTPUT"
294+
else
295+
echo "bottle_updated=true" >> "$GITHUB_OUTPUT"
296+
fi
288297

298+
- name: Commit formula update if changed
299+
if: steps.merge.outputs.bottle_updated == 'true'
300+
shell: bash
301+
run: |
302+
set -euo pipefail
303+
git add Formula/mfc.rb
304+
if git diff --cached --quiet; then
305+
echo "No changes staged; skipping commit."
306+
exit 0
307+
fi
308+
git commit -m "mfc: bottles for v${{ steps.meta.outputs.version }}"
309+
289310
- name: Push bottle updates if changed
290311
if: steps.merge.outputs.bottle_updated == 'true'
312+
shell: bash
291313
run: |
292314
set -euo pipefail
293-
294-
echo "Pushing bottle update commit..."
295-
git log -1 --stat
296-
297-
git config --local --unset-all http.https://github.com/.extraheader || true
298-
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git
299-
315+
git remote set-url origin "https://x-access-token:${{ github.token }}@github.com/${{ github.repository }}.git"
300316
git push origin HEAD:main
301317
302-
- name: Create or update GitHub Release
318+
- name: Create/update release and upload bottles
303319
uses: softprops/action-gh-release@v1
304320
with:
305321
tag_name: ${{ steps.meta.outputs.tag }}
306322
name: MFC bottles ${{ steps.meta.outputs.version }}
307-
env:
308-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
309-
310-
- name: Upload bottles to Release
311-
uses: softprops/action-gh-release@v1
312-
with:
313-
tag_name: ${{ steps.meta.outputs.tag }}
314323
files: bottles/*.bottle.*
324+
fail_on_unmatched_files: true
315325
env:
316-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
326+
GITHUB_TOKEN: ${{ github.token }}

0 commit comments

Comments
 (0)