Skip to content

Instantly share code, notes, and snippets.

@coenraadhuman
Last active November 18, 2021 11:23
Show Gist options
  • Save coenraadhuman/2f1a0faf898c3fefc228a0166f61c661 to your computer and use it in GitHub Desktop.
Save coenraadhuman/2f1a0faf898c3fefc228a0166f61c661 to your computer and use it in GitHub Desktop.
Stupid script to see if you have SNAPSHOT in your artifact version or dependencies in you Maven pom.xml
#!/usr/bin/env bash
set -euo pipefail
function main() {
echo "Branch to be checked: $1"
echo "Running evaluation on artifact pom:"
# Reason for code block with || true on grep commands is because it exists with 1 if nothing is found.
# Which is perfectly acceptable for the below scenario, so we need to change the exit code to 0.
# EXPLANATION:
# "The "||" means "or". If the first part of the command "fails" (meaning "grep e" returns a non-zero
# exit code) then the part after the "||" is executed, succeeds and returns zero as the exit code
# (true always returns zero)."
# See for futher information: https://unix.stackexchange.com/questions/330660/prevent-grep-from-exiting-in-case-of-nomatch
foundSnapshot=$(cat pom.xml | { grep "<version>.*-SNAPSHOT<\/version>" -c || true; })
# Print the grep results:
cat pom.xml | { grep "<version>.*-SNAPSHOT<\/version>" -n || true; }
if [[ 0 -eq $foundSnapshot ]];
then
echo "No snapshot versions found in pom."
else
echo "Found snapshot version in pom."
fi
if [[ "$1" == *"hotfix"* ]] || [[ "$1" == *"release"* ]] || [[ "$1" == "master" ]] || [[ "$1" == "main" ]]; then
if [[ 0 -eq $foundSnapshot ]];
then
echo "Version is correct for production."
exit 0
else
echo "Version is wrong and it can't be a SNAPSHOT version for production!"
echo "For more information regarding the artifact versioning please visit: https://aws-tools.standardbank.co.za/confluence/display/PAST/Artifact+Versioning"
exit 1
fi
else
if [[ 1 -eq $foundSnapshot ]];
then
echo "Version is correct and includes expected SNAPSHOT for development."
exit 0
else
echo "Note: IF THIS IS A RELEASE BRANCH, PLEASE USE THE CORRECT BRANCH TYPE: 'release/' OR AT THE VERY LEAST INCLUDE 'release' IN THE BRANCH NAME."
echo "Note: IF THIS IS A HOTFIX BRANCH, PLEASE USE THE CORRECT BRANCH TYPE: 'hotfix/' OR AT THE VERY LEAST INCLUDE 'hotfix' IN THE BRANCH NAME."
echo "Version is wrong and it can't be a SNAPSHOT version for production!"
echo "For more information regarding the artifact versioning please visit: https://aws-tools.standardbank.co.za/confluence/display/PAST/Artifact+Versioning"
exit 1
fi
fi
}
main $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment