Make tag prefix configurable by --tag-prefix option#48
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a configurable --tag-prefix option so maltmill can safely operate in repos with multiple release/tag streams (e.g., monorepos managed by release-please), selecting releases only from the intended prefix.
Changes:
- Introduces
--tag-prefixfor bothmaltmill(update) andmaltmill new, and wires it through command runners. - Replaces repository-wide “latest release” selection with prefix-aware release discovery.
- Adds/updates tests for tag parsing, prefix-aware selection, and CLI argument parsing; updates README example.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
formula.go |
Adds tag parsing + prefix-aware latest release selection and uses it during formula updates. |
cmd_maltmill.go |
Plumbs CLI-provided tag prefix into formula update execution. |
cmd_new.go |
Uses prefix-aware release selection when no explicit tag is provided. |
cli.go |
Adds --tag-prefix flag (default "v") and forwards it to subcommand parsing. |
formula_test.go |
Adds unit tests for parsing tag names and selecting latest release by prefix. |
cli_test.go |
Adds tests verifying -tag-prefix is parsed for both update and new. |
README.md |
Updates usage example to show --tag-prefix. |
Comments suppressed due to low confidence (1)
formula.go:110
fromTag := fo.tagPrefix + fo.versionassumes the repository’s release tags are always exactly<prefix><version>. With the new defaulttag-prefixof "v", repositories that tag releases as plain semver (e.g.1.2.3) will now fail both release selection andGetReleaseByTag(it will look forv1.2.3). Consider preserving previous behavior by either (a) defaultingtag-prefixto an empty string, or (b) auto-detecting/falling back to an empty prefix when no matching releases are found for the configured prefix.
return false, nil
}
fromTag := fo.tagPrefix + fo.version
fromRele, resp, err := ghcli.Repositories.GetReleaseByTag(ctx, fo.owner, fo.repo, fromTag)
if err != nil {
return false, errors.Wrapf(err, "update formula failed: %s", fo.fname)
}
resp.Body.Close()
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| func findLatestReleaseByPrefix(ctx context.Context, ghcli *github.Client, owner, repo, prefix string) (*github.RepositoryRelease, *semver.Version, error) { | ||
| var ( | ||
| latest *github.RepositoryRelease | ||
| latestVer *semver.Version | ||
| opt = &github.ListOptions{PerPage: 100} | ||
| ) | ||
|
|
||
| for { | ||
| releases, resp, err := ghcli.Repositories.ListReleases(ctx, owner, repo, opt) | ||
| if resp != nil { | ||
| resp.Body.Close() | ||
| } | ||
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
| cand, candVer := selectLatestReleaseByPrefix(releases, prefix) | ||
| if cand != nil && (latest == nil || latestVer.LessThan(candVer)) { | ||
| latest = cand | ||
| latestVer = candVer | ||
| } | ||
| if resp == nil || resp.NextPage == 0 { | ||
| break | ||
| } | ||
| opt.Page = resp.NextPage | ||
| } |
There was a problem hiding this comment.
findLatestReleaseByPrefix paginates through all releases and performs semver comparisons, which can substantially increase GitHub API calls vs the previous GetLatestRelease (and may hit rate limits on repos with many releases). If the intended meaning of “latest” is GitHub’s ordering (newest published release), you can stop once you find the first matching non-draft/non-prerelease release while iterating pages (often within the first page). If semver-max is required, it would be good to document the extra API usage and consider adding a reasonable page limit or other mitigation.
There was a problem hiding this comment.
I think this is OK.
In most case, the target repository is under the control for who runs the maltmill. They should be able to use proper prefix that does not trigger paging so much.
|
That's good. It could also support tags like lib/bar/v1.2.3, which are commonly used in Go and Terraform. |
Thank you for sharing a great product with OSS community! 🤝
Here I want to ask for adding an optional commandline option to make maltmill working with release-please.
Description
This PR makes tag-prefix handling configurable via the
--tag-prefixoption.--tag-prefixto bothmaltmill(update) andmaltmill new.--tag-prefix.--tag-prefix inspequte-voption.Why
I use
release-pleaseto handle automatic release from monorepo projects and such projects contain multiple release streams (different products/components) under different tag prefixes.In case of inspequte, it has
inspequte-vX.Y.Zstream andgradle-plugin-vX.Y.Zstream.Without explicit prefix filtering, maltmill can pick an unrelated release/tag and update formulae incorrectly.
Making the prefix configurable ensures the intended product stream is selected.
Compatibility
--tag-prefixis optional.v, so commonvX.Y.Zrepositories continue to work without changes.--tag-prefix <prefix>to avoid cross-stream release selection.