From cb5c0bea2d79b472b9f46a7c60fdd91757775433 Mon Sep 17 00:00:00 2001 From: Dalton Hubble Date: Fri, 8 Jan 2016 14:34:01 -0800 Subject: [PATCH] git-version: Add git-version commit/tag detection script --- docker-build | 2 +- docker-push | 2 +- git-version | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100755 git-version diff --git a/docker-build b/docker-build index 54db028b..402f0ada 100755 --- a/docker-build +++ b/docker-build @@ -1,7 +1,7 @@ #!/bin/bash -e REPO=coreos/bootcfg -GIT_SHA=$(git rev-parse HEAD) +GIT_SHA=$(./git-version) docker build -q --rm=true -t $REPO:$GIT_SHA . docker tag -f $REPO:$GIT_SHA $REPO:latest \ No newline at end of file diff --git a/docker-push b/docker-push index 6bc6b689..b37e0046 100755 --- a/docker-push +++ b/docker-push @@ -2,7 +2,7 @@ REPO=coreos/bootcfg QUAY_REPO=quay.io/coreos/bootcfg -GIT_SHA=$(git rev-parse HEAD) +GIT_SHA=$(./git-version) # quay.io docker tag -f $REPO:$GIT_SHA $QUAY_REPO:latest diff --git a/git-version b/git-version new file mode 100755 index 00000000..36dd38db --- /dev/null +++ b/git-version @@ -0,0 +1,21 @@ +#!/bin/bash -e + +# parse the current git commit hash +COMMIT=`git rev-parse HEAD` + +# check if the current commit has a matching tag +TAG=$(git describe --exact-match --abbrev=0 --tags ${COMMIT} 2> /dev/null || true) + +# use the matching tag as the version, if available +if [ -z "$TAG" ]; then + VERSION=$COMMIT +else + VERSION=$TAG +fi + +# check for changed files (not untracked files) +if [ -n "$(git diff --shortstat 2> /dev/null | tail -n1)" ]; then + VERSION="${VERSION}+dirty" +fi + +echo $VERSION \ No newline at end of file