From 2ae0de42922185fd1b23751c58d8a1ff671f52be Mon Sep 17 00:00:00 2001 From: John Stebbins Date: Tue, 25 Aug 2015 09:48:14 -0700 Subject: build: use git version info instead of svn Migrate from svn to git. Since our build system automatically generates version info from the svn repo, this needs to change when we move the repo to git. --- scripts/repo-info.sh | 67 +++++++++++++++++++++++++++++++++++++++ scripts/tag-release.sh | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100755 scripts/repo-info.sh create mode 100755 scripts/tag-release.sh (limited to 'scripts') diff --git a/scripts/repo-info.sh b/scripts/repo-info.sh new file mode 100755 index 000000000..72d974d04 --- /dev/null +++ b/scripts/repo-info.sh @@ -0,0 +1,67 @@ +#! /bin/bash +# +# Retrieves git repository info for directory ${1} using command ${2} + +# Args +REPO_DIR='.' +if [[ ${1} ]]; then + REPO_DIR=${1} +fi +GIT_EXE='git' +if [[ ${2} ]]; then + GIT_EXE=${2} +fi + +# Switch to working directory +if ! cd ${REPO_DIR} 2>/dev/null; then + echo "Invalid directory ${REPO_DIR}." 1>&2 + exit 1 +fi + +# Check whether we have git +if ! hash ${GIT_EXE} 2>/dev/null; then + echo "Command '${GIT_EXE}' not found." 1>&2 + exit 1 +fi + +# Check if there is a valid git repo here +HASH=$(${GIT_EXE} rev-parse HEAD) +ERR=$? +if [[ ${ERR} -ne 0 ]]; then + echo "Not a valid repository." 1>&2 + exit ${ERR} +elif [[ -z ${HASH} ]]; then + echo "Not a valid repository." 1>&2 + exit 1 +fi + +# Retrieve info +URL=$(${GIT_EXE} config remote.origin.url) +TAG=$(${GIT_EXE} describe --abbrev=0) +if [[ ${TAG} ]]; then + REV=$(${GIT_EXE} rev-list ${TAG}.. --count) +else + TAG=$(${GIT_EXE} describe $(${GIT_EXE} rev-list --tags --max-count=1)) + if [[ ${TAG} ]]; then + REV=$(${GIT_EXE} rev-list $(${GIT_EXE} merge-base 0.10.2 HEAD).. --count) + else + REV=$(${GIT_EXE} rev-list HEAD --count) + fi +fi +BRANCH=$(${GIT_EXE} symbolic-ref -q --short HEAD) +REMOTE="${URL}" +UPSTREAM=$(${GIT_EXE} config branch.${BRANCH}.remote) +if [[ ${UPSTREAM} ]]; then + REMOTE="${UPSTREAM}" +fi +DATE=$(${GIT_EXE} log -1 --format="format:%ai") + +# Output +# Only write tag and rev if they exist. A fresh clone currently has no tags. +echo "URL=${URL}" +echo "HASH=${HASH}" +if [[ ${TAG} ]]; then echo "TAG=${TAG}"; fi +if [[ ${REV} ]]; then echo "REV=${REV}"; fi +echo "BRANCH=${BRANCH}" +echo "REMOTE=${REMOTE}" +echo "DATE=${DATE}" diff --git a/scripts/tag-release.sh b/scripts/tag-release.sh new file mode 100755 index 000000000..64f98103e --- /dev/null +++ b/scripts/tag-release.sh @@ -0,0 +1,86 @@ +#! /bin/bash +# +# Usage: tag-release.sh [] +# +# Creates a new branch and tag for the release +# Optionally, the release can be based off a specific git commit. +# + +TAG=${1} +COMMIT=${2} + +if [ "x${TAG}" == "x" ]; then + echo "Missing release tag (e.g. 0.10.0)" +fi + +if [ "x${COMMIT}" == "x" ]; then + echo "Creating release tag ${TAG} and branch ${TAG}-dev from HEAD, proceed?" +else + echo "Creating release tag ${TAG} and branch ${TAG}-dev from ${COMMIT}, proceed?" +fi +read proceed +if [[ ( "x${proceed}" != "xy" ) && ( "x${proceed}" != "xY" ) ]] ; then + echo "Aborting..." + exit 0 +fi + +if [ "x${COMMIT}" != "x" ]; then + # create release branch from specific commit + git checkout "${COMMIT}" -b "${TAG}-dev" + ERR=$? +else + # create release branch from head of current branch + git checkout -b "${TAG}-dev" + ERR=$? +fi +if [ ${ERR} -ne 0 ]; then + echo "Failed to create branch ${TAG}-dev" + exit ${ERR} +fi + +# creat tag +git tag -a "${TAG}" -m "Release ${TAG}" HEAD +ERR=$? +if [ ${ERR} -ne 0 ]; then + echo "Failed to create tag ${TAG}" + # cleanup... remove the branch that was created + git branch -d "${TAG}-dev" + exit ${ERR} +fi + +# checkout tag in preparation for building release +# this should put you in a "detached HEAD" state +git checkout "${TAG}" +ERR=$? +if [ ${ERR} -ne 0 ]; then + echo "Failed to checkout tag ${TAG}" + # cleanup... remove the branch that was created + git branch -d "${TAG}-dev" + exit ${ERR} +fi + +remote=$(git config remote.origin.url) +echo +echo "Do you wish to push this release branch and tag to $remote? (y/N)" +echo "You may want to do this manually after creating and verifying release." +echo "e.g." +echo " git push -u origin ${TAG}-dev" +echo " git push origin ${TAG}" +read proceed +if [[ ( "x${proceed}" == "xy" ) || ( "x${proceed}" == "xY" ) ]] ; then + git push -u origin "${TAG}-dev" + ERR=$? + if [ ${ERR} -ne 0 ]; then + echo "Failed to push branch ${TAG}-dev to remote" + exit ${ERR} + fi + git push origin "${TAG}" + ERR=$? + if [ ${ERR} -ne 0 ]; then + echo "Failed to push tag ${TAG}-dev to remote" + exit ${ERR} + fi +else + echo "Branch and tag are local, changes not pushed to remote!" +fi + -- cgit v1.2.3