Skip to content

Commit 76bd83d

Browse files
authored
ci: fix code.json metadata, drop intel mac build (#70)
1 parent 07c732b commit 76bd83d

2 files changed

Lines changed: 127 additions & 3 deletions

File tree

.github/workflows/release.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
strategy:
1919
fail-fast: false
2020
matrix:
21-
os: [ubuntu-22.04, macos-14, macos-15-intel, windows-2022]
21+
os: [ubuntu-22.04, macos-14, windows-2022]
2222
defaults:
2323
run:
2424
shell: bash
@@ -57,8 +57,7 @@ jobs:
5757
version=${{ env.GCC_V }}
5858
brew_prefix="$(brew --prefix)"
5959
libpath="$brew_prefix/opt/gcc@$version/lib/gcc/$version"
60-
# libgcc_s.1.1 has no static counterpart on Intel; only hide it on ARM
61-
[[ "$(uname -m)" == "arm64" ]] && mv $libpath/libgcc_s.1.1.dylib $libpath/libgcc_s.1.1.dylib.bak
60+
mv $libpath/libgcc_s.1.1.dylib $libpath/libgcc_s.1.1.dylib.bak
6261
mv $libpath/libgfortran.5.dylib $libpath/libgfortran.5.dylib.bak
6362
mv $libpath/libquadmath.0.dylib $libpath/libquadmath.0.dylib.bak
6463
mv $libpath/libstdc++.6.dylib $libpath/libstdc++.6.dylib.bak
@@ -112,6 +111,14 @@ jobs:
112111
pixi run --manifest-path modflow6/pixi.toml make-program mf2005,mfusg,mfnwt,mflgr --appdir $ostag --double --keep --zip $ostag.zip --verbose
113112
pixi run --manifest-path modflow6/pixi.toml make-code-json --appdir $ostag --zip $ostag.zip --verbose
114113
114+
- name: Patch code.json with fetched program versions
115+
run: |
116+
ostag="${{ steps.ostag.outputs.ostag }}"
117+
pixi run --manifest-path modflow6/pixi.toml python scripts/patch_code_json.py \
118+
--manifest releases.json \
119+
--ostag $ostag \
120+
--zip $ostag.zip
121+
115122
- name: Show programs
116123
run: |
117124
ostag="${{ steps.ostag.outputs.ostag }}"

scripts/patch_code_json.py

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
"""Patch code.json with correct version info for programs fetched from releases.json.
2+
3+
make-code-json reads versions from pymake's internal program catalog, which may
4+
be out of date relative to the versions actually fetched. This script overwrites
5+
the version (and url) for each program listed in releases.json with the values
6+
from the releases.json manifest.
7+
8+
Usage:
9+
python patch_code_json.py --manifest releases.json --ostag linux --zip linux.zip
10+
python patch_code_json.py --manifest releases.json --ostag linux code.json
11+
"""
12+
13+
import argparse
14+
import datetime
15+
import json
16+
import sys
17+
import urllib.request
18+
import zipfile
19+
from pathlib import Path
20+
21+
GITHUB_URL = "https://github.com/{repo}/releases/download/{tag}/{asset}"
22+
23+
24+
def _get_url_date(url):
25+
"""Fetch Last-Modified date from a URL's response headers."""
26+
try:
27+
req = urllib.request.Request(url, method="HEAD")
28+
with urllib.request.urlopen(req, timeout=10) as resp:
29+
for key in ("Last-Modified", "Date"):
30+
val = resp.headers.get(key)
31+
if val:
32+
dt = datetime.datetime.strptime(val, "%a, %d %b %Y %H:%M:%S %Z")
33+
return dt.strftime("%m/%d/%Y")
34+
except Exception:
35+
pass
36+
return None
37+
38+
39+
def patch(manifest_path, code_json_path, ostag, zip_path=None):
40+
with open(manifest_path) as f:
41+
manifest = json.load(f)
42+
43+
code_json_path = Path(code_json_path)
44+
if not code_json_path.exists():
45+
print(f"code.json not found: {code_json_path}", file=sys.stderr)
46+
sys.exit(1)
47+
48+
with open(code_json_path) as f:
49+
code = json.load(f)
50+
51+
changed = []
52+
for entry in manifest:
53+
repo = entry["repo"]
54+
tag = entry["tag"]
55+
version = tag.lstrip("v")
56+
asset = entry["assets"].get(ostag)
57+
url = GITHUB_URL.format(repo=repo, tag=tag, asset=asset) if asset else None
58+
59+
for prog_name in entry["programs"]:
60+
if prog_name not in code:
61+
continue
62+
prev_version = code[prog_name].get("version")
63+
if prev_version == version:
64+
continue
65+
code[prog_name]["version"] = version
66+
if url:
67+
code[prog_name]["url"] = url
68+
date = _get_url_date(url)
69+
if date:
70+
code[prog_name]["url_download_asset_date"] = date
71+
changed.append(f" {prog_name}: {prev_version!r} -> {version!r}")
72+
73+
if not changed:
74+
print("code.json already up to date")
75+
return
76+
77+
for line in changed:
78+
print(line)
79+
80+
code_json_path.write_text(json.dumps(code, indent=4) + "\n")
81+
print(f"wrote {code_json_path}")
82+
83+
if zip_path and Path(zip_path).exists():
84+
with zipfile.ZipFile(zip_path, "a", zipfile.ZIP_DEFLATED) as zf:
85+
zf.write(code_json_path, "code.json")
86+
print(f"updated code.json in {zip_path}")
87+
88+
89+
def main():
90+
parser = argparse.ArgumentParser(description=__doc__.split("\n")[0])
91+
parser.add_argument(
92+
"code_json",
93+
nargs="?",
94+
default="code.json",
95+
help="path to code.json to patch (default: code.json)",
96+
)
97+
parser.add_argument(
98+
"--manifest",
99+
default="releases.json",
100+
help="path to releases.json manifest (default: releases.json)",
101+
)
102+
parser.add_argument(
103+
"--ostag",
104+
required=True,
105+
help="platform tag (linux, mac, macarm, win64)",
106+
)
107+
parser.add_argument(
108+
"--zip",
109+
dest="zip_path",
110+
help="zip file to update with the patched code.json",
111+
)
112+
args = parser.parse_args()
113+
patch(args.manifest, args.code_json, args.ostag, args.zip_path)
114+
115+
116+
if __name__ == "__main__":
117+
main()

0 commit comments

Comments
 (0)