diff --git a/scripts/build b/scripts/build index 8c354e9329..d0c85530ba 100755 --- a/scripts/build +++ b/scripts/build @@ -11,27 +11,26 @@ PKG_RANCHER_CONTAINERD="github.com/rancher/containerd" PKG_CRICTL="github.com/kubernetes-sigs/cri-tools" buildDate=$(date -u '+%Y-%m-%dT%H:%M:%SZ') -versionFiles=" - vendor/k8s.io/client-go/pkg/version/base.go - vendor/k8s.io/component-base/version/base.go -" - -for i in $versionFiles; do - sed -e "s/gitVersion\s*=.*/gitVersion=\"$VERSION\"/" -i $i - sed -e "s/gitCommit\s*=.*/gitCommit=\"$(git rev-parse HEAD)\"/" -i $i - if [[ -n "$DIRTY" ]]; then - sed -e "s/gitTreeState\s*=.*/gitTreeState=\"dirty\"/" -i $i - fi - sed -e "s/buildDate\s*=.*/buildDate=\"$buildDate\"/" -i $i -done VENDOR_PREFIX="${PKG}/vendor/" VERSIONFLAGS=" -X ${PKG}/pkg/version.Version=${VERSION} -X ${PKG}/pkg/version.GitCommit=${COMMIT:0:8} + + -X ${VENDOR_PREFIX}k8s.io/client-go/pkg/version.gitVersion=${VERSION} + -X ${VENDOR_PREFIX}k8s.io/client-go/pkg/version.gitCommit=${LONG_COMMIT} + -X ${VENDOR_PREFIX}k8s.io/client-go/pkg/version.gitTreeState=${TREE_STATE} + -X ${VENDOR_PREFIX}k8s.io/client-go/pkg/version.buildDate=${buildDate} + + -X ${VENDOR_PREFIX}k8s.io/component-base/version.gitVersion=${VERSION} + -X ${VENDOR_PREFIX}k8s.io/component-base/version.gitCommit=${LONG_COMMIT} + -X ${VENDOR_PREFIX}k8s.io/component-base/version.gitTreeState=${TREE_STATE} + -X ${VENDOR_PREFIX}k8s.io/component-base/version.buildDate=${buildDate} + -X ${VENDOR_PREFIX}${PKG_CONTAINERD}/version.Version=${VERSION_CONTAINERD} -X ${VENDOR_PREFIX}${PKG_CONTAINERD}/version.Package=${PKG_RANCHER_CONTAINERD} - -X ${VENDOR_PREFIX}${PKG_CRICTL}/pkg/version.Version=${VERSION_CRICTL}" + -X ${VENDOR_PREFIX}${PKG_CRICTL}/pkg/version.Version=${VERSION_CRICTL} +" LDFLAGS=" -w -s" STATIC=" diff --git a/scripts/version.sh b/scripts/version.sh index 614ebc8ee6..4ae8feece3 100755 --- a/scripts/version.sh +++ b/scripts/version.sh @@ -1,10 +1,14 @@ #!/bin/bash +TREE_STATE=clean if [ -n "$(git status --porcelain --untracked-files=no)" ]; then DIRTY="-dirty" + TREE_STATE=dirty fi COMMIT=$(git rev-parse --short HEAD) +LONG_COMMIT=$(git rev-parse HEAD) + GIT_TAG=${DRONE_TAG:-$(git tag -l --contains HEAD | head -n 1)} ARCH=$(go env GOARCH) @@ -30,6 +34,6 @@ VERSION_CNIPLUGINS="v0.7.6-k3s1" if [[ -n "$GIT_TAG" ]]; then VERSION=$GIT_TAG else - VERSION="$(sed -e 's/[-+].*//' <<< "$VERSION_K8S")+$COMMIT" + VERSION="$(sed -e 's/[-+].*//' <<< "$VERSION_K8S")+$COMMIT$DIRTY" VERSION_TAG="$(sed -e 's/+/-/g' <<< "$VERSION")" fi