Skip to content

fix(homebrew): take the formula version from the bottle filename - #100

Merged
bketelsen merged 2 commits into
mainfrom
fix/homebrew-bottle-version
Nov 13, 2026
Merged

bketelsen merged 2 commits into
mainfrom
fix/homebrew-bottle-version

Conversation

@frostyard-machines

@frostyard-machines frostyard-machines commented Nov 13, 2026 •

Copy link
Copy Markdown

Summary

Every generated Homebrew formula said version "1.0.0". The CLI builds a bottle models.Package with only Filename, Size and SHA256Sum, and generateFormula fell back to the hard-coded 1.0.0 when Version was empty. The bottle filename name--version.platform.bottle.tar.gz encodes the version (docs/specs/generators.md, Homebrew section), so the generator now reads it from there.

Closes #95

What changes (all in internal/generator/homebrew/)

  • New parseBottleFilename: name = text before the first --; platform = text after the last .; version = text between them. Suffix .bottle.tar.gz or .bottle.tar is required. Name, version and platform must be non-empty.
  • generateFormula takes the version from the bottle filenames. The 1.0.0 default is gone. The filename is the source of truth: pkg.Version is not used for the formula version, because in incremental mode it comes from old formula files, which can hold the wrong 1.0.0.
  • Generate groups bottles by the parsed name. extractPackageNameFromURL reuses the parser (old fallback kept for odd input); the unused extractPackageName is removed.

Behavior for a filename that does not parse

The run fails with an error; nothing is skipped and nothing is defaulted. ValidatePackages returns the error, and it runs in phase 1 of generate, before any format writes output. Generate also returns the error (defense in depth).

Behavior change: mixed versions in one formula

A formula holds 1 version. When the bottles of 1 name have different versions, ValidatePackages now fails (bottles for foo have different versions: 1.0.0, 2.0.0). Before, the formula took the first bottle's metadata version and the first bottle's URL per platform, so an incremental run that added a new version of an existing bottle silently kept the old URL. Upgrading a formula in incremental mode is out of scope here; this change makes the case fail loudly instead of writing a stale formula.

Not changed

  • internal/cli/generate.go (an L1 risk path) is not touched. Setting Name and Version there would switch on incremental conflict detection for bottles (identity name:version, no platform), which is a separate behavior change.

Checks

  • make check — exit 0 (lint 0 issues, docs integrity, unit tests)
  • make vuln, make test-race, make build-cross locally — green
  • make test-integration — needs Docker, not available on the dev host; the CI run covers it
  • Reproduction: repogen generate --input-dir test/fixtures/bottles --output-dir $TMP/out --base-url https://example.invalid now writes version "1.0.0" for repogen-test and version "2.0.0" for repogen-utils.

Guard

  • TestGenerateUsesBottleFilenameVersion builds a package like the CLI does (no Name, no Version) for repogen-utils--2.0.0.x86_64_linux.bottle.tar.gz and asserts version "2.0.0". A second case sets a stale Version: "1.0.0", as an old formula gives in incremental mode, and the filename must still win.
  • Revert test: in a scratch worktree at the PR head, generator.go restored from the base, go test ./internal/generator/homebrew/ -count=1 fails TestGenerateUsesBottleFilenameVersion (both subtests: the formula holds version "1.0.0"), TestValidatePackagesRejectsBadFilenames, TestValidatePackagesRejectsMixedVersions and TestGenerateRejectsBadFilenames.
  • Unit tests also cover parseBottleFilename (valid and invalid names), the error for unparsable filenames in ValidatePackages and Generate (no formula written), and the mixed-version error.
  • test/integration_test.go now requires version "1.0.0" / version "2.0.0" for the 2 fixtures, not only the word version.

Risk tier

  • Tier 2: Moderate

Rationale: Homebrew generator only; no path in .github/risk-paths.json is touched. Output changes only in the formula version line, and invalid input now fails instead of writing a wrong formula.

Verification

  • node scripts/check-docs.mjs green (inside make check)
  • Output-format changes: docs/specs/generators.md updated alongside the code

The CLI builds a bottle package with no name and no version, so every
generated formula fell back to version 1.0.0. The bottle filename
(name--version.platform.bottle.tar.gz) encodes the version; the
generator now reads it from there. A filename that does not parse, or
bottles of one formula with different versions, fail validation before
any output is written.

Closes #95
@github-actions github-actions Bot added the level:L3 Skim label Nov 13, 2026
@codecov

codecov Bot commented Nov 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/generator/homebrew/generator.go 85.71% 3 Missing and 3 partials ⚠️
internal/generator/homebrew/parser.go 85.71% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@frostyard-machines

Copy link
Copy Markdown
Author

Cross-review (read-only, independent model family)

  • Coder: deepseek/deepseek-flash. Reviewer: openai/gpt-6.1-sol.
  • Base 0f1f070d080b55df899bfd1d82e189e0993babce.
  • Initial review at 95a8eb64bf298b9e24e491d8cc6d6d0434203ea9: Ready, Blocking: none. 1 low, non-blocking finding: the guard test did not cover a stale non-empty metadata version. Fixed in 52b76e2 (table case with Version: "1.0.0").
  • Re-review 1 at 52b76e2a4a631af16204bb772a262cae19b548ee: Ready, Blocking: none, no findings.
  • Revert test at 52b76e2: with generator.go from the base, both TestGenerateUsesBottleFilenameVersion subtests fail on the version assertion.
  • CI at 52b76e2: make ci green; the integration suite ran TestIntegration/Homebrew with the tightened version checks and passed.

@frostyard-machines frostyard-machines added the ready-for-human Reviewed, CI green: ready for Brian to review and merge label Nov 13, 2026
@bketelsen
bketelsen added this pull request to the merge queue Nov 13, 2026
Merged via the queue into main with commit 05a5bcb Nov 13, 2026
5 checks passed
@frostyard-machines
frostyard-machines deleted the fix/homebrew-bottle-version branch November 13, 2026 01:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

level:L3 Skim ready-for-human Reviewed, CI green: ready for Brian to review and merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sweep: Homebrew formulas always get version 1.0.0, not the bottle's version

2 participants