ci: auto-bump homebrew formula on release #39
76
.github/workflows/homebrew-bump.yml
vendored
Normal file
76
.github/workflows/homebrew-bump.yml
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
name: Bump Homebrew Tap
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
version:
|
||||
description: 'Version to bump (e.g. 0.10.0 or v0.10.0)'
|
||||
required: true
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
bump:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Determine version
|
||||
id: ver
|
||||
run: |
|
||||
if [ "${{ github.event_name }}" = "release" ]; then
|
||||
V="${{ github.event.release.tag_name }}"
|
||||
else
|
||||
V="${{ github.event.inputs.version }}"
|
||||
fi
|
||||
V="${V#v}"
|
||||
echo "version=$V" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Fetch sha256 checksums from release assets
|
||||
id: shas
|
||||
env:
|
||||
V: ${{ steps.ver.outputs.version }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
base="https://github.com/razvandimescu/numa/releases/download/v${V}"
|
||||
for t in macos-aarch64 macos-x86_64 linux-aarch64 linux-x86_64; do
|
||||
sha=$(curl -fsSL "${base}/numa-${t}.tar.gz.sha256" | awk '{print $1}')
|
||||
if [ -z "$sha" ]; then
|
||||
echo "ERROR: failed to fetch sha256 for $t" >&2
|
||||
exit 1
|
||||
fi
|
||||
key=$(echo "$t" | tr '[:lower:]-' '[:upper:]_')
|
||||
echo "SHA_${key}=${sha}" >> "$GITHUB_ENV"
|
||||
done
|
||||
|
||||
- name: Clone homebrew-tap
|
||||
env:
|
||||
HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }}
|
||||
run: |
|
||||
git clone "https://x-access-token:${HOMEBREW_TAP_GITHUB_TOKEN}@github.com/razvandimescu/homebrew-tap.git" tap
|
||||
|
||||
- name: Update formula
|
||||
env:
|
||||
VERSION: ${{ steps.ver.outputs.version }}
|
||||
run: |
|
||||
python3 scripts/update-homebrew-formula.py tap/numa.rb
|
||||
echo "--- updated numa.rb ---"
|
||||
cat tap/numa.rb
|
||||
|
||||
- name: Commit and push
|
||||
working-directory: tap
|
||||
env:
|
||||
V: ${{ steps.ver.outputs.version }}
|
||||
run: |
|
||||
if git diff --quiet; then
|
||||
echo "numa.rb already at v${V}, nothing to commit"
|
||||
exit 0
|
||||
fi
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
||||
git add numa.rb
|
||||
git commit -m "chore: bump numa to v${V}"
|
||||
git push origin main
|
||||
57
scripts/update-homebrew-formula.py
Executable file
57
scripts/update-homebrew-formula.py
Executable file
@@ -0,0 +1,57 @@
|
||||
#!/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)
|
||||
Reference in New Issue
Block a user