feat(version): support 18.06.0 tag format.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
parent
fb3410585f
commit
9c54d0dd13
1
go.sum
1
go.sum
@ -1,5 +1,6 @@
|
||||
github.com/aws/aws-sdk-go v1.16.15 h1:kQyxfRyjAwIYjf0225sn/pn+WAlncKyI8dmT3+ItMFE=
|
||||
github.com/aws/aws-sdk-go v1.16.15/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
|
||||
github.com/bradrydzewski/cli v0.0.0-20190108225652-0d51abd87c77 h1:bXc5tB7PFVzIHUfTECDt0Orw6mIAzHePWBmemvtnfiU=
|
||||
github.com/bradrydzewski/cli v0.0.0-20190108225652-0d51abd87c77/go.mod h1:4SmsVk3pOgYeJlG54e23Ztd/HucXeH5RmH5bNO+uOpk=
|
||||
github.com/coreos/go-semver v0.2.0 h1:3Jm3tLmsgAYcjC+4Up7hJrFBPr+n7rAqYeSw/SZazuY=
|
||||
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
|
||||
|
25
tags.go
25
tags.go
@ -24,6 +24,16 @@ func DefaultTagSuffix(ref, suffix string) []string {
|
||||
return tags
|
||||
}
|
||||
|
||||
func splitOff(input string, delim string) string {
|
||||
parts := strings.SplitN(input, delim, 2)
|
||||
|
||||
if len(parts) == 2 {
|
||||
return parts[0]
|
||||
}
|
||||
|
||||
return input
|
||||
}
|
||||
|
||||
// DefaultTags returns a set of default suggested tags based on
|
||||
// the commit ref.
|
||||
func DefaultTags(ref string) []string {
|
||||
@ -40,16 +50,21 @@ func DefaultTags(ref string) []string {
|
||||
version.String(),
|
||||
}
|
||||
}
|
||||
|
||||
v = stripTagPrefix(ref)
|
||||
v = splitOff(splitOff(v, "+"), "-")
|
||||
dotParts := strings.SplitN(v, ".", 3)
|
||||
|
||||
if version.Major == 0 {
|
||||
return []string{
|
||||
fmt.Sprintf("%d.%d", version.Major, version.Minor),
|
||||
fmt.Sprintf("%d.%d.%d", version.Major, version.Minor, version.Patch),
|
||||
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),
|
||||
}
|
||||
}
|
||||
return []string{
|
||||
fmt.Sprint(version.Major),
|
||||
fmt.Sprintf("%d.%d", version.Major, version.Minor),
|
||||
fmt.Sprintf("%d.%d.%d", version.Major, version.Minor, version.Patch),
|
||||
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),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,6 +93,15 @@ func TestDefaultTagSuffix(t *testing.T) {
|
||||
"1.9.2-nanoserver",
|
||||
},
|
||||
},
|
||||
{
|
||||
Before: "refs/tags/v18.06.0",
|
||||
Suffix: "nanoserver",
|
||||
After: []string{
|
||||
"18-nanoserver",
|
||||
"18.06-nanoserver",
|
||||
"18.06.0-nanoserver",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
Loading…
Reference in New Issue
Block a user