From 9e8d4a1c68ed16b555350d1a1605eb70b66d1adf Mon Sep 17 00:00:00 2001 From: Stephen Cochrane Date: Sun, 19 Feb 2023 01:35:05 +0200 Subject: [PATCH] Added script for java projects that assists in authoring a release --- skelly.sh | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/skelly.sh b/skelly.sh index b5193d2..8674306 100755 --- a/skelly.sh +++ b/skelly.sh @@ -199,6 +199,63 @@ init_java() pp=${pp:-com.example} pp=${pp,,} + mkdir scripts + cat << EOF > scripts/release.sh +#!/usr/bin/env bash +# Guide the user through a new release +# Written by Stephen Cochrane + +set -e + +ROOT=\$(realpath "\$(dirname "\$0")/..") # This sets the ROOT to root of the repo + +cd "\$ROOT" || exit 1 + +BRANCH=\$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/') + +# Currently, we only want to de releases from the master branch, review this +# decision later +if [ ! "\$BRANCH" = master ] +then + echo "Must be on master branch to do a release" + exit 1 +fi + +# Check valid semvar +checkSemvar() +{ + grep -qP '^(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)\.(?P0|[1-9]\d*)(?:-(?P(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$' <<< "\$1" +} + +read -rp 'Enter next version: ' version + +if ! checkSemvar "\$version" +then + echo "Invalid semvar, please ensure the version number follows https://semver.org/ spec." + exit 1 +fi + +task=install + +if grep -q '' pom.xml +then + task=deploy +fi + +mvn \$task +tag=v\$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) + +# bump to the next version +echo "\$version" | mvn versions:set +rm pom.xml.versionsBackup # delete the backup pom, this is redundent + +git tag "\$tag" +git add . +git commit -m "Bump Version: \$version" +git push --atomic origin master "\$tag" +EOF + chmod +x scripts/release.sh + cat << EOF > run.sh #!/usr/bin/env bash # java wrapper script -- 2.45.2