Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update version script #369

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
79 changes: 67 additions & 12 deletions version
Original file line number Diff line number Diff line change
@@ -1,24 +1,79 @@
#!/bin/bash

# Version script for Metronome.
# Version script for USI
#
# Change MINOR to x+1 and BRANCH_POINT to commit hash of common ancestor of master and releases/0.x
# after a releases/0.x was cut
MAJOR=0
MINOR=6
BRANCH_POINT=a03c135305c914e19b5706d5e7f8655f6b97fd6e
REF=HEAD
CANON=origin/master

declare -a OTHERARGS
help() {
cat <<-EOF
Usage $0 [options]

--help This help
--ref The reference for which version to output Defaults to HEAD

Non-arg params

* commit - output just the formatted commit hash
* package - output the version with the commit hash, ie 1.9.34-a122edcb4

EOF
}

while ! [ -z "$1" ]; do
arg="$1"
shift
case "$arg" in
--help)
help
exit 0
;;
--ref)
REF="$1"
shift
;;
*)
OTHERARGS+=("$arg")
;;
esac
done

# Infer version
# Number of commits since branch point
COMMIT_NUMBER="$(git rev-list --count --first-parent $BRANCH_POINT..HEAD)"
COMMIT_HASH=$(git rev-parse --short HEAD)
IS_DIRECT_CHILD=$( git log $CANON..$BRANCH_POINT)

# Echo commit hash
if [ "$#" -eq 1 ] && [ "$1" == "commit" ]; then
echo "$COMMIT_HASH"
exit 0
REV=$(git rev-parse $REF)
MERGE_BASE=$(git merge-base $REF $CANON)
COMMIT_NUMBER="$(git rev-list --count --first-parent $BRANCH_POINT..$MERGE_BASE)"
COMMIT_HASH=${REV::7}

if [ "$MERGE_BASE" == "$REV" ]; then
SNAPSHOT_INFO=""
else
SNAPSHOT_INFO="-${COMMIT_HASH}-SNAPSHOT"
fi

# Echo verion
# E.g. 0.5.42
echo "$MAJOR.$MINOR.$COMMIT_NUMBER"

case ${OTHERARGS[0]} in
commit)
# Echo commit hash
echo "$COMMIT_HASH"
;;
"")
# Echo version
# E.g. 1.7.42
echo "$MAJOR.$MINOR.$COMMIT_NUMBER${SNAPSHOT_INFO}"
;;
*)
echo "ERROR: ${OTHERARGS[0]} is not a version format"
echo
help
exit 1
;;


esac