-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from cfergeau/version
Generate vfkit version from git tag
- Loading branch information
Showing
5 changed files
with
54 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/pkg/cmdline/version.go export-subst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package cmdline | ||
|
||
import ( | ||
"runtime/debug" | ||
"strings" | ||
) | ||
|
||
var ( | ||
// set using the '-X github.com/crc-org/vfkit/pkg/cmdline.gitVersion' linker flag | ||
gitVersion = "unknown" | ||
|
||
// set through .gitattributes when `git archive` is used | ||
// see https://icinga.com/blog/2022/05/25/embedding-git-commit-information-in-go-binaries/ | ||
gitArchiveVersion = "$Format:%(describe)$" | ||
) | ||
|
||
func Version() string { | ||
switch { | ||
// This will be substituted when building from a GitHub tarball | ||
case !strings.HasPrefix(gitArchiveVersion, "$Format:"): | ||
return gitArchiveVersion | ||
// This will be set when building from git using make | ||
case gitVersion != "": | ||
return gitVersion | ||
// moduleVersionFromBuildInfo() will be set when using `go install` | ||
default: | ||
return moduleVersionFromBuildInfo() | ||
} | ||
} | ||
|
||
func moduleVersionFromBuildInfo() string { | ||
info, ok := debug.ReadBuildInfo() | ||
if !ok { | ||
return "" | ||
} | ||
if info.Main.Version == "(devel)" { | ||
return "" | ||
} | ||
return info.Main.Version | ||
} |