Skip to content

Commit 32bd630

Browse files
authored
homebrew: fix toolchain install without git metadata (#1098)
1 parent 49d4ae9 commit 32bd630

File tree

2 files changed

+37
-17
lines changed

2 files changed

+37
-17
lines changed

.github/workflows/deploy-tap.yml

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@ on:
77
paths:
88
- 'packaging/homebrew/mfc.rb'
99
- 'packaging/homebrew/README.md'
10-
# Deploy to tap on push to master
10+
# Deploy to tap on push to master (only when formula files changed)
1111
push:
12-
branches: [ master, homebrew-new ]
12+
branches: [ master ]
1313
paths:
1414
- 'packaging/homebrew/mfc.rb'
1515
- 'packaging/homebrew/README.md'
16-
tags:
17-
- 'v*.*.*'
18-
# Allow manual trigger for testing
16+
# Deploy to tap when a tag is created (no paths filter on tag creation)
17+
create:
1918
workflow_dispatch:
2019

2120
permissions:
@@ -25,6 +24,7 @@ jobs:
2524
deploy-tap:
2625
name: Audit and deploy formula
2726
runs-on: macos-14
27+
if: github.event_name != 'create' || github.event.ref_type == 'tag'
2828
permissions:
2929
contents: write
3030
pull-requests: write
@@ -37,28 +37,38 @@ jobs:
3737
- name: Determine event metadata
3838
id: meta
3939
run: |
40-
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
41-
VERSION="${GITHUB_REF_NAME#v}"
40+
set -euo pipefail
41+
EVENT_NAME="${{ github.event_name }}"
42+
REF_NAME="${{ github.ref_name }}"
43+
44+
if [[ "${EVENT_NAME}" == "create" ]]; then
45+
# Tag creation event
46+
VERSION="${REF_NAME#v}"
47+
URL="https://github.com/${{ github.repository }}/archive/refs/tags/v${VERSION}.tar.gz"
48+
elif [[ "${GITHUB_REF_TYPE:-}" == "tag" ]]; then
49+
# Tag push event
50+
VERSION="${REF_NAME#v}"
4251
URL="https://github.com/${{ github.repository }}/archive/refs/tags/v${VERSION}.tar.gz"
4352
else
4453
# 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)"
54+
URL="$(grep -Eo 'https://github.com/[^"]+/archive/refs/tags/v[0-9]+\.[0-9]+\.[0-9]+\.tar\.gz' packaging/homebrew/mfc.rb | tail -n 1)"
4655
VERSION="$(echo "${URL}" | sed -E 's/.*v([0-9]+\.[0-9]+\.[0-9]+)\.tar\.gz/\1/')"
4756
fi
57+
4858
SHASUM="$(curl -sL "${URL}" | shasum -a 256 | awk '{print $1}')"
4959
echo "version=${VERSION}" >> $GITHUB_OUTPUT
5060
echo "url=${URL}" >> $GITHUB_OUTPUT
5161
echo "sha256=${SHASUM}" >> $GITHUB_OUTPUT
52-
echo "Event: ${{ github.event_name }}" >> $GITHUB_STEP_SUMMARY
62+
echo "Event: ${EVENT_NAME}" >> $GITHUB_STEP_SUMMARY
5363
echo "Version: ${VERSION}" >> $GITHUB_STEP_SUMMARY
54-
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
64+
if [[ "${EVENT_NAME}" == "pull_request" ]]; then
5565
echo "Mode: Audit only (PR)" >> $GITHUB_STEP_SUMMARY
5666
else
5767
echo "Mode: Audit and deploy" >> $GITHUB_STEP_SUMMARY
5868
fi
5969
6070
- name: Update formula (for tag events)
61-
if: github.ref_type == 'tag'
71+
if: github.event_name == 'create' || github.ref_type == 'tag'
6272
run: |
6373
/usr/bin/sed -i '' "s@^ url \".*\"@ url \"${{ steps.meta.outputs.url }}\"@" packaging/homebrew/mfc.rb
6474
/usr/bin/sed -i '' "s@^ sha256 \".*\"@ sha256 \"${{ steps.meta.outputs.sha256 }}\"@" packaging/homebrew/mfc.rb

packaging/homebrew/mfc.rb

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
class Mfc < Formula
77
desc "Exascale multiphase/multiphysics compressible flow solver"
88
homepage "https://mflowcode.github.io/"
9-
url "https://github.com/MFlowCode/MFC/archive/refs/tags/v5.1.0.tar.gz"
10-
sha256 "4684bee6a529287f243f8929fb7edb0dfebbb04df7c1806459761c9a6c9261cf"
9+
url "https://github.com/MFlowCode/MFC/archive/refs/tags/v5.1.5.tar.gz"
10+
sha256 "229ba4532d9b31e54e7db67cc6c6a4c069034bb143be7c57cba31c5a56fe6a0b"
1111
license "MIT"
1212
head "https://github.com/MFlowCode/MFC.git", branch: "master"
1313

@@ -29,7 +29,11 @@ def install
2929
# Create Python virtual environment inside libexec (inside Cellar for proper bottling)
3030
venv = libexec/"venv"
3131
system Formula["python@3.12"].opt_bin/"python3.12", "-m", "venv", venv
32-
system venv/"bin/pip", "install", "--upgrade", "pip", "setuptools", "wheel", "setuptools-scm"
32+
system venv/"bin/pip", "install", "--upgrade",
33+
"pip", "setuptools", "wheel",
34+
"setuptools-scm",
35+
"hatchling", "hatch-vcs",
36+
"editables"
3337

3438
# Install Cantera from PyPI using pre-built wheel (complex package, doesn't need custom flags)
3539
# Cantera has CMake compatibility issues when building from source with newer CMake versions
@@ -42,8 +46,9 @@ def install
4246
# Keep toolchain in buildpath for now - mfc.sh needs it there
4347
#
4448
# MFC's toolchain uses VCS-derived versioning (via Hatch/hatch-vcs) and Homebrew builds from
45-
# GitHub release tarballs without a .git directory. Scope pretend-version env vars tightly
46-
# to avoid polluting subsequent pip installs.
49+
# GitHub release tarballs without a .git directory. Use --no-build-isolation so the build
50+
# backend can see our environment variables, and set SETUPTOOLS_SCM_PRETEND_VERSION which
51+
# hatch-vcs respects when VCS metadata is unavailable.
4752
pretend_env = {
4853
"SETUPTOOLS_SCM_PRETEND_VERSION_FOR_MFC" => version.to_s,
4954
"SETUPTOOLS_SCM_PRETEND_VERSION_FOR_mfc" => version.to_s,
@@ -56,7 +61,7 @@ def install
5661
end
5762

5863
begin
59-
system venv/"bin/pip", "install", "-e", buildpath/"toolchain"
64+
system venv/"bin/pip", "install", "--no-build-isolation", "-e", buildpath/"toolchain"
6065
ensure
6166
pretend_env.each_key do |k|
6267
if saved_env[k].nil?
@@ -75,6 +80,11 @@ def install
7580
# Set VIRTUAL_ENV so mfc.sh uses existing venv instead of creating new one
7681
ENV["VIRTUAL_ENV"] = venv
7782

83+
# Also set pretend-version env vars for mfc.sh in case it tries to reinstall toolchain
84+
ENV["SETUPTOOLS_SCM_PRETEND_VERSION_FOR_MFC"] = version.to_s
85+
ENV["SETUPTOOLS_SCM_PRETEND_VERSION_FOR_mfc"] = version.to_s
86+
ENV["SETUPTOOLS_SCM_PRETEND_VERSION"] = version.to_s
87+
7888
# Build MFC using pre-configured venv
7989
# Must run from buildpath (MFC root directory) where toolchain/ exists
8090
Dir.chdir(buildpath) do

0 commit comments

Comments
 (0)