Skip to content

Commit

Permalink
fix(packaging) fix version number for fips build
Browse files Browse the repository at this point in the history
Keep the '-fips' postfix if present
  • Loading branch information
fguimond committed Nov 25, 2024
1 parent 0036d0f commit 4d92db6
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 8 deletions.
15 changes: 11 additions & 4 deletions pkg/extension/sumologicextension/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -1064,12 +1064,19 @@ func getHostname(logger *zap.Logger) (string, error) {
// cleaned up. All other version formats will remain the same.
// Cleaned up format: 0.108.0-sumo-2-4d57200692d5c5c39effad4ae3b29fef79209113
func cleanupBuildVersion(version string) string {
pattern := "(^[0-9]+\\.[0-9]+\\.[0-9]+-sumo-[0-9]+)-[0-9a-f]{40}$"
pattern := "^v?([0-9]+\\.[0-9]+\\.[0-9]+-sumo-[0-9]+)(-[0-9a-f]{40}){0,1}(-fips){0,1}$"
re := regexp.MustCompile(pattern)

sm := re.FindAllStringSubmatch(version, 1)
if len(sm) == 1 {
ver := sm[0][1]
matches := re.FindAllStringSubmatch(version, 1)
if len(matches) != 1 {
return version
}
subMatches := matches[0]
if len(subMatches) > 1 {
ver := subMatches[1]
if len(subMatches) == 4 {
ver += subMatches[3]
}
return "v" + ver
}

Expand Down
44 changes: 40 additions & 4 deletions pkg/extension/sumologicextension/extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1604,17 +1604,53 @@ func Test_cleanupBuildVersion(t *testing.T) {
want string
}{
{
name: "already ok",
args: args{version: "0.108.0-sumo-2"},
want: "v0.108.0-sumo-2",
}, {
name: "no hash fips",
args: args{version: "0.108.0-sumo-2-fips"},
want: "v0.108.0-sumo-2-fips",
}, {
name: "with hash",
args: args{version: "0.108.0-sumo-2-4d57200692d5c5c39effad4ae3b29fef79209113"},
want: "v0.108.0-sumo-2",
}, {
name: "already ok",
name: "hash fips",
args: args{version: "0.108.0-sumo-2-4d57200692d5c5c39effad4ae3b29fef79209113-fips"},
want: "v0.108.0-sumo-2-fips",
}, {
name: "v already ok",
args: args{version: "v0.108.0-sumo-2"},
want: "v0.108.0-sumo-2",
}, {
name: "non v",
args: args{version: "0.108.0-sumo-2"},
want: "0.108.0-sumo-2",
name: "v no hash fips",
args: args{version: "v0.108.0-sumo-2-fips"},
want: "v0.108.0-sumo-2-fips",
}, {
name: "v with hash",
args: args{version: "v0.108.0-sumo-2-4d57200692d5c5c39effad4ae3b29fef79209113"},
want: "v0.108.0-sumo-2",
}, {
name: "v hash fips",
args: args{version: "v0.108.0-sumo-2-4d57200692d5c5c39effad4ae3b29fef79209113-fips"},
want: "v0.108.0-sumo-2-fips",
}, {
name: "no patch version",
args: args{version: "0.108-sumo-2"},
want: "0.108-sumo-2",
}, {
name: "v no patch version",
args: args{version: "v0.108-sumo-2"},
want: "v0.108-sumo-2",
}, {
name: "no sumo version",
args: args{version: "0.108-0-sumo"},
want: "0.108-0-sumo",
}, {
name: "v no patch version",
args: args{version: "v0.108-0-sumo"},
want: "v0.108-0-sumo",
}, {
name: "nonsense",
args: args{version: "hfiwe-23rhc8eg.fhf"},
Expand Down

0 comments on commit 4d92db6

Please sign in to comment.