From 142515dddd1b902c5ac5f5f2b4fd5033a0e993fc Mon Sep 17 00:00:00 2001 From: Joshua Krusell Date: Fri, 15 Nov 2019 23:26:33 +0100 Subject: [PATCH] Initial release script to bump git tag --- scripts/build.sh | 13 +++++-- scripts/semver.sh | 95 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 4 deletions(-) create mode 100755 scripts/semver.sh diff --git a/scripts/build.sh b/scripts/build.sh index ad2521d..b0314c9 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -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 diff --git a/scripts/semver.sh b/scripts/semver.sh new file mode 100755 index 0000000..582e6d7 --- /dev/null +++ b/scripts/semver.sh @@ -0,0 +1,95 @@ +#!/bin/sh + +## Utility functions +usage() { + printf "Usage: ./$(basename $0) [-h] [-m ] [-s ]\n" + exit 127 +} + +help() { +cat </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