Restore Homebrew publication after stable GitHub releases
The v1.0.2 build published a valid macOS archive, but its release workflow lacked the Homebrew job that published v1.0.0. Restore the job, updater, tests and setup notes from a707076 alongside the existing Arch and OpenArtifact jobs. Verify the Apple Silicon archive against the published GitHub digest before updating the CLI formula and GUI cask in one tap commit. Skip prereleases and older versions, and retry from the current tap head after a concurrent push. Use the existing HOMEBREW_TAP_TOKEN with the same tap and branch. On macOS, all three updater tests passed. Exercised the workflow shell with the real v1.0.2 archive, mocked release transport and a local Git remote, including checksum rejection, concurrent updates and retries. Actionlint and ShellCheck passed with the old actionlint runner list exception for ubuntu-26.04. Workspace formatting and strict Clippy passed. All 568 default tests passed with three ignored after enabling loopback for the test run. No live workflow was triggered.
This commit is contained in:
1 parent
ee77ddb9ac
commit
21b8381fa3
4 files changed
+199
No files matched your search
@@ -0,0 +1,42 @@
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from update_homebrew import update_tap
|
||||
|
||||
|
||||
class UpdateTapTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
directory = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(directory.cleanup)
|
||||
self.tap = Path(directory.name)
|
||||
self.formula = self.tap / "Formula/tsunagi.rb"
|
||||
self.cask = self.tap / "Casks/tsunagi-gui.rb"
|
||||
self.formula.parent.mkdir()
|
||||
self.cask.parent.mkdir()
|
||||
self.old_hash = "a" * 64
|
||||
self.new_hash = "b" * 64
|
||||
self.formula.write_text(f' VERSION = "1.9.0"\n SHA256 = "{self.old_hash}"\n')
|
||||
self.cask.write_text(f' version "1.9.0"\n sha256 "{self.old_hash}"\n')
|
||||
|
||||
def test_updates_both_packages_and_allows_retry(self):
|
||||
for _ in range(2):
|
||||
update_tap(self.tap, "v1.10.0", self.new_hash)
|
||||
self.assertEqual(self.formula.read_text(), f' VERSION = "1.10.0"\n SHA256 = "{self.new_hash}"\n')
|
||||
self.assertEqual(self.cask.read_text(), f' version "1.10.0"\n sha256 "{self.new_hash}"\n')
|
||||
|
||||
def test_older_release_does_not_replace_either_package(self):
|
||||
before = self.formula.read_bytes(), self.cask.read_bytes()
|
||||
update_tap(self.tap, "v1.8.9", self.new_hash)
|
||||
self.assertEqual((self.formula.read_bytes(), self.cask.read_bytes()), before)
|
||||
|
||||
def test_invalid_release_or_cask_leaves_formula_untouched(self):
|
||||
before = self.formula.read_bytes()
|
||||
with self.assertRaises(ValueError):
|
||||
update_tap(self.tap, "v1.10.0-rc.1", self.new_hash)
|
||||
with self.assertRaises(ValueError):
|
||||
update_tap(self.tap, "v1.10.0", "invalid")
|
||||
self.cask.write_text(' version "1.9.0"\n')
|
||||
with self.assertRaises(ValueError):
|
||||
update_tap(self.tap, "v1.10.0", self.new_hash)
|
||||
self.assertEqual(self.formula.read_bytes(), before)
|
||||
@@ -0,0 +1,51 @@
|
||||
"""Update the tap's formula and cask for a verified macOS release archive."""
|
||||
|
||||
import argparse
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
VERSION = r"(?:0|[1-9][0-9]*)(?:\.(?:0|[1-9][0-9]*)){2}"
|
||||
SHA256 = r"[0-9a-f]{64}"
|
||||
|
||||
|
||||
def update_tap(tap: Path, tag: str, checksum: str) -> None:
|
||||
if not re.fullmatch(f"v{VERSION}", tag):
|
||||
raise ValueError("expected a stable vMAJOR.MINOR.PATCH release")
|
||||
if not re.fullmatch(SHA256, checksum):
|
||||
raise ValueError("expected a SHA-256 digest")
|
||||
|
||||
version = tag[1:]
|
||||
updates = {}
|
||||
for filename, version_field, hash_field in (
|
||||
("Formula/tsunagi.rb", "VERSION = ", "SHA256 = "),
|
||||
("Casks/tsunagi-gui.rb", "version ", "sha256 "),
|
||||
):
|
||||
path = tap / filename
|
||||
original = path.read_text()
|
||||
version_pattern = rf'^( {version_field}")({VERSION})(")$'
|
||||
hash_pattern = rf'^( {hash_field}")({SHA256})(")$'
|
||||
current = re.findall(version_pattern, original, re.MULTILINE)
|
||||
if len(current) != 1 or len(re.findall(hash_pattern, original, re.MULTILINE)) != 1:
|
||||
raise ValueError(f"expected one version and one SHA-256 in {filename}")
|
||||
if tuple(map(int, version.split("."))) < tuple(map(int, current[0][1].split("."))):
|
||||
print(f"Skipping older release {tag}: {filename} already has {current[0][1]}")
|
||||
return
|
||||
updated = re.sub(version_pattern, rf"\g<1>{version}\g<3>", original, flags=re.MULTILINE)
|
||||
updated = re.sub(hash_pattern, rf"\g<1>{checksum}\g<3>", updated, flags=re.MULTILINE)
|
||||
updates[path] = (original, updated)
|
||||
|
||||
for path, (original, updated) in updates.items():
|
||||
if updated != original:
|
||||
path.write_text(updated)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("tap", type=Path)
|
||||
parser.add_argument("tag")
|
||||
parser.add_argument("checksum")
|
||||
args = parser.parse_args()
|
||||
try:
|
||||
update_tap(args.tap, args.tag, args.checksum)
|
||||
except (OSError, ValueError) as error:
|
||||
parser.exit(1, f"{error}\n")
|
||||
Reference in new issue
Block a user