Skip to content

Commit

Permalink
+ semver tag push
Browse files Browse the repository at this point in the history
  • Loading branch information
q3769 committed Aug 20, 2024
1 parent 00c482e commit a7c4217
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions semver-tag-push.sh
Original file line number Diff line number Diff line change
@@ -1,34 +1,21 @@
#!/usr/bin/env bash

# This script is used to tag and push a new version of the project
# It is intended to be run from the root of the project
# It uses the git tag command to create a new tag and push it to the remote repository
# Tag and push a new version of the project from the root directory

# Ensure the script is run from the root of the project
if [ ! -f "pom.xml" ]; then
echo "This script must be run from the root of the project where the pom.xml file is located."
exit 1
fi
[ -f "pom.xml" ] || { echo "Run from the project root with pom.xml"; exit 1; }

# Ensure the working directory is clean
if [ -n "$(git status --porcelain)" ]; then
echo "Working directory is not clean. Please commit or stash your changes."
exit 1
fi
[ -z "$(git status --porcelain)" ] || { echo "Working directory is not clean, please commit or stash your changes"; exit 1; }

# Ensure current POM version is a valid semver
if ! mvn semver:verify-current; then
echo "Current POM version is not a valid semver version."
exit 1
fi
mvn semver:verify-current >/dev/null || { echo "Current POM version is not a valid semver version"; exit 1; }

# Get the current version from the pom.xml file
CURRENT_VERSION=$(mvn org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate -Dexpression=project.version -q -DforceStdout | tr -d "[:space:]")
CURRENT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout | tr -d "[:space:]")

# Create a new tag with the current version
# Create and push a new tag with the current version
git tag -a "$CURRENT_VERSION" -m "Release version tag $CURRENT_VERSION"

# Push the new tag to the remote repository
git push origin "$CURRENT_VERSION"

echo "Tagged and pushed version $CURRENT_VERSION."

0 comments on commit a7c4217

Please sign in to comment.