diff --git a/publisher/pkg/impl/funcs_tiup.go b/publisher/pkg/impl/funcs_tiup.go index b8ba897..d42ca13 100644 --- a/publisher/pkg/impl/funcs_tiup.go +++ b/publisher/pkg/impl/funcs_tiup.go @@ -15,7 +15,7 @@ const nightlyVerSuffix = "-nightly" var ( pkgNameRegex = regexp.MustCompile(`^(.+)-v\d+\.\d+\.\d+`) pkgVersionNightlyRegex = regexp.MustCompile(`(-\d+-g[0-9a-f]{7,})$`) - ociGATagRegex = regexp.MustCompile(`^(v\d+\.\d+\.\d+)(-\w+-)?_(linux|darwin)_(amd64|arm64)$`) + ociGATagRegex = regexp.MustCompile(`^(v\d+\.\d+\.\d+)(-\w+)?_(linux|darwin)_(amd64|arm64)$`) ociNightlyTagRegex = regexp.MustCompile(`^(master|main)_(linux|darwin)_(amd64|arm64)$`) tiupVersionRegex = regexp.MustCompile(`^v\d+\.\d+\.\d+.*(-nightly)$`) ) @@ -162,7 +162,7 @@ func transformTiupVer(version, tag string) string { case ociGATagRegex.MatchString(tag): // GA case // ociGATagRegex = regexp.MustCompile(`^(v\d+\.\d+\.\d+)(-\w+)?_(linux|darwin)_(amd64|arm64)$`) matches := ociGATagRegex.FindStringSubmatch(tag) - return strings.Join(matches[1:2], "") + return strings.Join(matches[1:3], "") case ociNightlyTagRegex.MatchString(tag): // Nightly case // we replace the suffix part of version: '-[0-9]+-g[0-9a-f]+$' to "-nightly" return pkgVersionNightlyRegex.ReplaceAllString(version, "") + nightlyVerSuffix diff --git a/publisher/pkg/impl/funcs_tiup_test.go b/publisher/pkg/impl/funcs_tiup_test.go new file mode 100644 index 0000000..4297239 --- /dev/null +++ b/publisher/pkg/impl/funcs_tiup_test.go @@ -0,0 +1,31 @@ +package impl + +import "testing" + +func Test_transformTiupVer(t *testing.T) { + type args struct { + version string + tag string + } + tests := []struct { + name string + args args + want string + }{ + { + name: "test1", + args: args{ + version: "v8.5.0-pre", + tag: "v8.5.0-centos7_linux_amd64", + }, + want: "v8.5.0-centos7", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := transformTiupVer(tt.args.version, tt.args.tag); got != tt.want { + t.Errorf("transformTiupVer() = %v, want %v", got, tt.want) + } + }) + } +}