Skip to content

Instantly share code, notes, and snippets.

@marcingrzejszczak
Created August 12, 2016 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcingrzejszczak/37a7789950175ff0df05c24ce34a4b66 to your computer and use it in GitHub Desktop.
Save marcingrzejszczak/37a7789950175ff0df05c24ce34a4b66 to your computer and use it in GitHub Desktop.
Retrieves the Spring Cloud project's version
#!/usr/bin/env bash
source common.sh || source scripts/common.sh || echo "No common.sh script found..."
set -e
function print_usage() {
cat <<EOF
USAGE:
You can use the following options:
-v|--version - which version of Spring Cloud Contract do you want to use
EOF
}
while [[ $# > 0 ]]
do
key="$1"
case $key in
-v|--version)
VERIFIER_VERSION="$2"
shift # past argument
;;
--help)
print_usage
exit 0
;;
*)
echo "Invalid option: [$1]"
print_usage
exit 1
;;
esac
shift # past argument or value
done
# Code grepping for the 3rd presence of "version" in pom.xml.
# The 3rd one is where we define the SC-Contract version
VERSION_NODE=`awk '/version/{i++}i==3{print; exit}' $ROOT_FOLDER/pom.xml`
# Extract the contents of the version node
VERSION_VALUE=$(sed -ne '/version/{s/.*<version>\(.*\)<\/version>.*/\1/p;q;}' <<< "$VERSION_NODE")
[[ -z "${VERIFIER_VERSION}" ]] && VERIFIER_VERSION="$VERSION_VALUE"
export VERIFIER_VERSION
echo -e "\n\nBUILDING AND RUNNING TESTS FOR VERIFIER IN VERSION [$VERIFIER_VERSION]\n\n"
@marcingrzejszczak
Copy link
Author

#!/usr/bin/env bash

set -e

ROOT_FOLDER=`pwd`
echo "Current folder is $ROOT_FOLDER"

if [[ ! -e "${ROOT_FOLDER}/.git" ]]; then
    cd ..
    ROOT_FOLDER=`pwd`
fi

echo "Root folder is $ROOT_FOLDER"

# Code grepping for the 3rd presence of "version" in pom.xml.
# The 3rd one is where we define the SC-Contract version
VERSION_NODE=`awk '/version/{i++}i==3{print; exit}' $ROOT_FOLDER/pom.xml`
# Extract the contents of the version node
VERSION_VALUE=$(sed -ne '/version/{s/.*<version>\(.*\)<\/version>.*/\1/p;q;}' <<< "$VERSION_NODE")

echo "Extracted version from root pom.xml is [$VERSION_VALUE]"

export ROOT_FOLDER
export VERSION_VALUE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment