Skip to content

Commit

Permalink
fix: use strict semver version for autogenerated tags (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
xoxys authored Nov 21, 2023
1 parent 08e3dd3 commit e2766f9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 39 deletions.
42 changes: 5 additions & 37 deletions plugin/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,6 @@ func DefaultTagSuffix(ref, suffix string) ([]string, error) {
return tags, nil
}

func splitOff(input, delim string) string {
const splits = 2
parts := strings.SplitN(input, delim, splits)

if len(parts) == splits {
return parts[0]
}

return input
}

// DefaultTags returns a set of default suggested tags based on
// the commit ref.
func DefaultTags(ref string) ([]string, error) {
Expand All @@ -61,38 +50,17 @@ func DefaultTags(ref string) ([]string, error) {
}, nil
}

rawVersion = stripTagPrefix(ref)
rawVersion = splitOff(splitOff(rawVersion, "+"), "-")
//nolint:gomnd
dotParts := strings.SplitN(rawVersion, ".", 3)

if version.Major == 0 {
return []string{
fmt.Sprintf("%0*d.%0*d", len(dotParts[0]), version.Major, len(dotParts[1]), version.Minor),
fmt.Sprintf(
"%0*d.%0*d.%0*d",
len(dotParts[0]),
version.Major,
len(dotParts[1]),
version.Minor,
len(dotParts[2]),
version.Patch,
),
fmt.Sprintf("%v.%v", version.Major, version.Minor),
fmt.Sprintf("%v.%v.%v", version.Major, version.Minor, version.Patch),
}, nil
}

return []string{
fmt.Sprintf("%0*d", len(dotParts[0]), version.Major),
fmt.Sprintf("%0*d.%0*d", len(dotParts[0]), version.Major, len(dotParts[1]), version.Minor),
fmt.Sprintf(
"%0*d.%0*d.%0*d",
len(dotParts[0]),
version.Major,
len(dotParts[1]),
version.Minor,
len(dotParts[2]),
version.Patch,
),
fmt.Sprintf("%v", version.Major),
fmt.Sprintf("%v.%v", version.Major, version.Minor),
fmt.Sprintf("%v.%v.%v", version.Major, version.Minor, version.Patch),
}, nil
}

Expand Down
5 changes: 3 additions & 2 deletions plugin/tags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func TestDefaultTags(t *testing.T) {
{"refs/tags/v1.0.0+1", []string{"1", "1.0", "1.0.0"}},
{"refs/tags/v1.0.0-alpha.1", []string{"1.0.0-alpha.1"}},
{"refs/tags/v1.0.0-alpha", []string{"1.0.0-alpha"}},
{"refs/tags/1.01.0", []string{"1", "1.1", "1.1.0"}},
}

for _, test := range tests {
Expand Down Expand Up @@ -117,8 +118,8 @@ func TestDefaultTagSuffix(t *testing.T) {
Suffix: "nanoserver",
After: []string{
"18-nanoserver",
"18.06-nanoserver",
"18.06.0-nanoserver",
"18.6-nanoserver",
"18.6.0-nanoserver",
},
},
}
Expand Down

0 comments on commit e2766f9

Please sign in to comment.