This repository has been archived by the owner on Sep 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add script to set workspace status implement version subcommand for capdctl add script to build binaries implement versioninfo as a package build capd-manager with version info build kind-test with version info update readme Signed-off-by: Ashish Amarnath <ashish.amarnath@gmail.com>
- Loading branch information
1 parent
0a75841
commit 55c2e59
Showing
7 changed files
with
196 additions
and
8 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
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,51 @@ | ||
/* | ||
Copyright 2019 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package versioninfo | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
var ( | ||
// GitBranch is the branch from which this binary was built | ||
GitBranch string | ||
// GitReleaseTag is the git tag from which this binary is released | ||
GitReleaseTag string | ||
// GitReleaseCommit is the commit corresponding to the GitReleaseTag | ||
GitReleaseCommit string | ||
// GitTreeState indicates if the git tree, from which this binary was built, was clean or dirty | ||
GitTreeState string | ||
// GitCommit is the git commit at which this binary binary was built | ||
GitCommit string | ||
// GitMajor is the major version of the release | ||
GitMajor string | ||
// GitMinor is the minor version of the release | ||
GitMinor string | ||
) | ||
|
||
// VersionInfo returns version information for the supplied binary | ||
func VersionInfo(binName string) string { | ||
var vi strings.Builder | ||
vi.WriteString(fmt.Sprintf("%s version info:\n", binName)) | ||
vi.WriteString(fmt.Sprintf("GitReleaseTag: %q, Major: %q, Minor: %q, GitRelaseCommit: %q\n", GitReleaseTag, GitMajor, GitMinor, GitReleaseCommit)) | ||
vi.WriteString(fmt.Sprintf("Git Branch: %q\n", GitBranch)) | ||
vi.WriteString(fmt.Sprintf("Git commit: %q\n", GitCommit)) | ||
vi.WriteString(fmt.Sprintf("Git tree state: %q\n", GitTreeState)) | ||
|
||
return vi.String() | ||
} |
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,80 @@ | ||
#!/bin/bash | ||
# Copyright 2019 The Kubernetes Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
GIT_COMMIT="$(git describe --always --dirty --abbrev=14)" | ||
|
||
if git_status=$(git status --porcelain 2>/dev/null) && [[ -z ${git_status} ]]; then | ||
GIT_TREE_STATE="clean" | ||
else | ||
GIT_TREE_STATE="dirty" | ||
fi | ||
|
||
# mostly stolen from k8s.io/hack/lib/version.sh | ||
# Use git describe to find the version based on tags. | ||
if GIT_VERSION=$(git describe --tags --abbrev=14 2>/dev/null); then | ||
# This translates the "git describe" to an actual semver.org | ||
# compatible semantic version that looks something like this: | ||
# v1.1.0-alpha.0.6+84c76d1142ea4d | ||
# | ||
# TODO: We continue calling this "git version" because so many | ||
# downstream consumers are expecting it there. | ||
DASHES_IN_VERSION=$(echo "${GIT_VERSION}" | sed "s/[^-]//g") | ||
if [[ "${DASHES_IN_VERSION}" == "---" ]] ; then | ||
# We have distance to subversion (v1.1.0-subversion-1-gCommitHash) | ||
GIT_VERSION=$(echo "${GIT_VERSION}" | sed "s/-\([0-9]\{1,\}\)-g\([0-9a-f]\{14\}\)$/.\1\-\2/") | ||
elif [[ "${DASHES_IN_VERSION}" == "--" ]] ; then | ||
# We have distance to base tag (v1.1.0-1-gCommitHash) | ||
GIT_VERSION=$(echo "${GIT_VERSION}" | sed "s/-g\([0-9a-f]\{14\}\)$/-\1/") | ||
fi | ||
if [[ "${GIT_TREE_STATE}" == "dirty" ]]; then | ||
# git describe --dirty only considers changes to existing files, but | ||
# that is problematic since new untracked .go files affect the build, | ||
# so use our idea of "dirty" from git status instead. | ||
GIT_VERSION+="-dirty" | ||
fi | ||
|
||
|
||
# Try to match the "git describe" output to a regex to try to extract | ||
# the "major" and "minor" versions and whether this is the exact tagged | ||
# version or whether the tree is between two tagged versions. | ||
if [[ "${GIT_VERSION}" =~ ^v([0-9]+)\.([0-9]+)(\.[0-9]+)?([-].*)?([+].*)?$ ]]; then | ||
GIT_MAJOR=${BASH_REMATCH[1]} | ||
GIT_MINOR=${BASH_REMATCH[2]} | ||
fi | ||
|
||
# If GIT_VERSION is not a valid Semantic Version, then refuse to build. | ||
if ! [[ "${GIT_VERSION}" =~ ^v([0-9]+)\.([0-9]+)(\.[0-9]+)?(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]]; then | ||
GIT_VERSION=v0.0.0+${GIT_VERSION} | ||
GIT_MAJOR=0 | ||
GIT_MINOR=0 | ||
fi | ||
else | ||
GIT_VERSION="UNKNOWN_GIT_VERSION" | ||
GIT_MAJOR="UNKNOWN_GIT_MAJOR_VERSION" | ||
GIT_MINOR="UNKNOWN_GIT_MINOR_VERSION" | ||
fi | ||
|
||
if GIT_RELEASE_TAG=$(git describe --abbrev=0 --tags 2> /dev/null); then | ||
GIT_RELEASE_COMMIT=$(git rev-list -n 1 ${GIT_RELEASE_TAG} | head -c 14) | ||
else | ||
GIT_RELEASE_TAG="UNKNOWN_RELEASE" | ||
GIT_RELEASE_COMMIT="UNKNOWN_RELEAE_COMMIT" | ||
fi | ||
|
||
GIT_BRANCH=$(git branch | grep \* | cut -d ' ' -f2) |
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,46 @@ | ||
#!/usr/bin/env bash | ||
# Copyright 2019 The Kubernetes Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -o errexit | ||
set -o xtrace | ||
|
||
# shellcheck source=/dev/null | ||
source "$(dirname "$0")/../hack/utils.sh" | ||
readonly REPO_PATH=$(get_root_path) | ||
readonly CAPDCTL_BIN=${REPO_PATH}/bin/capdctl | ||
readonly CAPDCTL_SRC=${REPO_PATH}/cmd/capdctl | ||
|
||
readonly CAPDMGR_BIN=${REPO_PATH}/bin/capd-manager | ||
readonly CAPDMGR_SRC=${REPO_PATH}/cmd/capd-manager | ||
|
||
readonly KIND_TEST_BIN=${REPO_PATH}/bin/kind-test | ||
readonly KIND_TEST_SRC=${REPO_PATH}/cmd/kind-test | ||
|
||
source "${REPO_PATH}/hack/set-workspace-status.sh" | ||
|
||
LDFLAGS="-X sigs.k8s.io/cluster-api-provider-docker/cmd/versioninfo.GitBranch=${GIT_BRANCH} \ | ||
-X sigs.k8s.io/cluster-api-provider-docker/cmd/versioninfo.GitReleaseTag=${GIT_RELEASE_TAG} \ | ||
-X sigs.k8s.io/cluster-api-provider-docker/cmd/versioninfo.GitReleaseCommit=${GIT_RELEASE_COMMIT} \ | ||
-X sigs.k8s.io/cluster-api-provider-docker/cmd/versioninfo.GitTreeState=${GIT_TREE_STATE} \ | ||
-X sigs.k8s.io/cluster-api-provider-docker/cmd/versioninfo.GitCommit=${GIT_COMMIT} \ | ||
-X sigs.k8s.io/cluster-api-provider-docker/cmd/versioninfo.GitMajor=${GIT_MAJOR} \ | ||
-X sigs.k8s.io/cluster-api-provider-docker/cmd/versioninfo.GitMinor=${GIT_MINOR}" | ||
|
||
# build capdctl | ||
go build -ldflags "${LDFLAGS}" -o ${CAPDCTL_BIN} ${CAPDCTL_SRC} | ||
# build capd-manager | ||
go build -ldflags "${LDFLAGS}" -o ${CAPDMGR_BIN} ${CAPDMGR_SRC} | ||
# build kind-test | ||
go build -ldflags "${LDFLAGS}" -o ${KIND_TEST_BIN} ${KIND_TEST_SRC} |