From 06e793940681cfef544fa9c2d065c750e9b1b0ee Mon Sep 17 00:00:00 2001 From: Jan Zickermann <jan.zickermann@dataport.de> Date: Tue, 11 Feb 2025 11:56:31 +0100 Subject: [PATCH] Add release script --- .gitignore | 1 + scripts/release-minor-version.sh | 49 ++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100755 scripts/release-minor-version.sh diff --git a/.gitignore b/.gitignore index 8731113..08bbd1d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +out/ # ---> Maven target/ pom.xml.tag diff --git a/scripts/release-minor-version.sh b/scripts/release-minor-version.sh new file mode 100755 index 0000000..090c4ec --- /dev/null +++ b/scripts/release-minor-version.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +set -e + +# Change directory to the root of the project +cd "$(dirname "${BASH_SOURCE[0]}")/../" + +if [ "$(git rev-parse --abbrev-ref HEAD)" != "main" ] +then + echo "[ERROR] Not on main branch" + exit 1 +fi + +if [ -n "$(git status --porcelain)" ] +then + echo "[ERROR] Working directory is not clean" + exit 1 +fi + +MAVEN_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) +if [[ ! "$MAVEN_VERSION" =~ -SNAPSHOT$ ]] +then + echo "[ERROR] Version should end with -SNAPSHOT" + exit 1 +fi + +prompt_yes_no() { + read -p "$1 (y/n) " -n 1 -r + echo + [[ $REPLY =~ ^[Yy]$ ]] || exit 1 +} + +NUMERIC_VERSION=$(echo "$MAVEN_VERSION" | cut -d'-' -f1) +MAJOR=$(echo "$NUMERIC_VERSION" | cut -d '.' -f 1) +MINOR=$(echo "$NUMERIC_VERSION" | cut -d '.' -f 2) +PATCH=$(echo "$NUMERIC_VERSION" | cut -d '.' -f 3) + +CURRENT_VERSION="$MAJOR.$MINOR.$PATCH" +NEW_VERSION="$MAJOR.$((MINOR + 1)).0" +NEW_SNAPSHOT_VERSION="$NEW_VERSION-SNAPSHOT" +prompt_yes_no "Tag $CURRENT_VERSION and bump version from $MAVEN_VERSION to $NEW_SNAPSHOT_VERSION?" + +git tag -m "Release version $CURRENT_VERSION" "$CURRENT_VERSION" +mvn versions:set -DnewVersion="$NEW_SNAPSHOT_VERSION" -DgenerateBackupPoms=false +git add -u +git commit -m "Start development of $NEW_VERSION" + +prompt_yes_no "git push origin main $CURRENT_VERSION?" +git push origin main "$CURRENT_VERSION" \ No newline at end of file -- GitLab