Last active
September 11, 2019 22:12
-
-
Save czende/72a72042f121359967b7839cbf81d19d to your computer and use it in GitHub Desktop.
Check version by git tag in pipeline
This file contains hidden or 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/sh | |
APP_VERSION="$(git tag --contains $BITBUCKET_COMMIT)" | |
ENVIRONMENT="$1" | |
STG_REGEX="^v.*\\-.*$" | |
PROD_REGEX="^v.[^-]*$" | |
# Check commit tag | |
if [ "$APP_VERSION" == "" ] ; then | |
echo "ERROR: Commit doesn't contain TAG!"; | |
exit 1; | |
else | |
echo "SUCCESS: Commit contains TAG!"; | |
fi | |
# Check proper staging version | |
if [ "$ENVIRONMENT" = "stg" ] ; then | |
if (echo "$APP_VERSION" | grep -Eq "$STG_REGEX"); then | |
echo "SUCCESS: Valid staging version!"; | |
else | |
echo "ERROR: Not a valid staging version! Proper usage: v001-rc1, v001-pre, v0.0.1-rc1, ..."; | |
exit 1; | |
fi | |
fi | |
# Check proper production version | |
if [ "$ENVIRONMENT" = "prod" ]; then | |
if (echo "$APP_VERSION" | grep -Eq "$PROD_REGEX"); then | |
echo "SUCCESS: Valid production version!"; | |
else | |
echo "ERROR: Not a valid production version! Proper usage: v001, v002, v0.0.1 ..."; | |
exit 1; | |
fi | |
fi | |
export APP_VERSION=$APP_VERSION |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment