Created
February 4, 2021 18:29
-
-
Save canmogol/b2149a6cafec641ac2d2809346528910 to your computer and use it in GitHub Desktop.
pom.xml version check on commit, .git/hooks/pre-commit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
TARGET_VERSION="develop" | |
Color_Off='\033[0m' | |
BRed="\033[1;31m" | |
# put the pom.xml from develop branch into the temp folder | |
RANDOM_NUMBER=$((100000 + $RANDOM % 100000)) | |
#echo "RANDOM_NUMBER: "$RANDOM_NUMBER | |
#echo "git show $TARGET_VERSION:pom.xml > /tmp/$RANDOM_NUMBER-pom.xml" | |
git show $TARGET_VERSION:pom.xml > /tmp/$RANDOM_NUMBER-pom.xml | |
# get the current version from pom.xml | |
CURRENT_VERSION=$(xpath pom.xml 'string(/project/version/text())' 2>/dev/null) | |
#echo "CURRENT_VERSION: "$CURRENT_VERSION | |
# get the target branch version | |
TARGET_VERSION=$(xpath /tmp/$RANDOM_NUMBER-pom.xml 'string(/project/version/text())' 2>/dev/null) | |
#echo "TARGET_VERSION: "$TARGET_VERSION | |
rm /tmp/$RANDOM_NUMBER-pom.xml | |
if [[ $CURRENT_VERSION = $TARGET_VERSION ]]; then | |
printf "${BRed}Version number must be different, current version: $CURRENT_VERSION target version: $TARGET_VERSION are the same.\n" | |
exit 1 | |
else | |
printf "Version changed." | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment