Fix #3: ensure gitversion produces reliable versioning info across all branches
This commit is contained in:
42
LICENSE.txt
42
LICENSE.txt
@@ -1,21 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013 Andrew Kesterson <andrew@aklabs.net>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
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
|
||||
THE SOFTWARE.
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013 Andrew Kesterson <andrew@aklabs.net>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
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
|
||||
THE SOFTWARE.
|
||||
|
||||
190
Makefile
190
Makefile
@@ -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)
|
||||
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
|
||||
SPECFILE=versioners.spec
|
||||
|
||||
ifndef RHEL_VERSION
|
||||
RHEL_VERSION=5
|
||||
endif
|
||||
ifeq ($(RHEL_VERSION),5)
|
||||
MOCKFLAGS=--define "_source_filedigest_algorithm md5" --define "_binary_filedigest_algorithm md5"
|
||||
endif
|
||||
ifndef PREFIX
|
||||
PREFIX=''
|
||||
endif
|
||||
|
||||
RHEL_RELEASE:=$(RELEASE).el$(RHEL_VERSION)
|
||||
SRPM=versioners-$(VERSION)-$(RHEL_RELEASE).src.rpm
|
||||
RPM=versioners-$(VERSION)-$(RHEL_RELEASE).noarch.rpm
|
||||
RHEL_DISTFILE=./dist/versioners-$(VERSION)-$(RHEL_RELEASE).tar.gz
|
||||
|
||||
DISTFILE_DEPS=$(shell find . -type f | grep -Ev '\.git|\./dist/|$(DISTFILE)')
|
||||
|
||||
all: ./dist/$(RPM)
|
||||
|
||||
# --- PHONY targets
|
||||
|
||||
.PHONY: clean srpm rpm gitclean dist
|
||||
clean:
|
||||
rm -f $(DISTFILE) $(RHEL_DISTFILE)
|
||||
rm -fr dist/versioners-$(VERSION)-$(RELEASE)*
|
||||
|
||||
version.sh:
|
||||
gitversion.sh > version.sh
|
||||
|
||||
dist: $(DISTFILE)
|
||||
|
||||
srpm: ./dist/$(SRPM)
|
||||
|
||||
rpm: ./dist/$(RPM) ./dist/$(SRPM)
|
||||
|
||||
gitclean:
|
||||
git clean -df
|
||||
|
||||
# --- End phony targets
|
||||
|
||||
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 and no version.sh, you're boned"; exit 1; fi ; \
|
||||
if [ -d .git ] ; then \
|
||||
bash ./gitversion.sh > tmpversion.sh && \
|
||||
VERSIONSHA=$$(openssl sha1 version.sh | cut -d = -f 2) ; \
|
||||
TMPVERSIONSHA=$$(openssl sha1 tmpversion.sh | cut -d = -f 2) ; \
|
||||
if [ ! -e version.sh ] || [ "$$VERSIONSHA" != "$$TMPVERSIONSHA" ]; then \
|
||||
mv tmpversion.sh version.sh; \
|
||||
fi; \
|
||||
fi
|
||||
|
||||
$(DISTFILE): version.sh
|
||||
mkdir -p dist/
|
||||
mkdir dist/versioners-$(VERSION)-$(RELEASE) || rm -fr dist/versioners-$(VERSION)-$(RELEASE)
|
||||
rsync -aWH . --exclude=.git --exclude=dist ./dist/versioners-$(VERSION)-$(RELEASE)/
|
||||
cd dist && tar -czvf ../$@ versioners-$(VERSION)-$(RELEASE)
|
||||
|
||||
$(RHEL_DISTFILE): $(DISTFILE)
|
||||
cd dist && \
|
||||
cp -R versioners-$(VERSION)-$(RELEASE) versioners-$(VERSION)-$(RHEL_RELEASE) && \
|
||||
tar -czvf ../$@ versioners-$(VERSION)-$(RHEL_RELEASE)
|
||||
|
||||
./dist/$(SRPM): $(RHEL_DISTFILE)
|
||||
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)"
|
||||
|
||||
./dist/$(RPM): ./dist/$(SRPM)
|
||||
rm -fr ./dist/$(RPM)
|
||||
/usr/bin/mock --verbose -r epel-$(RHEL_VERSION)-noarch ./dist/$(SRPM) --resultdir ./dist/ --define "version $(VERSION)" --define "release $(RHEL_RELEASE)"
|
||||
|
||||
uninstall:
|
||||
rm -f $(PREFIX)/usr/bin/taggit.sh
|
||||
rm -f $(PREFIX)/usr/bin/taghg.sh
|
||||
rm -f $(PREFIX)/usr/bin/gitversion.sh
|
||||
rm -f $(PREFIX)/usr/bin/hgversion.sh
|
||||
|
||||
|
||||
install:
|
||||
mkdir -p $(PREFIX)/usr/bin
|
||||
install ./gitversion.sh $(PREFIX)/usr/bin/gitversion.sh
|
||||
install ./hgversion.sh $(PREFIX)/usr/bin/hgversion.sh
|
||||
install ./taggit.sh $(PREFIX)/usr/bin/taggit.sh
|
||||
install ./taghg.sh $(PREFIX)/usr/bin/taghg.sh
|
||||
|
||||
MANIFEST:
|
||||
echo /usr/bin/gitversion.sh > MANIFEST
|
||||
echo /usr/bin/hgversion.sh >> MANIFEST
|
||||
echo /usr/bin/taggit.sh >> MANIFEST
|
||||
echo /usr/bin/taghg.sh >> MANIFEST
|
||||
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)
|
||||
DISTFILE=./dist/versioners-$(VERSION)-$(RELEASE).tar.gz
|
||||
SPECFILE=versioners.spec
|
||||
|
||||
ifndef RHEL_VERSION
|
||||
RHEL_VERSION=5
|
||||
endif
|
||||
ifeq ($(RHEL_VERSION),5)
|
||||
MOCKFLAGS=--define "_source_filedigest_algorithm md5" --define "_binary_filedigest_algorithm md5"
|
||||
endif
|
||||
ifndef PREFIX
|
||||
PREFIX=''
|
||||
endif
|
||||
|
||||
RHEL_RELEASE:=$(RELEASE).el$(RHEL_VERSION)
|
||||
SRPM=versioners-$(VERSION)-$(RHEL_RELEASE).src.rpm
|
||||
RPM=versioners-$(VERSION)-$(RHEL_RELEASE).noarch.rpm
|
||||
RHEL_DISTFILE=./dist/versioners-$(VERSION)-$(RHEL_RELEASE).tar.gz
|
||||
|
||||
DISTFILE_DEPS=$(shell find . -type f | grep -Ev '\.git|\./dist/|$(DISTFILE)')
|
||||
|
||||
all: ./dist/$(RPM)
|
||||
|
||||
# --- PHONY targets
|
||||
|
||||
.PHONY: clean srpm rpm gitclean dist
|
||||
clean:
|
||||
rm -f $(DISTFILE) $(RHEL_DISTFILE)
|
||||
rm -fr dist/versioners-$(VERSION)-$(RELEASE)*
|
||||
|
||||
version.sh:
|
||||
gitversion.sh > version.sh
|
||||
|
||||
dist: $(DISTFILE)
|
||||
|
||||
srpm: ./dist/$(SRPM)
|
||||
|
||||
rpm: ./dist/$(RPM) ./dist/$(SRPM)
|
||||
|
||||
gitclean:
|
||||
git clean -df
|
||||
|
||||
# --- End phony targets
|
||||
|
||||
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 and no version.sh, you're boned"; exit 1; fi ; \
|
||||
if [ -d .git ] ; then \
|
||||
bash ./gitversion.sh > tmpversion.sh && \
|
||||
VERSIONSHA=$$(openssl sha1 version.sh | cut -d = -f 2) ; \
|
||||
TMPVERSIONSHA=$$(openssl sha1 tmpversion.sh | cut -d = -f 2) ; \
|
||||
if [ ! -e version.sh ] || [ "$$VERSIONSHA" != "$$TMPVERSIONSHA" ]; then \
|
||||
mv tmpversion.sh version.sh; \
|
||||
fi; \
|
||||
fi
|
||||
|
||||
$(DISTFILE): version.sh
|
||||
mkdir -p dist/
|
||||
mkdir dist/versioners-$(VERSION)-$(RELEASE) || rm -fr dist/versioners-$(VERSION)-$(RELEASE)
|
||||
rsync -aWH . --exclude=.git --exclude=dist ./dist/versioners-$(VERSION)-$(RELEASE)/
|
||||
cd dist && tar -czvf ../$@ versioners-$(VERSION)-$(RELEASE)
|
||||
|
||||
$(RHEL_DISTFILE): $(DISTFILE)
|
||||
cd dist && \
|
||||
cp -R versioners-$(VERSION)-$(RELEASE) versioners-$(VERSION)-$(RHEL_RELEASE) && \
|
||||
tar -czvf ../$@ versioners-$(VERSION)-$(RHEL_RELEASE)
|
||||
|
||||
./dist/$(SRPM): $(RHEL_DISTFILE)
|
||||
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)"
|
||||
|
||||
./dist/$(RPM): ./dist/$(SRPM)
|
||||
rm -fr ./dist/$(RPM)
|
||||
/usr/bin/mock --verbose -r epel-$(RHEL_VERSION)-noarch ./dist/$(SRPM) --resultdir ./dist/ --define "version $(VERSION)" --define "release $(RHEL_RELEASE)"
|
||||
|
||||
uninstall:
|
||||
rm -f $(PREFIX)/usr/bin/taggit.sh
|
||||
rm -f $(PREFIX)/usr/bin/taghg.sh
|
||||
rm -f $(PREFIX)/usr/bin/gitversion.sh
|
||||
rm -f $(PREFIX)/usr/bin/hgversion.sh
|
||||
|
||||
|
||||
install:
|
||||
mkdir -p $(PREFIX)/usr/bin
|
||||
install ./gitversion.sh $(PREFIX)/usr/bin/gitversion.sh
|
||||
install ./hgversion.sh $(PREFIX)/usr/bin/hgversion.sh
|
||||
install ./taggit.sh $(PREFIX)/usr/bin/taggit.sh
|
||||
install ./taghg.sh $(PREFIX)/usr/bin/taghg.sh
|
||||
|
||||
MANIFEST:
|
||||
echo /usr/bin/gitversion.sh > MANIFEST
|
||||
echo /usr/bin/hgversion.sh >> MANIFEST
|
||||
echo /usr/bin/taggit.sh >> MANIFEST
|
||||
echo /usr/bin/taghg.sh >> MANIFEST
|
||||
|
||||
156
gitversion.sh
156
gitversion.sh
@@ -1,78 +1,78 @@
|
||||
#!/bin/bash
|
||||
|
||||
LOGSPEC='%ci %an <%aE>%n%n %s%n [%h]%d%n'
|
||||
VERSIONERS_SEPARATOR=${VERSIONERS_SEPARATOR:-,}
|
||||
|
||||
BRANCH=$2
|
||||
if [ "${BRANCH}" == "" ]; then
|
||||
BRANCH=$(git branch | grep '^\*\s*.*' | cut -d ' ' -f 2-)
|
||||
fi
|
||||
|
||||
REBUILDING=0
|
||||
SHA1=$(git rev-parse HEAD)
|
||||
TAG=$(git describe --tags --abbrev=0 `git rev-list --tags --max-count=1 HEAD` 2>/dev/null)
|
||||
BUILD=0
|
||||
TAGSHA=$(git rev-list $TAG | head -n 1)
|
||||
CHANGELOG="$(git log --format="format:$LOGSPEC" ${TAGSHA}..HEAD)"
|
||||
if [ "$TAG" == "" ]; then
|
||||
BUILD=0
|
||||
REBUILDING=1
|
||||
MAJOR=$BRANCH
|
||||
else
|
||||
MAJOR=$(echo $TAG | cut -d ${VERSIONERS_SEPARATOR} -f 2)
|
||||
BUILD=$(echo $TAG | cut -d ${VERSIONERS_SEPARATOR} -f 3)
|
||||
if [ "$TAGSHA" != "$SHA1" ]; then
|
||||
CHANGELOG="$(git log --format="format:$LOGSPEC" $TAGSHA..$SHA1)"
|
||||
BUILD=$(expr $BUILD + 1)
|
||||
REBUILDING=1
|
||||
else
|
||||
SHA1=$TAGSHA
|
||||
fi
|
||||
fi
|
||||
|
||||
OS_NAME=""
|
||||
OS_VERSION=""
|
||||
if [ "$OS_NAME" == "" ] && [ "$(uname)" == "Darwin" ]; then
|
||||
OS_NAME="osx"
|
||||
elif [ "$OS_NAME" == "" ] && [ -f /etc/redhat-release ]; then
|
||||
OS_NAME="el"
|
||||
elif [ "$OS_NAME" == "" ] && [ "$(uname | grep -i '^MINGW')" != "" ] || [ "$(uname | grep -i '^CYGWIN')" != "" ]; then
|
||||
OS_NAME="win"
|
||||
fi
|
||||
|
||||
if [ "$OS_VERSION" == "" ] && [ "$OS_NAME" == "el" ]; then
|
||||
OS_VERSION=$(cat /etc/redhat-release | grep -o "release [0-9]" | cut -d " " -f 2)
|
||||
RHEL_VERSION=$OS_VERSION
|
||||
elif [ "$OS_VERSION" == "" ] && [ "$OS_NAME" == "osx" ]; then
|
||||
OS_VERSION="$(sw_vers | grep 'ProductVersion:' | grep -o '[0-9]*\.[0-9]*\.[0-9]*')"
|
||||
elif [ "$OS_VERSION" == "" ] && [ "$OS_NAME" == "win" ]; then
|
||||
echo "OS_VERSION unsupported on Microsoft Windows." >&2
|
||||
fi
|
||||
|
||||
if [ "$ARCH" == "" ]; then
|
||||
if [ "$OS_NAME" == "osx" ]; then
|
||||
ARCH=$(uname -m)
|
||||
elif [ "$OS_NAME" != "win" ]; then
|
||||
ARCH=$(uname -i)
|
||||
elif [ "$OS_NAME" == "win" ]; then
|
||||
ARCH=$(uname -m)
|
||||
fi
|
||||
fi
|
||||
|
||||
SOURCE=$((git remote show origin 2>/dev/null | grep "Fetch URL" | cut -d : -f 2- | cut -d ' ' -f 2-) || echo '')
|
||||
|
||||
echo "TAG=\"${TAG}\""
|
||||
echo "BRANCH=\"${BRANCH}\""
|
||||
echo "MAJOR=\"${MAJOR}\""
|
||||
echo "BUILD=\"${BUILD}\""
|
||||
echo "SHA1=\"${SHA1}\""
|
||||
echo "OS_NAME=\"\${OS_NAME:-$OS_NAME}\""
|
||||
echo "OS_VERSION=\"\${OS_VERSION:-$OS_VERSION}\""
|
||||
echo "ARCH=\"\${ARCH:-$ARCH}\""
|
||||
echo "VERSION=\"${MAJOR}-${BUILD}\""
|
||||
echo "BUILDHOST=\"$(hostname)\""
|
||||
echo "BUILDUSER=\"$(whoami)\""
|
||||
echo "BUILDDIR=\"$(pwd)\""
|
||||
echo "SOURCE=\"${SOURCE}\""
|
||||
echo "REBUILDING=$REBUILDING"
|
||||
echo "CHANGELOG=\"$CHANGELOG\""
|
||||
#!/bin/bash
|
||||
|
||||
LOGSPEC='%ci %an <%aE>%n%n %s%n [%h]%d%n'
|
||||
VERSIONERS_SEPARATOR=${VERSIONERS_SEPARATOR:-,}
|
||||
|
||||
BRANCH=$2
|
||||
if [ "${BRANCH}" == "" ]; then
|
||||
BRANCH=$(git branch | grep '^\*\s*.*' | cut -d ' ' -f 2-)
|
||||
fi
|
||||
|
||||
REBUILDING=0
|
||||
SHA1=$(git rev-parse HEAD)
|
||||
TAG=$(git describe --tags --abbrev=0 2>/dev/null)
|
||||
BUILD=0
|
||||
TAGSHA=$(git rev-list $TAG | head -n 1)
|
||||
CHANGELOG="$(git log --format="format:$LOGSPEC" ${TAGSHA}..HEAD)"
|
||||
if [ "$TAG" == "" ]; then
|
||||
BUILD=0
|
||||
REBUILDING=1
|
||||
MAJOR=$BRANCH
|
||||
else
|
||||
MAJOR=$(echo $TAG | cut -d ${VERSIONERS_SEPARATOR} -f 2)
|
||||
BUILD=$(echo $TAG | cut -d ${VERSIONERS_SEPARATOR} -f 3)
|
||||
if [ "$TAGSHA" != "$SHA1" ]; then
|
||||
CHANGELOG="$(git log --format="format:$LOGSPEC" $TAGSHA..$SHA1)"
|
||||
BUILD=$(expr $BUILD + 1)
|
||||
REBUILDING=1
|
||||
else
|
||||
SHA1=$TAGSHA
|
||||
fi
|
||||
fi
|
||||
|
||||
OS_NAME=""
|
||||
OS_VERSION=""
|
||||
if [ "$OS_NAME" == "" ] && [ "$(uname)" == "Darwin" ]; then
|
||||
OS_NAME="osx"
|
||||
elif [ "$OS_NAME" == "" ] && [ -f /etc/redhat-release ]; then
|
||||
OS_NAME="el"
|
||||
elif [ "$OS_NAME" == "" ] && [ "$(uname | grep -i '^MINGW')" != "" ] || [ "$(uname | grep -i '^CYGWIN')" != "" ]; then
|
||||
OS_NAME="win"
|
||||
fi
|
||||
|
||||
if [ "$OS_VERSION" == "" ] && [ "$OS_NAME" == "el" ]; then
|
||||
OS_VERSION=$(cat /etc/redhat-release | grep -o "release [0-9]" | cut -d " " -f 2)
|
||||
RHEL_VERSION=$OS_VERSION
|
||||
elif [ "$OS_VERSION" == "" ] && [ "$OS_NAME" == "osx" ]; then
|
||||
OS_VERSION="$(sw_vers | grep 'ProductVersion:' | grep -o '[0-9]*\.[0-9]*\.[0-9]*')"
|
||||
elif [ "$OS_VERSION" == "" ] && [ "$OS_NAME" == "win" ]; then
|
||||
echo "OS_VERSION unsupported on Microsoft Windows." >&2
|
||||
fi
|
||||
|
||||
if [ "$ARCH" == "" ]; then
|
||||
if [ "$OS_NAME" == "osx" ]; then
|
||||
ARCH=$(uname -m)
|
||||
elif [ "$OS_NAME" != "win" ]; then
|
||||
ARCH=$(uname -i)
|
||||
elif [ "$OS_NAME" == "win" ]; then
|
||||
ARCH=$(uname -m)
|
||||
fi
|
||||
fi
|
||||
|
||||
SOURCE=$((git remote show origin 2>/dev/null | grep "Fetch URL" | cut -d : -f 2- | cut -d ' ' -f 2-) || echo '')
|
||||
|
||||
echo "TAG=\"${TAG}\""
|
||||
echo "BRANCH=\"${BRANCH}\""
|
||||
echo "MAJOR=\"${MAJOR}\""
|
||||
echo "BUILD=\"${BUILD}\""
|
||||
echo "SHA1=\"${SHA1}\""
|
||||
echo "OS_NAME=\"\${OS_NAME:-$OS_NAME}\""
|
||||
echo "OS_VERSION=\"\${OS_VERSION:-$OS_VERSION}\""
|
||||
echo "ARCH=\"\${ARCH:-$ARCH}\""
|
||||
echo "VERSION=\"${MAJOR}-${BUILD}\""
|
||||
echo "BUILDHOST=\"$(hostname)\""
|
||||
echo "BUILDUSER=\"$(whoami)\""
|
||||
echo "BUILDDIR=\"$(pwd)\""
|
||||
echo "SOURCE=\"${SOURCE}\""
|
||||
echo "REBUILDING=$REBUILDING"
|
||||
echo "CHANGELOG=\"$CHANGELOG\""
|
||||
|
||||
154
hgversion.sh
154
hgversion.sh
@@ -1,77 +1,77 @@
|
||||
#!/bin/bash
|
||||
|
||||
BRANCH=$2
|
||||
if [ "${BRANCH}" == "" ]; then
|
||||
BRANCH=$(hg identify -b)
|
||||
fi
|
||||
|
||||
REBUILDING=0
|
||||
SHA1=$(hg identify -i | grep -Eo "[a-zA-Z0-9]+")
|
||||
TAG=$(hg parents --template '{latesttag}')
|
||||
TAGSHA=$(hg identify -r $TAG | cut -d ' ' -f 1)
|
||||
BUILD=0
|
||||
CHANGELOG="$(hg log --branch $BRANCH -X .hgtags --style=changelog -r ${TAG}:${SHA1})"
|
||||
if [ "$TAG" == "" ]; then
|
||||
BUILD=0
|
||||
REBUILDING=1
|
||||
MAJOR=$BRANCH
|
||||
else
|
||||
MAJOR=$(echo $TAG | cut -d \| -f 2)
|
||||
BUILD=$(echo $TAG | cut -d \| -f 3)
|
||||
SHORTTAGSHA=${TAGSHA:0:12}
|
||||
hg log -r tip | grep "Added tag build|${BRANCH}|${BUILD} for changeset ${SHORTTAGSHA}" >/dev/null
|
||||
if [ $? -ne 0 ] && [ "$TAGSHA" != "$SHA1" ]; then
|
||||
CHANGELOG="$(hg log --branch $BRANCH -X .hgtags --style=changelog -r ${SHORTTAGSHA}:${SHA1})"
|
||||
BUILD=$(expr $BUILD + 1)
|
||||
REBUILDING=1
|
||||
else
|
||||
SHA1=$TAGSHA
|
||||
fi
|
||||
fi
|
||||
|
||||
OS_NAME=""
|
||||
OS_VERSION=""
|
||||
if [ "$OS_NAME" == "" ] && [ "$(uname)" == "Darwin" ]; then
|
||||
OS_NAME="osx"
|
||||
elif [ "$OS_NAME" == "" ] && [ -f /etc/redhat-release ]; then
|
||||
OS_NAME="el"
|
||||
elif [ "$OS_NAME" == "" ] && [ "$(uname | grep -i '^MINGW')" != "" ] || [ "$(uname | grep -i '^CYGWIN')" != "" ]; then
|
||||
OS_NAME="win"
|
||||
fi
|
||||
|
||||
if [ "$OS_VERSION" == "" ] && [ "$OS_NAME" == "el" ]; then
|
||||
OS_VERSION=$(cat /etc/redhat-release | grep -o "release [0-9]" | cut -d " " -f 2)
|
||||
RHEL_VERSION=$OS_VERSION
|
||||
elif [ "$OS_VERSION" == "" ] && [ "$OS_NAME" == "osx" ]; then
|
||||
OS_VERSION="$(sw_vers | grep 'ProductVersion:' | grep -o '[0-9]*\.[0-9]*\.[0-9]*')"
|
||||
elif [ "$OS_VERSION" == "" ] && [ "$OS_NAME" == "win" ]; then
|
||||
echo "OS_VERSION unsupported on Microsoft Windows." >&2
|
||||
fi
|
||||
|
||||
if [ "$ARCH" == "" ]; then
|
||||
if [ "$OS_NAME" == "osx" ]; then
|
||||
ARCH=$(uname -m)
|
||||
elif [ "$OS_NAME" != "win" ]; then
|
||||
ARCH=$(uname -i)
|
||||
elif [ "$OS_NAME" == "win" ]; then
|
||||
ARCH=$(uname -m)
|
||||
fi
|
||||
fi
|
||||
|
||||
SOURCE=$((cat .hg/hgrc 2>/dev/null | grep default | cut -d = -f 2 | sed s/"^ *"//g) || echo '')
|
||||
|
||||
echo "TAG=\"${TAG}\""
|
||||
echo "BRANCH=\"${BRANCH}\""
|
||||
echo "MAJOR=\"${MAJOR}\""
|
||||
echo "BUILD=\"${BUILD}\""
|
||||
echo "SHA1=\"${SHA1}\""
|
||||
echo "OS_NAME=\"\${OS_NAME:-$OS_NAME}\""
|
||||
echo "OS_VERSION=\"\${OS_VERSION:-$OS_VERSION}\""
|
||||
echo "ARCH=\"\${ARCH:-$ARCH}\""
|
||||
echo "VERSION=\"${MAJOR}-${BUILD}\""
|
||||
echo "BUILDHOST=\"$(hostname)\""
|
||||
echo "BUILDUSER=\"$(whoami)\""
|
||||
echo "BUILDDIR=\"$(pwd)\""
|
||||
echo "SOURCE=\"${SOURCE}\""
|
||||
echo "REBUILDING=$REBUILDING"
|
||||
echo "CHANGELOG=\"$CHANGELOG\""
|
||||
#!/bin/bash
|
||||
|
||||
BRANCH=$2
|
||||
if [ "${BRANCH}" == "" ]; then
|
||||
BRANCH=$(hg identify -b)
|
||||
fi
|
||||
|
||||
REBUILDING=0
|
||||
SHA1=$(hg identify -i | grep -Eo "[a-zA-Z0-9]+")
|
||||
TAG=$(hg parents --template '{latesttag}')
|
||||
TAGSHA=$(hg identify -r $TAG | cut -d ' ' -f 1)
|
||||
BUILD=0
|
||||
CHANGELOG="$(hg log --branch $BRANCH -X .hgtags --style=changelog -r ${TAG}:${SHA1})"
|
||||
if [ "$TAG" == "" ]; then
|
||||
BUILD=0
|
||||
REBUILDING=1
|
||||
MAJOR=$BRANCH
|
||||
else
|
||||
MAJOR=$(echo $TAG | cut -d \| -f 2)
|
||||
BUILD=$(echo $TAG | cut -d \| -f 3)
|
||||
SHORTTAGSHA=${TAGSHA:0:12}
|
||||
hg log -r tip | grep "Added tag build|${BRANCH}|${BUILD} for changeset ${SHORTTAGSHA}" >/dev/null
|
||||
if [ $? -ne 0 ] && [ "$TAGSHA" != "$SHA1" ]; then
|
||||
CHANGELOG="$(hg log --branch $BRANCH -X .hgtags --style=changelog -r ${SHORTTAGSHA}:${SHA1})"
|
||||
BUILD=$(expr $BUILD + 1)
|
||||
REBUILDING=1
|
||||
else
|
||||
SHA1=$TAGSHA
|
||||
fi
|
||||
fi
|
||||
|
||||
OS_NAME=""
|
||||
OS_VERSION=""
|
||||
if [ "$OS_NAME" == "" ] && [ "$(uname)" == "Darwin" ]; then
|
||||
OS_NAME="osx"
|
||||
elif [ "$OS_NAME" == "" ] && [ -f /etc/redhat-release ]; then
|
||||
OS_NAME="el"
|
||||
elif [ "$OS_NAME" == "" ] && [ "$(uname | grep -i '^MINGW')" != "" ] || [ "$(uname | grep -i '^CYGWIN')" != "" ]; then
|
||||
OS_NAME="win"
|
||||
fi
|
||||
|
||||
if [ "$OS_VERSION" == "" ] && [ "$OS_NAME" == "el" ]; then
|
||||
OS_VERSION=$(cat /etc/redhat-release | grep -o "release [0-9]" | cut -d " " -f 2)
|
||||
RHEL_VERSION=$OS_VERSION
|
||||
elif [ "$OS_VERSION" == "" ] && [ "$OS_NAME" == "osx" ]; then
|
||||
OS_VERSION="$(sw_vers | grep 'ProductVersion:' | grep -o '[0-9]*\.[0-9]*\.[0-9]*')"
|
||||
elif [ "$OS_VERSION" == "" ] && [ "$OS_NAME" == "win" ]; then
|
||||
echo "OS_VERSION unsupported on Microsoft Windows." >&2
|
||||
fi
|
||||
|
||||
if [ "$ARCH" == "" ]; then
|
||||
if [ "$OS_NAME" == "osx" ]; then
|
||||
ARCH=$(uname -m)
|
||||
elif [ "$OS_NAME" != "win" ]; then
|
||||
ARCH=$(uname -i)
|
||||
elif [ "$OS_NAME" == "win" ]; then
|
||||
ARCH=$(uname -m)
|
||||
fi
|
||||
fi
|
||||
|
||||
SOURCE=$((cat .hg/hgrc 2>/dev/null | grep default | cut -d = -f 2 | sed s/"^ *"//g) || echo '')
|
||||
|
||||
echo "TAG=\"${TAG}\""
|
||||
echo "BRANCH=\"${BRANCH}\""
|
||||
echo "MAJOR=\"${MAJOR}\""
|
||||
echo "BUILD=\"${BUILD}\""
|
||||
echo "SHA1=\"${SHA1}\""
|
||||
echo "OS_NAME=\"\${OS_NAME:-$OS_NAME}\""
|
||||
echo "OS_VERSION=\"\${OS_VERSION:-$OS_VERSION}\""
|
||||
echo "ARCH=\"\${ARCH:-$ARCH}\""
|
||||
echo "VERSION=\"${MAJOR}-${BUILD}\""
|
||||
echo "BUILDHOST=\"$(hostname)\""
|
||||
echo "BUILDUSER=\"$(whoami)\""
|
||||
echo "BUILDDIR=\"$(pwd)\""
|
||||
echo "SOURCE=\"${SOURCE}\""
|
||||
echo "REBUILDING=$REBUILDING"
|
||||
echo "CHANGELOG=\"$CHANGELOG\""
|
||||
|
||||
68
taggit.sh
68
taggit.sh
@@ -1,34 +1,34 @@
|
||||
#!/bin/bash
|
||||
|
||||
SEP=${VERSIONERS_SEPARATOR:-,}
|
||||
VERSIONERS_TAGBASE=${VERSIONERS_TAGBASE:-build}
|
||||
|
||||
if [ "$MAKETAG" == "false" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ ! -f version.sh ]; then
|
||||
$(dirname $BASH_SOURCE)/gitversion.sh > version.sh
|
||||
fi
|
||||
|
||||
. ~/.buildtoolsrc || echo
|
||||
. version.sh
|
||||
|
||||
WHOLETAG="${VERSIONERS_TAGBASE}${SEP}${MAJOR}${SEP}${BUILD}"
|
||||
|
||||
git fetch --tags
|
||||
|
||||
TAGSHA1=$(git rev-list $TAG | head -n 1)
|
||||
if [ $REBUILDING -eq 0 ]; then
|
||||
echo "This is a rebuild of a previous tag, not tagging or pushing" >&2
|
||||
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
|
||||
exit 1
|
||||
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."
|
||||
else
|
||||
git tag -f -a "${WHOLETAG}" -m "Tagging for ${MAJOR}-${BUILD}" $SHA1
|
||||
if [ "$PUSHTAG" != "false" ]; then
|
||||
git push --tags
|
||||
fi
|
||||
fi
|
||||
#!/bin/bash
|
||||
|
||||
SEP=${VERSIONERS_SEPARATOR:-,}
|
||||
VERSIONERS_TAGBASE=${VERSIONERS_TAGBASE:-build}
|
||||
|
||||
if [ "$MAKETAG" == "false" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ ! -f version.sh ]; then
|
||||
$(dirname $BASH_SOURCE)/gitversion.sh > version.sh
|
||||
fi
|
||||
|
||||
. ~/.buildtoolsrc || echo
|
||||
. version.sh
|
||||
|
||||
WHOLETAG="${VERSIONERS_TAGBASE}${SEP}${MAJOR}${SEP}${BUILD}"
|
||||
|
||||
git fetch --tags
|
||||
|
||||
TAGSHA1=$(git rev-list $TAG | head -n 1)
|
||||
if [ $REBUILDING -eq 0 ]; then
|
||||
echo "This is a rebuild of a previous tag, not tagging or pushing" >&2
|
||||
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
|
||||
exit 1
|
||||
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."
|
||||
else
|
||||
git tag -f -a "${WHOLETAG}" -m "Tagging for ${MAJOR}-${BUILD}" $SHA1
|
||||
if [ "$PUSHTAG" != "false" ]; then
|
||||
git push --tags
|
||||
fi
|
||||
fi
|
||||
|
||||
60
taghg.sh
60
taghg.sh
@@ -1,30 +1,30 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ "$MAKETAG" == "false" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ ! -f version ]; then
|
||||
${dirname $BASH_SOURCE)/genversion > version
|
||||
fi
|
||||
|
||||
. ~/.buildtoolsrc
|
||||
. version
|
||||
hg pull -u --branch $(hg branch)
|
||||
|
||||
TAGSHA1=$(cat .hgtags | grep "build,${MAJOR},${BUILD}" | cut -d " " -f 1)
|
||||
echo "$TAGSHA1" | grep "^$SHA1" >/dev/null 2>&1
|
||||
SHORTSHAMATCH=$?
|
||||
if [ $REBUILDING -eq 0 ]; then
|
||||
echo "This is a rebuild of a previous tag, not tagging or pushing" >&2
|
||||
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
|
||||
exit 1
|
||||
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."
|
||||
else
|
||||
hg tag -f -r ${SHA1} "build|${MAJOR}|${BUILD}"
|
||||
if [ "$PUSHTAG" != "false" ]; then
|
||||
hg push
|
||||
fi
|
||||
fi
|
||||
#!/bin/bash
|
||||
|
||||
if [ "$MAKETAG" == "false" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ ! -f version ]; then
|
||||
${dirname $BASH_SOURCE)/genversion > version
|
||||
fi
|
||||
|
||||
. ~/.buildtoolsrc
|
||||
. version
|
||||
hg pull -u --branch $(hg branch)
|
||||
|
||||
TAGSHA1=$(cat .hgtags | grep "build,${MAJOR},${BUILD}" | cut -d " " -f 1)
|
||||
echo "$TAGSHA1" | grep "^$SHA1" >/dev/null 2>&1
|
||||
SHORTSHAMATCH=$?
|
||||
if [ $REBUILDING -eq 0 ]; then
|
||||
echo "This is a rebuild of a previous tag, not tagging or pushing" >&2
|
||||
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
|
||||
exit 1
|
||||
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."
|
||||
else
|
||||
hg tag -f -r ${SHA1} "build|${MAJOR}|${BUILD}"
|
||||
if [ "$PUSHTAG" != "false" ]; then
|
||||
hg push
|
||||
fi
|
||||
fi
|
||||
|
||||
61
tests/test_gitversion.sh
Normal file
61
tests/test_gitversion.sh
Normal 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"
|
||||
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
function shunittest_shutup
|
||||
{
|
||||
return 0
|
||||
}
|
||||
39
tests/test_taggit.sh
Normal file
39
tests/test_taggit.sh
Normal 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"
|
||||
}
|
||||
@@ -1,27 +1,27 @@
|
||||
%define __os_install_post %{nil}
|
||||
Summary: Automatic Versioning Tools
|
||||
Name: versioners
|
||||
Version: %{version}
|
||||
Release: %{release}
|
||||
License: Andrew Kesterson
|
||||
Vendor: Andrew Kesterson
|
||||
Packager: Andrew Kesterson <andrew@aklabs.net>
|
||||
Group: Development Tools
|
||||
Provides: %{name}
|
||||
BuildArch: noarch
|
||||
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}
|
||||
Source: %{name}-%{version}-%{release}.tar.gz
|
||||
|
||||
Requires: bash
|
||||
|
||||
%description
|
||||
|
||||
%install
|
||||
mkdir -p %{buildroot}/usr/src
|
||||
tar -zxvf %{_sourcedir}/%{name}-%{version}-%{release}.tar.gz
|
||||
cd %{name}-%{version}-%{release}
|
||||
PREFIX=%{buildroot} make install
|
||||
PREFIX=%{buildroot} make MANIFEST
|
||||
cp MANIFEST /tmp/
|
||||
|
||||
%files -f /tmp/MANIFEST
|
||||
%define __os_install_post %{nil}
|
||||
Summary: Automatic Versioning Tools
|
||||
Name: versioners
|
||||
Version: %{version}
|
||||
Release: %{release}
|
||||
License: Andrew Kesterson
|
||||
Vendor: Andrew Kesterson
|
||||
Packager: Andrew Kesterson <andrew@aklabs.net>
|
||||
Group: Development Tools
|
||||
Provides: %{name}
|
||||
BuildArch: noarch
|
||||
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}
|
||||
Source: %{name}-%{version}-%{release}.tar.gz
|
||||
|
||||
Requires: bash
|
||||
|
||||
%description
|
||||
|
||||
%install
|
||||
mkdir -p %{buildroot}/usr/src
|
||||
tar -zxvf %{_sourcedir}/%{name}-%{version}-%{release}.tar.gz
|
||||
cd %{name}-%{version}-%{release}
|
||||
PREFIX=%{buildroot} make install
|
||||
PREFIX=%{buildroot} make MANIFEST
|
||||
cp MANIFEST /tmp/
|
||||
|
||||
%files -f /tmp/MANIFEST
|
||||
|
||||
Reference in New Issue
Block a user