git-version: Add git-version commit/tag detection script

This commit is contained in:
Dalton Hubble
2016-01-08 14:34:01 -08:00
parent 787ddee22a
commit cb5c0bea2d
3 changed files with 23 additions and 2 deletions

View File

@@ -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

View File

@@ -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

21
git-version Executable file
View File

@@ -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