Skip to content

Instantly share code, notes, and snippets.

@czende
Last active September 11, 2019 22:12
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 czende/72a72042f121359967b7839cbf81d19d to your computer and use it in GitHub Desktop.
Save czende/72a72042f121359967b7839cbf81d19d to your computer and use it in GitHub Desktop.
Check version by git tag in pipeline
#!/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