Skip to content
This repository has been archived by the owner on Oct 7, 2020. It is now read-only.

Commit

Permalink
Initial release script to bump git tag
Browse files Browse the repository at this point in the history
  • Loading branch information
jsks committed Nov 15, 2019
1 parent e81db8b commit f18a317
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 4 deletions.
13 changes: 9 additions & 4 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

set -e

if [ -n "$1" ]; then
printf "Attaching tag: %s\n" "$1"
tag=":$1"
fi

if which podman 2>&1 >/dev/null; then
podman build -t docker.io/jsks/conflict_onset .
podman push docker.io/jsks/conflict_onset
podman build -t "docker.io/jsks/conflict_onset$tag" .
podman push "docker.io/jsks/conflict_onset$tag"
else
docker build -t jsks/conflict_onset:latest .
docker push jsks/conflict_onset
docker build -t "jsks/conflict_onset$tag" .
docker push "jsks/conflict_onset$tag"
fi
95 changes: 95 additions & 0 deletions scripts/semver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/bin/sh

## Utility functions
usage() {
printf "Usage: ./$(basename $0) [-h] [-m <msg>] [-s <semver>]\n"
exit 127
}

help() {
cat <<EOF
$(usage)
Sets the project-wide version number. If not specified, default to
bumping the current patch version.
Options:
-h Useless help message
-m Tagging message
-s Specify version number
EOF

exit
}

confirm() {
printf "$*. Continue (y/n)? "
read ans

case $ans in
[Yy] | Yes | yes)
return 0;;
*)
return 1;;
esac
}

validate() {
if ! grep -E '^[0-9]+[.][0-9]+[.][0-9]+$' <<< "$1" >/dev/null; then
printf "Invalid semver: %s\n" "$1"
exit 127
fi

IFS=.
read major minor patch <<< "$tag"
read next_major next_minor next_patch <<< "$1"
IFS=""

if (( next_major < major )) ||
(( next_minor < minor )) ||
(( next_patch <= patch )); then
printf "Current version %s >= %s\n" "$tag" "$1"
exit 127
fi
}

## Main
if [ -n "$(git diff --name-only --staged)" ]; then
printf "Finish commit before updating version number\n"
exit 127
fi

if [ -n "$(git status -s)" ] && ! confirm "Uncommitted changes"; then
exit 127
fi

root=$(git rev-parse --show-toplevel)
tag=$(git describe --tags --abbrev=0 2>/dev/null | cut -c 2-)
: ${tag:="0.0.0"}

next_version="${tag%.*}.$(( ${tag##*.} + 1 ))"

while getopts 'hs:' opt; do
case $opt in
h)
help;;
m)
msg=$OPTARG;;
s)
validate $OPTARG
next_version=$OPTARG;;
*)
usage;;
esac
done

set -e
confirm "Bumping version to v$next_version"

sed -i "s/Version:.*/Version: $next_version/" $root/R/thesis.utils/DESCRIPTION
git add $root/R/thesis.utils/DESCRIPTION
git commit -m "Prepare release v$next_version"

git tag -a "v$next_version" -m $msg

sh $root/scripts/build.sh

0 comments on commit f18a317

Please sign in to comment.