From 5b0862ef65d4290400b865827d2fb4bd08ef2738 Mon Sep 17 00:00:00 2001 From: Esteban Beltran Date: Tue, 13 Jul 2021 16:16:04 +0200 Subject: [PATCH] Add increment version script Update readme --- Makefile | 6 ++++ README.md | 11 ++++++- scripts/increment-version.sh | 57 ++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100755 scripts/increment-version.sh diff --git a/Makefile b/Makefile index 2b8dfbf..121d353 100644 --- a/Makefile +++ b/Makefile @@ -21,3 +21,9 @@ clean: rm -rf kibbe.spec rm -rf build rm -rf dist + +minor-release: + ./scripts/increment-version.sh -v minor + +major-release: + ./scripts/increment-version.sh -v major \ No newline at end of file diff --git a/README.md b/README.md index ced311e..feb6ed4 100644 --- a/README.md +++ b/README.md @@ -81,4 +81,13 @@ or simply ## Linting and formatting -This project uses autopep8 and flake8 for formatting and linting. Make sure your editor has these tools installed and running. \ No newline at end of file +This project uses autopep8 and flake8 for formatting and linting. Make sure your editor has these tools installed and running. + +## Releasing + +To release a new version, you need to push a new incremental tag. That will trigger an auto-build and release. + +There's a handy script to automate this process in `scripts/increment-version.sh` and you can use make to invoke it: + +Minor release: `make minor-release` +Major release: `make major-relase` diff --git a/scripts/increment-version.sh b/scripts/increment-version.sh new file mode 100755 index 0000000..d5476f7 --- /dev/null +++ b/scripts/increment-version.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +VERSION="" + +#get parameters +while getopts v: flag; do + case "${flag}" in + v) VERSION=${OPTARG} ;; + esac +done + +#get highest tag number, and add 1.0.0 if doesn't exist +CURRENT_VERSION=$(git describe --abbrev=0 --tags 2>/dev/null) + +if [[ $CURRENT_VERSION == '' ]]; then + CURRENT_VERSION='1.0.0' +fi +echo "Current Version: $CURRENT_VERSION" + +#replace . with space so can split into an array +CURRENT_VERSION_PARTS=(${CURRENT_VERSION//./ }) + +#get number parts +VNUM1=${CURRENT_VERSION_PARTS[0]} +VNUM2=${CURRENT_VERSION_PARTS[1]} +VNUM3=${CURRENT_VERSION_PARTS[2]} + +if [[ $VERSION == 'major' ]]; then + VNUM1=$((VNUM1 + 1)) +elif [[ $VERSION == 'minor' ]]; then + VNUM2=$((VNUM2 + 1)) +elif [[ $VERSION == 'patch' ]]; then + VNUM3=$((VNUM3 + 1)) +else + echo "No version type (https://semver.org/) or incorrect type specified, try: -v [major, minor, patch]" + exit 1 +fi + +#create new tag +NEW_TAG="$VNUM1.$VNUM2.$VNUM3" +echo "($VERSION) updating $CURRENT_VERSION to $NEW_TAG" + +#get current hash and see if it already has a tag +GIT_COMMIT=$(git rev-parse HEAD) +NEEDS_TAG=$(git describe --contains $GIT_COMMIT 2>/dev/null) + +#only tag if no tag already +#to publish, need to be logged in to npm, and with clean working directory: `npm login; git stash` +if [ -z "$NEEDS_TAG" ]; then + git tag $NEW_TAG + echo "Tagged with $NEW_TAG" + git push --tags +else + echo "Already a tag on this commit" +fi + +exit 0