ref(installerconf): make VersionPrefixes a list, not a single string

Tag conventions can change across versions of the same project
(e.g. "jq-1.7.1" → bare "1.8.0"). A comma-separated list lets
the config express all historical prefixes. The parser tries each
in order and strips the first match.

Back-compat: singular "version_prefix" still works (parsed as a
single-element list).
This commit is contained in:
AJ ONeal
2026-03-10 10:46:47 -06:00
parent 0f7e0f3286
commit 8b9d101132
7 changed files with 170244 additions and 10 deletions

BIN
classify Executable file

Binary file not shown.

170214
distributables.csv Normal file

File diff suppressed because it is too large Load Diff

BIN
e2etest Executable file

Binary file not shown.

BIN
inspect Executable file

Binary file not shown.

View File

@@ -14,7 +14,7 @@
// source = github
// owner = jqlang
// repo = jq
// version_prefix = jq-
// version_prefixes = jq-
//
// With filename exclusions (hugo publishes _extended_ variants):
//
@@ -73,9 +73,12 @@ type Conf struct {
// version string. Example: "tools/monorel/"
TagPrefix string
// VersionPrefix is stripped from version strings.
// Example: jq tags as "jq-1.7.1" → set to "jq-" to get "1.7.1".
VersionPrefix string
// VersionPrefixes are stripped from version/tag strings.
// Comma-separated. Each release tag is checked against these in order;
// the first match is stripped. Projects may change tag conventions across
// versions (e.g. "jq-1.7.1" in older releases, bare "1.8.0" later).
// Example: "jq-, cli-"
VersionPrefixes []string
// Exclude lists filename substrings to filter out.
// Assets whose name contains any of these are skipped.
@@ -116,7 +119,18 @@ func Read(path string) (*Conf, error) {
c.Owner = raw["owner"]
c.Repo = raw["repo"]
c.TagPrefix = raw["tag_prefix"]
c.VersionPrefix = raw["version_prefix"]
if v := raw["version_prefixes"]; v != "" {
for _, p := range strings.Split(v, ",") {
p = strings.TrimSpace(p)
if p != "" {
c.VersionPrefixes = append(c.VersionPrefixes, p)
}
}
} else if v := raw["version_prefix"]; v != "" {
// Back-compat with singular form.
c.VersionPrefixes = []string{v}
}
if v := raw["base_url"]; v != "" {
c.BaseURL = v
@@ -137,7 +151,7 @@ func Read(path string) (*Conf, error) {
known := map[string]bool{
"source": true, "owner": true, "repo": true,
"base_url": true, "url": true,
"tag_prefix": true, "version_prefix": true,
"tag_prefix": true, "version_prefix": true, "version_prefixes": true,
"exclude": true,
}
for k, v := range raw {

View File

@@ -18,21 +18,27 @@ repo = bat
assertEqual(t, "Owner", c.Owner, "sharkdp")
assertEqual(t, "Repo", c.Repo, "bat")
assertEqual(t, "TagPrefix", c.TagPrefix, "")
assertEqual(t, "VersionPrefix", c.VersionPrefix, "")
if len(c.VersionPrefixes) != 0 {
t.Errorf("VersionPrefixes = %v, want empty", c.VersionPrefixes)
}
if len(c.Exclude) != 0 {
t.Errorf("Exclude = %v, want empty", c.Exclude)
}
}
func TestVersionPrefix(t *testing.T) {
func TestVersionPrefixes(t *testing.T) {
c := confFromString(t, `
source = github
owner = jqlang
repo = jq
version_prefix = jq-
version_prefixes = jq-, cli-
`)
assertEqual(t, "VersionPrefix", c.VersionPrefix, "jq-")
if len(c.VersionPrefixes) != 2 {
t.Fatalf("VersionPrefixes has %d items, want 2: %v", len(c.VersionPrefixes), c.VersionPrefixes)
}
assertEqual(t, "VersionPrefixes[0]", c.VersionPrefixes[0], "jq-")
assertEqual(t, "VersionPrefixes[1]", c.VersionPrefixes[1], "cli-")
}
func TestExclude(t *testing.T) {

BIN
zigtest Executable file

Binary file not shown.