Skip to content

Add workflow to build and publish Homebrew bottles #47

Add workflow to build and publish Homebrew bottles

Add workflow to build and publish Homebrew bottles #47

Workflow file for this run

name: Bottle
on:
push:
branches:
- main
paths:
- 'Formula/**'
- '.github/workflows/bottle.yml'
workflow_dispatch:
permissions:
contents: write
jobs:
test-bot:
strategy:
matrix:
os: [macos-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Set up Homebrew
uses: Homebrew/actions/setup-homebrew@master
- name: Checkout tap
uses: actions/checkout@v4
- name: Set variables
id: set_vars
run: |
echo "root_url=https://github.com/${{ github.repository }}/releases/download/bottles" >> $GITHUB_OUTPUT
- name: Build bottles with test-bot
env:
HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
brew test-bot --only-formulae --skip-dependents --skip-online-checks --root-url="${{ steps.set_vars.outputs.root_url }}" mfc
- name: Upload bottles as artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: bottles-${{ matrix.os }}
path: '*.bottle.*'
if-no-files-found: ignore
- name: Cleanup
if: always()
continue-on-error: true
run: |
brew uninstall --force mfc || true
test-run-case:
needs: test-bot
runs-on: macos-latest
steps:
- name: Set up Homebrew
uses: Homebrew/actions/setup-homebrew@master
- name: Checkout tap
uses: actions/checkout@v4
- name: Install MFC from bottle
run: |
# Wait a moment for bottle to be available
sleep 5
# Install the formula (will use bottle if available)
brew install mflowcode/mfc/mfc || brew install --build-from-source mflowcode/mfc/mfc
- name: Run Sod shock tube test case
run: |
mkdir -p ~/test_mfc_case
cd ~/test_mfc_case
cp $(brew --prefix mfc)/examples/1D_sodshocktube/case.py .
mfc case.py -j 1
- name: Verify output
run: |
test -d ~/test_mfc_case/silo_hdf5
echo "✅ Test case ran successfully and produced output"
- name: Cleanup
if: always()
run: |
brew uninstall --force mfc || true
rm -rf ~/test_mfc_case
verify-install:
needs: test-run-case
runs-on: macos-latest
steps:
- name: Set up Homebrew
uses: Homebrew/actions/setup-homebrew@master
- name: Checkout tap
uses: actions/checkout@v4
- name: Install MFC
run: |
brew install mflowcode/mfc/mfc || brew install --build-from-source mflowcode/mfc/mfc
- name: Verify installation
run: |
echo "1. Checking binaries..."
test -x $(brew --prefix mfc)/bin/pre_process
test -x $(brew --prefix mfc)/bin/simulation
test -x $(brew --prefix mfc)/bin/post_process
test -x $(brew --prefix mfc)/bin/mfc
echo "2. Checking toolchain..."
test -d $(brew --prefix mfc)/toolchain
echo "3. Checking Python venv..."
test -d $(brew --prefix mfc)/libexec/venv
test -x $(brew --prefix mfc)/libexec/venv/bin/python
echo "4. Checking examples..."
test -d $(brew --prefix mfc)/examples
echo "5. Testing mfc command..."
mfc --help
echo "✅ All verification checks passed"
- name: Cleanup
if: always()
run: |
brew uninstall --force mfc || true
build-bottle:
name: Build and publish bottles
needs: verify-install # <- only runs if all tests pass
runs-on: macos-14
steps:
- name: Checkout tap
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Homebrew
uses: Homebrew/actions/setup-homebrew@master
- name: Determine version and root URL
id: meta
run: |
set -euo pipefail
VERSION=$(grep -E 'version "[0-9]+\.[0-9]+\.[0-9]+"' Formula/mfc.rb | sed -E 's/.*version "([^"]+)".*/\1/')
TAG="mfc-${VERSION}"
ROOT_URL="https://github.com/${GITHUB_REPOSITORY}/releases/download/${TAG}"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
echo "root_url=${ROOT_URL}" >> "$GITHUB_OUTPUT"
- name: Install formula with --build-bottle
run: |
set -euo pipefail
brew install --build-bottle ./Formula/mfc.rb
- name: Build bottle
run: |
set -euo pipefail
brew bottle --root-url="${{ steps.meta.outputs.root_url }}" mfc
ls -1 *.bottle.*
- name: Merge bottle into formula
run: |
set -euo pipefail
JSON_BOTTLES=(*.bottle*.json)
if [[ -e "${JSON_BOTTLES[0]}" ]]; then
brew bottle --merge --write "${JSON_BOTTLES[@]}"
else
RB_BOTTLES=(*.bottle*.rb)
brew bottle --merge --write "${RB_BOTTLES[@]}"
fi
- name: Commit updated bottle block
run: |
set -euo pipefail
if git diff --quiet Formula/mfc.rb; then
echo "No changes to Formula/mfc.rb; skipping commit."
exit 0
fi
git add Formula/mfc.rb
git -c user.name="github-actions[bot]" \
-c user.email="github-actions[bot]@users.noreply.github.com" \
commit -m "mfc: update bottles for ${{ steps.meta.outputs.version }}"
git push origin HEAD:main
- name: Create or update GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.meta.outputs.tag }}
name: MFC bottles ${{ steps.meta.outputs.version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload bottles to Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.meta.outputs.tag }}
files: |
*.bottle.*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}