forked from antrea-io/antrea
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support versioning of OKN Go binaries
This is inspired by how [Helm](https://github.com/helm/helm) does versioning. * The version string can bet set through an environment variable when running make or defaults to the contents of the VERSION file, which can be updated with each release. * Version information is "passed-on" to the Go binaries at build-time using Go LDFLAGS. * All 3 OKN Go binaries can now display version information by using --version.
- Loading branch information
1 parent
db442a0
commit 6c3da59
Showing
9 changed files
with
127 additions
and
7 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
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 @@ | ||
v0.0.1 |
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 |
---|---|---|
@@ -1,18 +1,21 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"okn/pkg/cni" | ||
"okn/pkg/version" | ||
|
||
"github.com/containernetworking/cni/pkg/skel" | ||
"github.com/containernetworking/cni/pkg/version" | ||
cni_version "github.com/containernetworking/cni/pkg/version" | ||
) | ||
|
||
func main() { | ||
skel.PluginMain( | ||
cni.ActionAdd.Request, | ||
cni.ActionCheck.Request, | ||
cni.ActionDel.Request, | ||
version.PluginSupports("0.1.0", "0.2.0", "0.3.0", "0.3.1"), | ||
"OKN CNI", | ||
cni_version.PluginSupports("0.1.0", "0.2.0", "0.3.0", "0.3.1"), | ||
fmt.Sprintf("OKN CNI %s", version.GetFullVersionWithRuntimeInfo()), | ||
) | ||
} |
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,58 @@ | ||
// Package version provides information about the current semantic version for | ||
// the OKN project. | ||
|
||
package version | ||
|
||
import ( | ||
"fmt" | ||
"runtime" | ||
) | ||
|
||
// These variables are set at build-time. | ||
var ( | ||
// Must follow the rules in https://semver.org/ | ||
// Does not include git / build information | ||
Version = "" | ||
// Empty if git not available | ||
GitSHA = "" | ||
// Can be "dirty", "clean" or empty (if git not available) | ||
GitTreeState = "" | ||
// Can be "unreleased" or "released"; if it is "unreleased" then we add build information to | ||
// the version in GetFullVersion | ||
ReleaseStatus = "unreleased" | ||
) | ||
|
||
func GetVersion() string { | ||
return Version | ||
} | ||
|
||
func GetGitSHA() string { | ||
return GitSHA | ||
} | ||
|
||
// GetFullVersion returns the version string to be displayed by OKN binaries. It will look like | ||
// "<major>.<minor>.<patch>" for released versions and "<major>.<minor>.<patch>-<SHA>[.dirty]" for | ||
// unreleased versions. | ||
func GetFullVersion() string { | ||
if Version == "" { | ||
return "UKNOWN" | ||
} | ||
if ReleaseStatus == "released" { | ||
return Version | ||
} | ||
// add build information | ||
if GitSHA == "" { | ||
return fmt.Sprintf("%s-unknown", Version) | ||
} | ||
if GitTreeState == "dirty" { | ||
return fmt.Sprintf("%s-%s.dirty", Version, GitSHA) | ||
} | ||
return fmt.Sprintf("%s-%s", Version, GitSHA) | ||
} | ||
|
||
// GetFullVersionWithRuntimeInfo returns the same version string as GetFullVersion but appends | ||
// "<GOOS>/<GOARCH>", where GOOS is the running program's operating system target (e.g. darwin, | ||
// linux) and GOARCH is the the running program's architecture target (e.g. amd64). | ||
func GetFullVersionWithRuntimeInfo() string { | ||
return fmt.Sprintf("%s %s/%s", GetFullVersion(), runtime.GOOS, runtime.GOARCH) | ||
} |
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,48 @@ | ||
# check if git is available | ||
ifeq ($(shell which git),) | ||
$(warning git is not available, binaries will not include git SHA) | ||
GIT_SHA := | ||
GIT_TREE_STATE := | ||
GIT_TAG := | ||
VERSION_SUFFIX := unknown | ||
else | ||
GIT_SHA := $(shell git rev-parse --short HEAD) | ||
# Tree state is "dirty" if there are uncommitted changes, untracked files are ignored | ||
GIT_TREE_STATE := $(shell test -n "`git status --porcelain --untracked-files=no`" && echo "dirty" || echo "clean") | ||
# Empty string if we are not building a tag | ||
GIT_TAG := $(shell git describe --tags --abbrev=0 --exact-match 2>/dev/null) | ||
ifeq ($(GIT_TREE_STATE),dirty) | ||
VERSION_SUFFIX := $(GIT_SHA).dirty | ||
else | ||
VERSION_SUFFIX := $(GIT_SHA) | ||
endif | ||
endif | ||
|
||
# if building a tag or VERSION is set, set RELEASE_STATUS to "released" | ||
ifdef VERSION | ||
RELEASE_STATUS := released | ||
else ifneq ($(GIT_TAG),) | ||
RELEASE_STATUS := released | ||
else | ||
RELEASE_STATUS := unreleased | ||
endif | ||
|
||
ifndef VERSION | ||
VERSION := $(shell head -n 1 VERSION) | ||
DOCKER_IMG_VERSION := $(VERSION)-$(VERSION_SUFFIX) | ||
else | ||
DOCKER__IMG_VERSION := $(VERSION) | ||
endif | ||
|
||
VERSION_LDFLAGS = -X okn/pkg/version.Version=$(VERSION) | ||
VERSION_LDFLAGS += -X okn/pkg/version.GitSHA=$(GIT_SHA) | ||
VERSION_LDFLAGS += -X okn/pkg/version.GitTreeState=$(GIT_TREE_STATE) | ||
VERSION_LDFLAGS += -X okn/pkg/version.ReleaseStatus=$(RELEASE_STATUS) | ||
|
||
version-info: | ||
@echo "===> Version information <===" | ||
@echo "VERSION: $(VERSION)" | ||
@echo "GIT_SHA: $(GIT_SHA)" | ||
@echo "GIT_TREE_STATE: $(GIT_TREE_STATE)" | ||
@echo "RELEASE_STATUS: $(RELEASE_STATUS)" | ||
@echo "DOCKER_IMG_VERSION: $(DOCKER_IMG_VERSION)" |