Fix #3: ensure gitversion produces reliable versioning info across all branches

This commit is contained in:
2015-01-10 18:05:39 -08:00
parent 98740ba3aa
commit 7ce5fabce7
10 changed files with 462 additions and 366 deletions

View File

@@ -1,21 +1,21 @@
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2013 Andrew Kesterson <andrew@aklabs.net> Copyright (c) 2013 Andrew Kesterson <andrew@aklabs.net>
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions: furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software. all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.

190
Makefile
View File

@@ -1,95 +1,95 @@
VERSION:=$(shell if [ -d .git ]; then bash -c 'gitversion.sh | grep "^MAJOR=" | cut -d = -f 2'; else source version.sh && echo $$MAJOR ; fi) VERSION:=$(shell if [ -d .git ]; then bash -c 'gitversion.sh | grep "^MAJOR=" | cut -d = -f 2'; else source version.sh && echo $$MAJOR ; fi)
RELEASE:=$(shell if [ -d .git ]; then bash -c 'gitversion.sh | grep "^BUILD=" | cut -d = -f 2'; else source version.sh && echo $$BUILD ; fi) RELEASE:=$(shell if [ -d .git ]; then bash -c 'gitversion.sh | grep "^BUILD=" | cut -d = -f 2'; else source version.sh && echo $$BUILD ; fi)
DISTFILE=./dist/versioners-$(VERSION)-$(RELEASE).tar.gz DISTFILE=./dist/versioners-$(VERSION)-$(RELEASE).tar.gz
SPECFILE=versioners.spec SPECFILE=versioners.spec
ifndef RHEL_VERSION ifndef RHEL_VERSION
RHEL_VERSION=5 RHEL_VERSION=5
endif endif
ifeq ($(RHEL_VERSION),5) ifeq ($(RHEL_VERSION),5)
MOCKFLAGS=--define "_source_filedigest_algorithm md5" --define "_binary_filedigest_algorithm md5" MOCKFLAGS=--define "_source_filedigest_algorithm md5" --define "_binary_filedigest_algorithm md5"
endif endif
ifndef PREFIX ifndef PREFIX
PREFIX='' PREFIX=''
endif endif
RHEL_RELEASE:=$(RELEASE).el$(RHEL_VERSION) RHEL_RELEASE:=$(RELEASE).el$(RHEL_VERSION)
SRPM=versioners-$(VERSION)-$(RHEL_RELEASE).src.rpm SRPM=versioners-$(VERSION)-$(RHEL_RELEASE).src.rpm
RPM=versioners-$(VERSION)-$(RHEL_RELEASE).noarch.rpm RPM=versioners-$(VERSION)-$(RHEL_RELEASE).noarch.rpm
RHEL_DISTFILE=./dist/versioners-$(VERSION)-$(RHEL_RELEASE).tar.gz RHEL_DISTFILE=./dist/versioners-$(VERSION)-$(RHEL_RELEASE).tar.gz
DISTFILE_DEPS=$(shell find . -type f | grep -Ev '\.git|\./dist/|$(DISTFILE)') DISTFILE_DEPS=$(shell find . -type f | grep -Ev '\.git|\./dist/|$(DISTFILE)')
all: ./dist/$(RPM) all: ./dist/$(RPM)
# --- PHONY targets # --- PHONY targets
.PHONY: clean srpm rpm gitclean dist .PHONY: clean srpm rpm gitclean dist
clean: clean:
rm -f $(DISTFILE) $(RHEL_DISTFILE) rm -f $(DISTFILE) $(RHEL_DISTFILE)
rm -fr dist/versioners-$(VERSION)-$(RELEASE)* rm -fr dist/versioners-$(VERSION)-$(RELEASE)*
version.sh: version.sh:
gitversion.sh > version.sh gitversion.sh > version.sh
dist: $(DISTFILE) dist: $(DISTFILE)
srpm: ./dist/$(SRPM) srpm: ./dist/$(SRPM)
rpm: ./dist/$(RPM) ./dist/$(SRPM) rpm: ./dist/$(RPM) ./dist/$(SRPM)
gitclean: gitclean:
git clean -df git clean -df
# --- End phony targets # --- End phony targets
version.sh: version.sh:
if [ ! -d .git ] && [ -f version.sh ]; then echo "No git, keeping old version.sh" ; fi ; \ if [ ! -d .git ] && [ -f version.sh ]; then echo "No git, keeping old version.sh" ; fi ; \
if [ ! -d .git ] && [ ! -f version.sh ]; then echo "No git and no version.sh, you're boned"; exit 1; fi ; \ if [ ! -d .git ] && [ ! -f version.sh ]; then echo "No git and no version.sh, you're boned"; exit 1; fi ; \
if [ -d .git ] ; then \ if [ -d .git ] ; then \
bash ./gitversion.sh > tmpversion.sh && \ bash ./gitversion.sh > tmpversion.sh && \
VERSIONSHA=$$(openssl sha1 version.sh | cut -d = -f 2) ; \ VERSIONSHA=$$(openssl sha1 version.sh | cut -d = -f 2) ; \
TMPVERSIONSHA=$$(openssl sha1 tmpversion.sh | cut -d = -f 2) ; \ TMPVERSIONSHA=$$(openssl sha1 tmpversion.sh | cut -d = -f 2) ; \
if [ ! -e version.sh ] || [ "$$VERSIONSHA" != "$$TMPVERSIONSHA" ]; then \ if [ ! -e version.sh ] || [ "$$VERSIONSHA" != "$$TMPVERSIONSHA" ]; then \
mv tmpversion.sh version.sh; \ mv tmpversion.sh version.sh; \
fi; \ fi; \
fi fi
$(DISTFILE): version.sh $(DISTFILE): version.sh
mkdir -p dist/ mkdir -p dist/
mkdir dist/versioners-$(VERSION)-$(RELEASE) || rm -fr dist/versioners-$(VERSION)-$(RELEASE) mkdir dist/versioners-$(VERSION)-$(RELEASE) || rm -fr dist/versioners-$(VERSION)-$(RELEASE)
rsync -aWH . --exclude=.git --exclude=dist ./dist/versioners-$(VERSION)-$(RELEASE)/ rsync -aWH . --exclude=.git --exclude=dist ./dist/versioners-$(VERSION)-$(RELEASE)/
cd dist && tar -czvf ../$@ versioners-$(VERSION)-$(RELEASE) cd dist && tar -czvf ../$@ versioners-$(VERSION)-$(RELEASE)
$(RHEL_DISTFILE): $(DISTFILE) $(RHEL_DISTFILE): $(DISTFILE)
cd dist && \ cd dist && \
cp -R versioners-$(VERSION)-$(RELEASE) versioners-$(VERSION)-$(RHEL_RELEASE) && \ cp -R versioners-$(VERSION)-$(RELEASE) versioners-$(VERSION)-$(RHEL_RELEASE) && \
tar -czvf ../$@ versioners-$(VERSION)-$(RHEL_RELEASE) tar -czvf ../$@ versioners-$(VERSION)-$(RHEL_RELEASE)
./dist/$(SRPM): $(RHEL_DISTFILE) ./dist/$(SRPM): $(RHEL_DISTFILE)
rm -fr ./dist/$(SRPM) rm -fr ./dist/$(SRPM)
/usr/bin/mock --verbose -r epel-$(RHEL_VERSION)-noarch --buildsrpm --spec $(SPECFILE) $(MOCKFLAGS) --sources ./dist/ --resultdir ./dist/ --define "version $(VERSION)" --define "release $(RHEL_RELEASE)" /usr/bin/mock --verbose -r epel-$(RHEL_VERSION)-noarch --buildsrpm --spec $(SPECFILE) $(MOCKFLAGS) --sources ./dist/ --resultdir ./dist/ --define "version $(VERSION)" --define "release $(RHEL_RELEASE)"
./dist/$(RPM): ./dist/$(SRPM) ./dist/$(RPM): ./dist/$(SRPM)
rm -fr ./dist/$(RPM) rm -fr ./dist/$(RPM)
/usr/bin/mock --verbose -r epel-$(RHEL_VERSION)-noarch ./dist/$(SRPM) --resultdir ./dist/ --define "version $(VERSION)" --define "release $(RHEL_RELEASE)" /usr/bin/mock --verbose -r epel-$(RHEL_VERSION)-noarch ./dist/$(SRPM) --resultdir ./dist/ --define "version $(VERSION)" --define "release $(RHEL_RELEASE)"
uninstall: uninstall:
rm -f $(PREFIX)/usr/bin/taggit.sh rm -f $(PREFIX)/usr/bin/taggit.sh
rm -f $(PREFIX)/usr/bin/taghg.sh rm -f $(PREFIX)/usr/bin/taghg.sh
rm -f $(PREFIX)/usr/bin/gitversion.sh rm -f $(PREFIX)/usr/bin/gitversion.sh
rm -f $(PREFIX)/usr/bin/hgversion.sh rm -f $(PREFIX)/usr/bin/hgversion.sh
install: install:
mkdir -p $(PREFIX)/usr/bin mkdir -p $(PREFIX)/usr/bin
install ./gitversion.sh $(PREFIX)/usr/bin/gitversion.sh install ./gitversion.sh $(PREFIX)/usr/bin/gitversion.sh
install ./hgversion.sh $(PREFIX)/usr/bin/hgversion.sh install ./hgversion.sh $(PREFIX)/usr/bin/hgversion.sh
install ./taggit.sh $(PREFIX)/usr/bin/taggit.sh install ./taggit.sh $(PREFIX)/usr/bin/taggit.sh
install ./taghg.sh $(PREFIX)/usr/bin/taghg.sh install ./taghg.sh $(PREFIX)/usr/bin/taghg.sh
MANIFEST: MANIFEST:
echo /usr/bin/gitversion.sh > MANIFEST echo /usr/bin/gitversion.sh > MANIFEST
echo /usr/bin/hgversion.sh >> MANIFEST echo /usr/bin/hgversion.sh >> MANIFEST
echo /usr/bin/taggit.sh >> MANIFEST echo /usr/bin/taggit.sh >> MANIFEST
echo /usr/bin/taghg.sh >> MANIFEST echo /usr/bin/taghg.sh >> MANIFEST

View File

@@ -1,78 +1,78 @@
#!/bin/bash #!/bin/bash
LOGSPEC='%ci %an <%aE>%n%n %s%n [%h]%d%n' LOGSPEC='%ci %an <%aE>%n%n %s%n [%h]%d%n'
VERSIONERS_SEPARATOR=${VERSIONERS_SEPARATOR:-,} VERSIONERS_SEPARATOR=${VERSIONERS_SEPARATOR:-,}
BRANCH=$2 BRANCH=$2
if [ "${BRANCH}" == "" ]; then if [ "${BRANCH}" == "" ]; then
BRANCH=$(git branch | grep '^\*\s*.*' | cut -d ' ' -f 2-) BRANCH=$(git branch | grep '^\*\s*.*' | cut -d ' ' -f 2-)
fi fi
REBUILDING=0 REBUILDING=0
SHA1=$(git rev-parse HEAD) SHA1=$(git rev-parse HEAD)
TAG=$(git describe --tags --abbrev=0 `git rev-list --tags --max-count=1 HEAD` 2>/dev/null) TAG=$(git describe --tags --abbrev=0 2>/dev/null)
BUILD=0 BUILD=0
TAGSHA=$(git rev-list $TAG | head -n 1) TAGSHA=$(git rev-list $TAG | head -n 1)
CHANGELOG="$(git log --format="format:$LOGSPEC" ${TAGSHA}..HEAD)" CHANGELOG="$(git log --format="format:$LOGSPEC" ${TAGSHA}..HEAD)"
if [ "$TAG" == "" ]; then if [ "$TAG" == "" ]; then
BUILD=0 BUILD=0
REBUILDING=1 REBUILDING=1
MAJOR=$BRANCH MAJOR=$BRANCH
else else
MAJOR=$(echo $TAG | cut -d ${VERSIONERS_SEPARATOR} -f 2) MAJOR=$(echo $TAG | cut -d ${VERSIONERS_SEPARATOR} -f 2)
BUILD=$(echo $TAG | cut -d ${VERSIONERS_SEPARATOR} -f 3) BUILD=$(echo $TAG | cut -d ${VERSIONERS_SEPARATOR} -f 3)
if [ "$TAGSHA" != "$SHA1" ]; then if [ "$TAGSHA" != "$SHA1" ]; then
CHANGELOG="$(git log --format="format:$LOGSPEC" $TAGSHA..$SHA1)" CHANGELOG="$(git log --format="format:$LOGSPEC" $TAGSHA..$SHA1)"
BUILD=$(expr $BUILD + 1) BUILD=$(expr $BUILD + 1)
REBUILDING=1 REBUILDING=1
else else
SHA1=$TAGSHA SHA1=$TAGSHA
fi fi
fi fi
OS_NAME="" OS_NAME=""
OS_VERSION="" OS_VERSION=""
if [ "$OS_NAME" == "" ] && [ "$(uname)" == "Darwin" ]; then if [ "$OS_NAME" == "" ] && [ "$(uname)" == "Darwin" ]; then
OS_NAME="osx" OS_NAME="osx"
elif [ "$OS_NAME" == "" ] && [ -f /etc/redhat-release ]; then elif [ "$OS_NAME" == "" ] && [ -f /etc/redhat-release ]; then
OS_NAME="el" OS_NAME="el"
elif [ "$OS_NAME" == "" ] && [ "$(uname | grep -i '^MINGW')" != "" ] || [ "$(uname | grep -i '^CYGWIN')" != "" ]; then elif [ "$OS_NAME" == "" ] && [ "$(uname | grep -i '^MINGW')" != "" ] || [ "$(uname | grep -i '^CYGWIN')" != "" ]; then
OS_NAME="win" OS_NAME="win"
fi fi
if [ "$OS_VERSION" == "" ] && [ "$OS_NAME" == "el" ]; then if [ "$OS_VERSION" == "" ] && [ "$OS_NAME" == "el" ]; then
OS_VERSION=$(cat /etc/redhat-release | grep -o "release [0-9]" | cut -d " " -f 2) OS_VERSION=$(cat /etc/redhat-release | grep -o "release [0-9]" | cut -d " " -f 2)
RHEL_VERSION=$OS_VERSION RHEL_VERSION=$OS_VERSION
elif [ "$OS_VERSION" == "" ] && [ "$OS_NAME" == "osx" ]; then elif [ "$OS_VERSION" == "" ] && [ "$OS_NAME" == "osx" ]; then
OS_VERSION="$(sw_vers | grep 'ProductVersion:' | grep -o '[0-9]*\.[0-9]*\.[0-9]*')" OS_VERSION="$(sw_vers | grep 'ProductVersion:' | grep -o '[0-9]*\.[0-9]*\.[0-9]*')"
elif [ "$OS_VERSION" == "" ] && [ "$OS_NAME" == "win" ]; then elif [ "$OS_VERSION" == "" ] && [ "$OS_NAME" == "win" ]; then
echo "OS_VERSION unsupported on Microsoft Windows." >&2 echo "OS_VERSION unsupported on Microsoft Windows." >&2
fi fi
if [ "$ARCH" == "" ]; then if [ "$ARCH" == "" ]; then
if [ "$OS_NAME" == "osx" ]; then if [ "$OS_NAME" == "osx" ]; then
ARCH=$(uname -m) ARCH=$(uname -m)
elif [ "$OS_NAME" != "win" ]; then elif [ "$OS_NAME" != "win" ]; then
ARCH=$(uname -i) ARCH=$(uname -i)
elif [ "$OS_NAME" == "win" ]; then elif [ "$OS_NAME" == "win" ]; then
ARCH=$(uname -m) ARCH=$(uname -m)
fi fi
fi fi
SOURCE=$((git remote show origin 2>/dev/null | grep "Fetch URL" | cut -d : -f 2- | cut -d ' ' -f 2-) || echo '') SOURCE=$((git remote show origin 2>/dev/null | grep "Fetch URL" | cut -d : -f 2- | cut -d ' ' -f 2-) || echo '')
echo "TAG=\"${TAG}\"" echo "TAG=\"${TAG}\""
echo "BRANCH=\"${BRANCH}\"" echo "BRANCH=\"${BRANCH}\""
echo "MAJOR=\"${MAJOR}\"" echo "MAJOR=\"${MAJOR}\""
echo "BUILD=\"${BUILD}\"" echo "BUILD=\"${BUILD}\""
echo "SHA1=\"${SHA1}\"" echo "SHA1=\"${SHA1}\""
echo "OS_NAME=\"\${OS_NAME:-$OS_NAME}\"" echo "OS_NAME=\"\${OS_NAME:-$OS_NAME}\""
echo "OS_VERSION=\"\${OS_VERSION:-$OS_VERSION}\"" echo "OS_VERSION=\"\${OS_VERSION:-$OS_VERSION}\""
echo "ARCH=\"\${ARCH:-$ARCH}\"" echo "ARCH=\"\${ARCH:-$ARCH}\""
echo "VERSION=\"${MAJOR}-${BUILD}\"" echo "VERSION=\"${MAJOR}-${BUILD}\""
echo "BUILDHOST=\"$(hostname)\"" echo "BUILDHOST=\"$(hostname)\""
echo "BUILDUSER=\"$(whoami)\"" echo "BUILDUSER=\"$(whoami)\""
echo "BUILDDIR=\"$(pwd)\"" echo "BUILDDIR=\"$(pwd)\""
echo "SOURCE=\"${SOURCE}\"" echo "SOURCE=\"${SOURCE}\""
echo "REBUILDING=$REBUILDING" echo "REBUILDING=$REBUILDING"
echo "CHANGELOG=\"$CHANGELOG\"" echo "CHANGELOG=\"$CHANGELOG\""

View File

@@ -1,77 +1,77 @@
#!/bin/bash #!/bin/bash
BRANCH=$2 BRANCH=$2
if [ "${BRANCH}" == "" ]; then if [ "${BRANCH}" == "" ]; then
BRANCH=$(hg identify -b) BRANCH=$(hg identify -b)
fi fi
REBUILDING=0 REBUILDING=0
SHA1=$(hg identify -i | grep -Eo "[a-zA-Z0-9]+") SHA1=$(hg identify -i | grep -Eo "[a-zA-Z0-9]+")
TAG=$(hg parents --template '{latesttag}') TAG=$(hg parents --template '{latesttag}')
TAGSHA=$(hg identify -r $TAG | cut -d ' ' -f 1) TAGSHA=$(hg identify -r $TAG | cut -d ' ' -f 1)
BUILD=0 BUILD=0
CHANGELOG="$(hg log --branch $BRANCH -X .hgtags --style=changelog -r ${TAG}:${SHA1})" CHANGELOG="$(hg log --branch $BRANCH -X .hgtags --style=changelog -r ${TAG}:${SHA1})"
if [ "$TAG" == "" ]; then if [ "$TAG" == "" ]; then
BUILD=0 BUILD=0
REBUILDING=1 REBUILDING=1
MAJOR=$BRANCH MAJOR=$BRANCH
else else
MAJOR=$(echo $TAG | cut -d \| -f 2) MAJOR=$(echo $TAG | cut -d \| -f 2)
BUILD=$(echo $TAG | cut -d \| -f 3) BUILD=$(echo $TAG | cut -d \| -f 3)
SHORTTAGSHA=${TAGSHA:0:12} SHORTTAGSHA=${TAGSHA:0:12}
hg log -r tip | grep "Added tag build|${BRANCH}|${BUILD} for changeset ${SHORTTAGSHA}" >/dev/null hg log -r tip | grep "Added tag build|${BRANCH}|${BUILD} for changeset ${SHORTTAGSHA}" >/dev/null
if [ $? -ne 0 ] && [ "$TAGSHA" != "$SHA1" ]; then if [ $? -ne 0 ] && [ "$TAGSHA" != "$SHA1" ]; then
CHANGELOG="$(hg log --branch $BRANCH -X .hgtags --style=changelog -r ${SHORTTAGSHA}:${SHA1})" CHANGELOG="$(hg log --branch $BRANCH -X .hgtags --style=changelog -r ${SHORTTAGSHA}:${SHA1})"
BUILD=$(expr $BUILD + 1) BUILD=$(expr $BUILD + 1)
REBUILDING=1 REBUILDING=1
else else
SHA1=$TAGSHA SHA1=$TAGSHA
fi fi
fi fi
OS_NAME="" OS_NAME=""
OS_VERSION="" OS_VERSION=""
if [ "$OS_NAME" == "" ] && [ "$(uname)" == "Darwin" ]; then if [ "$OS_NAME" == "" ] && [ "$(uname)" == "Darwin" ]; then
OS_NAME="osx" OS_NAME="osx"
elif [ "$OS_NAME" == "" ] && [ -f /etc/redhat-release ]; then elif [ "$OS_NAME" == "" ] && [ -f /etc/redhat-release ]; then
OS_NAME="el" OS_NAME="el"
elif [ "$OS_NAME" == "" ] && [ "$(uname | grep -i '^MINGW')" != "" ] || [ "$(uname | grep -i '^CYGWIN')" != "" ]; then elif [ "$OS_NAME" == "" ] && [ "$(uname | grep -i '^MINGW')" != "" ] || [ "$(uname | grep -i '^CYGWIN')" != "" ]; then
OS_NAME="win" OS_NAME="win"
fi fi
if [ "$OS_VERSION" == "" ] && [ "$OS_NAME" == "el" ]; then if [ "$OS_VERSION" == "" ] && [ "$OS_NAME" == "el" ]; then
OS_VERSION=$(cat /etc/redhat-release | grep -o "release [0-9]" | cut -d " " -f 2) OS_VERSION=$(cat /etc/redhat-release | grep -o "release [0-9]" | cut -d " " -f 2)
RHEL_VERSION=$OS_VERSION RHEL_VERSION=$OS_VERSION
elif [ "$OS_VERSION" == "" ] && [ "$OS_NAME" == "osx" ]; then elif [ "$OS_VERSION" == "" ] && [ "$OS_NAME" == "osx" ]; then
OS_VERSION="$(sw_vers | grep 'ProductVersion:' | grep -o '[0-9]*\.[0-9]*\.[0-9]*')" OS_VERSION="$(sw_vers | grep 'ProductVersion:' | grep -o '[0-9]*\.[0-9]*\.[0-9]*')"
elif [ "$OS_VERSION" == "" ] && [ "$OS_NAME" == "win" ]; then elif [ "$OS_VERSION" == "" ] && [ "$OS_NAME" == "win" ]; then
echo "OS_VERSION unsupported on Microsoft Windows." >&2 echo "OS_VERSION unsupported on Microsoft Windows." >&2
fi fi
if [ "$ARCH" == "" ]; then if [ "$ARCH" == "" ]; then
if [ "$OS_NAME" == "osx" ]; then if [ "$OS_NAME" == "osx" ]; then
ARCH=$(uname -m) ARCH=$(uname -m)
elif [ "$OS_NAME" != "win" ]; then elif [ "$OS_NAME" != "win" ]; then
ARCH=$(uname -i) ARCH=$(uname -i)
elif [ "$OS_NAME" == "win" ]; then elif [ "$OS_NAME" == "win" ]; then
ARCH=$(uname -m) ARCH=$(uname -m)
fi fi
fi fi
SOURCE=$((cat .hg/hgrc 2>/dev/null | grep default | cut -d = -f 2 | sed s/"^ *"//g) || echo '') SOURCE=$((cat .hg/hgrc 2>/dev/null | grep default | cut -d = -f 2 | sed s/"^ *"//g) || echo '')
echo "TAG=\"${TAG}\"" echo "TAG=\"${TAG}\""
echo "BRANCH=\"${BRANCH}\"" echo "BRANCH=\"${BRANCH}\""
echo "MAJOR=\"${MAJOR}\"" echo "MAJOR=\"${MAJOR}\""
echo "BUILD=\"${BUILD}\"" echo "BUILD=\"${BUILD}\""
echo "SHA1=\"${SHA1}\"" echo "SHA1=\"${SHA1}\""
echo "OS_NAME=\"\${OS_NAME:-$OS_NAME}\"" echo "OS_NAME=\"\${OS_NAME:-$OS_NAME}\""
echo "OS_VERSION=\"\${OS_VERSION:-$OS_VERSION}\"" echo "OS_VERSION=\"\${OS_VERSION:-$OS_VERSION}\""
echo "ARCH=\"\${ARCH:-$ARCH}\"" echo "ARCH=\"\${ARCH:-$ARCH}\""
echo "VERSION=\"${MAJOR}-${BUILD}\"" echo "VERSION=\"${MAJOR}-${BUILD}\""
echo "BUILDHOST=\"$(hostname)\"" echo "BUILDHOST=\"$(hostname)\""
echo "BUILDUSER=\"$(whoami)\"" echo "BUILDUSER=\"$(whoami)\""
echo "BUILDDIR=\"$(pwd)\"" echo "BUILDDIR=\"$(pwd)\""
echo "SOURCE=\"${SOURCE}\"" echo "SOURCE=\"${SOURCE}\""
echo "REBUILDING=$REBUILDING" echo "REBUILDING=$REBUILDING"
echo "CHANGELOG=\"$CHANGELOG\"" echo "CHANGELOG=\"$CHANGELOG\""

View File

@@ -1,34 +1,34 @@
#!/bin/bash #!/bin/bash
SEP=${VERSIONERS_SEPARATOR:-,} SEP=${VERSIONERS_SEPARATOR:-,}
VERSIONERS_TAGBASE=${VERSIONERS_TAGBASE:-build} VERSIONERS_TAGBASE=${VERSIONERS_TAGBASE:-build}
if [ "$MAKETAG" == "false" ]; then if [ "$MAKETAG" == "false" ]; then
exit 0 exit 0
fi fi
if [ ! -f version.sh ]; then if [ ! -f version.sh ]; then
$(dirname $BASH_SOURCE)/gitversion.sh > version.sh $(dirname $BASH_SOURCE)/gitversion.sh > version.sh
fi fi
. ~/.buildtoolsrc || echo . ~/.buildtoolsrc || echo
. version.sh . version.sh
WHOLETAG="${VERSIONERS_TAGBASE}${SEP}${MAJOR}${SEP}${BUILD}" WHOLETAG="${VERSIONERS_TAGBASE}${SEP}${MAJOR}${SEP}${BUILD}"
git fetch --tags git fetch --tags
TAGSHA1=$(git rev-list $TAG | head -n 1) TAGSHA1=$(git rev-list $TAG | head -n 1)
if [ $REBUILDING -eq 0 ]; then if [ $REBUILDING -eq 0 ]; then
echo "This is a rebuild of a previous tag, not tagging or pushing" >&2 echo "This is a rebuild of a previous tag, not tagging or pushing" >&2
elif [ "$(git tag | grep $WHOLETAG)" != "" ] && [ "$TAGSHA1" != "" ] && [ "$TAGSHA1" != "$SHA1" ]; then elif [ "$(git tag | grep $WHOLETAG)" != "" ] && [ "$TAGSHA1" != "" ] && [ "$TAGSHA1" != "$SHA1" ]; then
echo "Someone else tagged my buildnumber (${WHOLETAG}) onto $TAGSHA1, while I built it from $SHA1 ... "'Help!' >&2 echo "Someone else tagged my buildnumber (${WHOLETAG}) onto $TAGSHA1, while I built it from $SHA1 ... "'Help!' >&2
exit 1 exit 1
elif [ "$TAGSHA1" != "" ] && [ "$TAGSHA1" == "$SHA1" ]; then elif [ "$TAGSHA1" != "" ] && [ "$TAGSHA1" == "$SHA1" ]; then
echo "Someone else built this version at the same time I did, and we both tagged the same SHA1 with the same build tag. Not pushing my tag." echo "Someone else built this version at the same time I did, and we both tagged the same SHA1 with the same build tag. Not pushing my tag."
else else
git tag -f -a "${WHOLETAG}" -m "Tagging for ${MAJOR}-${BUILD}" $SHA1 git tag -f -a "${WHOLETAG}" -m "Tagging for ${MAJOR}-${BUILD}" $SHA1
if [ "$PUSHTAG" != "false" ]; then if [ "$PUSHTAG" != "false" ]; then
git push --tags git push --tags
fi fi
fi fi

View File

@@ -1,30 +1,30 @@
#!/bin/bash #!/bin/bash
if [ "$MAKETAG" == "false" ]; then if [ "$MAKETAG" == "false" ]; then
exit 0 exit 0
fi fi
if [ ! -f version ]; then if [ ! -f version ]; then
${dirname $BASH_SOURCE)/genversion > version ${dirname $BASH_SOURCE)/genversion > version
fi fi
. ~/.buildtoolsrc . ~/.buildtoolsrc
. version . version
hg pull -u --branch $(hg branch) hg pull -u --branch $(hg branch)
TAGSHA1=$(cat .hgtags | grep "build,${MAJOR},${BUILD}" | cut -d " " -f 1) TAGSHA1=$(cat .hgtags | grep "build,${MAJOR},${BUILD}" | cut -d " " -f 1)
echo "$TAGSHA1" | grep "^$SHA1" >/dev/null 2>&1 echo "$TAGSHA1" | grep "^$SHA1" >/dev/null 2>&1
SHORTSHAMATCH=$? SHORTSHAMATCH=$?
if [ $REBUILDING -eq 0 ]; then if [ $REBUILDING -eq 0 ]; then
echo "This is a rebuild of a previous tag, not tagging or pushing" >&2 echo "This is a rebuild of a previous tag, not tagging or pushing" >&2
elif [ "$TAGSHA1" != "" ] && [ $SHORTSHAMATCH -ne 0 ]; then elif [ "$TAGSHA1" != "" ] && [ $SHORTSHAMATCH -ne 0 ]; then
echo "Someone else tagged my buildnumber (branch|${MAJOR}|${BUILD}) onto $TAGSHA1, while I built it from $SHA1 ... "'Help!' >&2 echo "Someone else tagged my buildnumber (branch|${MAJOR}|${BUILD}) onto $TAGSHA1, while I built it from $SHA1 ... "'Help!' >&2
exit 1 exit 1
elif [ "$TAGSHA1" != "" ] && [ $SHORTSHAMATCH -eq 0 ]; then elif [ "$TAGSHA1" != "" ] && [ $SHORTSHAMATCH -eq 0 ]; then
echo "Someone else built this version at the same time I did, and we both tagged the same SHA1 with the same build tag. Not pushing my tag." echo "Someone else built this version at the same time I did, and we both tagged the same SHA1 with the same build tag. Not pushing my tag."
else else
hg tag -f -r ${SHA1} "build|${MAJOR}|${BUILD}" hg tag -f -r ${SHA1} "build|${MAJOR}|${BUILD}"
if [ "$PUSHTAG" != "false" ]; then if [ "$PUSHTAG" != "false" ]; then
hg push hg push
fi fi
fi fi

61
tests/test_gitversion.sh Normal file
View File

@@ -0,0 +1,61 @@
#!/bin/bash
BASEDIR=$(pwd)
function die
{
echo "$1"
exit 1
}
function shunittest_gitversion_use_correct_tag
{
tdir=$(mktemp -d)
trap "rm -fr ${tdir}" EXIT
cd ${tdir}
git init .
touch README
git add README
git commit -m 'test' README
git tag -a -m 1.0-0 build,1.0,0
${BASEDIR}/gitversion.sh > version.sh
. version.sh
[[ "$MAJOR" == "1.0" ]] || die "MAJOR should be 1.0, not $MAJOR"
[[ "$BUILD" == "0" ]] || die "BUILD should be 0, not $BUILD"
git checkout -b branch1
echo 'This is a meaningless change' > README
git commit -m 'edited readme' README
git tag -a -m 2.0dev-0 build,2.0dev,0
${BASEDIR}/gitversion.sh > version.sh
. version.sh
[[ "$MAJOR" == "2.0dev" ]] || die "MAJOR should be 2.0dev, not $MAJOR"
[[ "$BUILD" == "0" ]] || die "BUILD should be 0, not $BUILD"
git checkout master
${BASEDIR}/gitversion.sh > version.sh
. version.sh
[[ "$MAJOR" == "1.0" ]] || die "MAJOR should be 1.0, not $MAJOR"
[[ "$BUILD" == "0" ]] || die "BUILD should be 0, not $BUILD"
}
function shunittest_gitversion_correct_rebuilding
{
tdir=$(mktemp -d)
trap "rm -fr ${tdir}" EXIT
cd ${tdir}
git init .
touch README
git add README
git commit -m 'test' README
git tag -a -m 1.0-0 build,1.0,0
${BASEDIR}/gitversion.sh > version.sh
. version.sh
[[ "$REBUILDING" == "0" ]] || die "REBUILDING should be 0, not $REBUILDING"
echo 'small meaningless change' > README
git commit -m 'test 2' README
${BASEDIR}/gitversion.sh > version.sh
. version.sh
[[ "$REBUILDING" == "1" ]] || die "REBUILDING should be 1, not $REBUILDING"
}

View File

@@ -1,4 +0,0 @@
function shunittest_shutup
{
return 0
}

39
tests/test_taggit.sh Normal file
View File

@@ -0,0 +1,39 @@
#!/bin/bash
BASEDIR=$(pwd)
function die
{
echo "$1"
exit 1
}
function shunittest_test_environment_separator
{
tdir=$(mktemp -d)
trap "rm -fr ${tdir}" EXIT
cd ${tdir}
git init .
touch README
git add README
git commit -m 'test' README
VERSIONERS_SEPARATOR='X' ${BASEDIR}/taggit.sh
${BASEDIR}/gitversion.sh > version.sh
tag=$(git describe --tags --abbrev=0)
[[ "$tag" == "buildXmasterX0" ]] || die "Tag should be buildXmasterX0, got $tag"
}
function shunittest_test_environment_tagbase
{
tdir=$(mktemp -d)
trap "rm -fr ${tdir}" EXIT
cd ${tdir}
git init .
touch README
git add README
git commit -m 'test' README
VERSIONERS_TAGBASE='release' ${BASEDIR}/taggit.sh
${BASEDIR}/gitversion.sh > version.sh
tag=$(git describe --tags --abbrev=0)
[[ "$tag" == "release,master,0" ]] || die "Tag should be release,master,0, got $tag"
}

View File

@@ -1,27 +1,27 @@
%define __os_install_post %{nil} %define __os_install_post %{nil}
Summary: Automatic Versioning Tools Summary: Automatic Versioning Tools
Name: versioners Name: versioners
Version: %{version} Version: %{version}
Release: %{release} Release: %{release}
License: Andrew Kesterson License: Andrew Kesterson
Vendor: Andrew Kesterson Vendor: Andrew Kesterson
Packager: Andrew Kesterson <andrew@aklabs.net> Packager: Andrew Kesterson <andrew@aklabs.net>
Group: Development Tools Group: Development Tools
Provides: %{name} Provides: %{name}
BuildArch: noarch BuildArch: noarch
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release} BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}
Source: %{name}-%{version}-%{release}.tar.gz Source: %{name}-%{version}-%{release}.tar.gz
Requires: bash Requires: bash
%description %description
%install %install
mkdir -p %{buildroot}/usr/src mkdir -p %{buildroot}/usr/src
tar -zxvf %{_sourcedir}/%{name}-%{version}-%{release}.tar.gz tar -zxvf %{_sourcedir}/%{name}-%{version}-%{release}.tar.gz
cd %{name}-%{version}-%{release} cd %{name}-%{version}-%{release}
PREFIX=%{buildroot} make install PREFIX=%{buildroot} make install
PREFIX=%{buildroot} make MANIFEST PREFIX=%{buildroot} make MANIFEST
cp MANIFEST /tmp/ cp MANIFEST /tmp/
%files -f /tmp/MANIFEST %files -f /tmp/MANIFEST