From 456962b2b83e1072d334ff1cf2842cd69ede92b9 Mon Sep 17 00:00:00 2001 From: Erik Wilson Date: Fri, 6 Mar 2020 10:48:20 -0700 Subject: [PATCH] Update versioning for no .git or go --- scripts/version.sh | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/scripts/version.sh b/scripts/version.sh index 7d6817b226..ee2aeae4b3 100755 --- a/scripts/version.sh +++ b/scripts/version.sh @@ -1,20 +1,25 @@ #!/bin/bash +ARCH=${ARCH:-$(go env GOARCH)} +SUFFIX="-${ARCH}" +GIT_TAG=$DRONE_TAG TREE_STATE=clean -if [ -n "$(git status --porcelain --untracked-files=no)" ]; then - DIRTY="-dirty" - TREE_STATE=dirty -fi +COMMIT=unknown -COMMIT=$(git log -n3 --pretty=format:"%H %ae" | grep -v ' drone@localhost$' | cut -f1 -d\ | head -1) -if [ -z "${COMMIT}" ]; then - COMMIT=$(git rev-parse HEAD) -fi - -GIT_TAG=${DRONE_TAG:-$(git tag -l --contains HEAD | head -n 1)} +if [ -d .git ]; then + if [ -z "$GIT_TAG" ]; then + GIT_TAG=$(git tag -l --contains HEAD | head -n 1) + fi + if [ -n "$(git status --porcelain --untracked-files=no)" ]; then + DIRTY="-dirty" + TREE_STATE=dirty + fi -ARCH=$(go env GOARCH) -SUFFIX="-${ARCH}" + COMMIT=$(git log -n3 --pretty=format:"%H %ae" | grep -v ' drone@localhost$' | cut -f1 -d\ | head -1) + if [ -z "${COMMIT}" ]; then + COMMIT=$(git rev-parse HEAD || true) + fi +fi VERSION_CONTAINERD=$(grep github.com/containerd/containerd go.mod | head -n1 | awk '{print $4}') if [ -z "$VERSION_CONTAINERD" ]; then