Add a workflow that runs on release:published (and via manual workflow_dispatch), fetches sha256 checksums from the published release assets, and rewrites razvandimescu/homebrew-tap/numa.rb in place: version, URL paths, and sha256 lines after each url. The formula's existing on_macos/on_linux structure is preserved. Uses HOMEBREW_TAP_GITHUB_TOKEN (already set as a repo secret) to push directly to the tap's main branch. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
58 lines
1.5 KiB
Python
Executable File
58 lines
1.5 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Rewrite a Homebrew formula in place: bump version, URL paths, and sha256 lines.
|
|
|
|
Reads the formula path from argv[1], and the following env vars:
|
|
VERSION e.g. "0.10.0" (no leading v)
|
|
SHA_MACOS_AARCH64
|
|
SHA_MACOS_X86_64
|
|
SHA_LINUX_AARCH64
|
|
SHA_LINUX_X86_64
|
|
|
|
Assumptions about the formula:
|
|
- Has `version "X.Y.Z"` somewhere
|
|
- Has `url "...releases/download/vX.Y.Z/numa-<target>.tar.gz"` lines
|
|
- May or may not already have `sha256 "..."` lines immediately after each url
|
|
"""
|
|
import os
|
|
import re
|
|
import sys
|
|
|
|
formula_path = sys.argv[1]
|
|
version = os.environ["VERSION"].lstrip("v")
|
|
shas = {
|
|
"macos-aarch64": os.environ["SHA_MACOS_AARCH64"],
|
|
"macos-x86_64": os.environ["SHA_MACOS_X86_64"],
|
|
"linux-aarch64": os.environ["SHA_LINUX_AARCH64"],
|
|
"linux-x86_64": os.environ["SHA_LINUX_X86_64"],
|
|
}
|
|
|
|
with open(formula_path) as f:
|
|
content = f.read()
|
|
|
|
content = re.sub(r'version "[^"]*"', f'version "{version}"', content)
|
|
content = re.sub(
|
|
r"releases/download/v[\d.]+/numa-",
|
|
f"releases/download/v{version}/numa-",
|
|
content,
|
|
)
|
|
content = re.sub(r'\n[ \t]*sha256 "[^"]*"', "", content)
|
|
|
|
|
|
def add_sha(match: re.Match) -> str:
|
|
indent = match.group(1)
|
|
target = match.group(2)
|
|
if target not in shas:
|
|
return match.group(0)
|
|
return f'{match.group(0)}\n{indent}sha256 "{shas[target]}"'
|
|
|
|
|
|
content = re.sub(
|
|
r'^([ \t]+)url "[^"]*numa-([\w-]+)\.tar\.gz"',
|
|
add_sha,
|
|
content,
|
|
flags=re.MULTILINE,
|
|
)
|
|
|
|
with open(formula_path, "w") as f:
|
|
f.write(content)
|