Skip to content

Commit

Permalink
semantic version (#991)
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentsimon committed Sep 10, 2021
1 parent af24ed4 commit d6174db
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var versionCmd = &cobra.Command{
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
// not using logger, since it prints timing info, etc
fmt.Printf("GitVersion:\t%s\n", pkg.GetVersion())
fmt.Printf("GitVersion:\t%s\n", pkg.GetTagVersion())
fmt.Printf("GitCommit:\t%s\n", pkg.GetCommit())
fmt.Printf("GitTreeState:\t%s\n", pkg.GetTreeState())
fmt.Printf("BuildDate:\t%s\n", pkg.GetBuildDate())
Expand Down
1 change: 0 additions & 1 deletion pkg/sarif.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ type physicalLocation struct {
ArtifactLocation artifactLocation `json:"artifactLocation"`
}

//TODO: remove linter and update unit tests.
//nolint:govet
type location struct {
PhysicalLocation physicalLocation `json:"physicalLocation"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/scorecard.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func RunScorecards(ctx context.Context,
CommitSHA: commitSHA,
},
Scorecard: ScorecardInfo{
Version: GetVersion(),
Version: GetSemanticVersion(),
CommitSHA: GetCommit(),
},
Date: time.Now(),
Expand Down
16 changes: 14 additions & 2 deletions pkg/scorecard_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package pkg

import (
"runtime"
"strings"
)

// Base version information.
Expand All @@ -34,11 +35,22 @@ var (
buildDate = "unknown"
)

// GetVersion returns the scorecard version.
func GetVersion() string {
// GetTagVersion returns the scorecard version
// fr the release GitHub tag, i.e. v.X.Y.Z.
func GetTagVersion() string {
return gitVersion
}

// GetSemanticVersion returns the semantic version,
// i.e., X.Y.Z.
func GetSemanticVersion() string {
tv := GetTagVersion()
if strings.HasPrefix(tv, "v") {
return tv[1:]
}
return tv
}

// GetCommit returns the GitHub's commit hash that scorecard was built from.
func GetCommit() string {
return gitCommit
Expand Down

0 comments on commit d6174db

Please sign in to comment.