Browse Source

git-version: script detection of git tag/commit

pull/221/head
Brian Waldon 10 years ago
parent
commit
c3dd998441
  1. 2
      build
  2. 8
      build-docker-push
  3. 21
      git-version

2
build

@ -25,7 +25,7 @@ mkdir -p $GOPATH/src/github.com/coreos/
# Only attempt to link dex into godeps if it isn't already there
[ -d $GOPATH/src/github.com/coreos/dex ] || ln -s ${PWD} $GOPATH/src/github.com/coreos/dex
LD_FLAGS="-X main.version=$(git rev-parse HEAD)"
LD_FLAGS="-X main.version=$(./git-version)"
go build -o bin/dex-worker -ldflags="$LD_FLAGS" github.com/coreos/dex/cmd/dex-worker
go build -o bin/dexctl github.com/coreos/dex/cmd/dexctl
go build -o bin/dex-overlord -ldflags="$LD_FLAGS" github.com/coreos/dex/cmd/dex-overlord

8
build-docker-push

@ -12,9 +12,9 @@ else
docker login --username="$DOCKER_USER" --password="$DOCKER_PASSWORD" --email="dex@example.com" $DOCKER_REGISTRY
fi
git_sha=$(git rev-parse HEAD)
version=$(./git-version)
docker build -q --rm=true -t $repo:$git_sha .
docker tag -f $repo:$git_sha $repo:latest
docker push $repo:$git_sha
docker build -q --rm=true -t $repo:$version .
docker tag -f $repo:$version $repo:latest
docker push $repo:$version
docker push $repo:latest

21
git-version

@ -0,0 +1,21 @@
#!/bin/bash -e
# pull 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
Loading…
Cancel
Save