Created
May 20, 2021 06:31
-
-
Save AvnerCohen/68ced8fb74125ba0243f61a068aad767 to your computer and use it in GitHub Desktop.
Automatic Git Tagging for Shared Libraries
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 | |
# When executing in circleci, make sure a user is defined in git config | |
CURRENT_NAME=$(git config user.name) | |
if [[ -z $CUR_NAME ]]; then | |
git config user.name "CI USER" | |
git config user.email [email protected] | |
echo "Git names init done." | |
fi | |
# Extract status - latest tag and prefix template | |
LATEST_TAG=$(git describe --tags --abbrev=0) | |
echo "Identified latest tag as - $LATEST_TAG" | |
TAG_MAJOR_PART=$(echo "${LATEST_TAG}" | cut -d"." -f1) | |
TAG_MINOR_PART=$(echo "${LATEST_TAG}" | cut -d"." -f2) | |
TAG_PATCH_PART=$(echo "${LATEST_TAG}" | cut -d"." -f3) | |
TMPLT_MAJOR_PART=$(cat version.prefix | cut -d"." -f1) | |
TMPLT_MAJOR_PART=$(cat version.prefix | cut -d"." -f2) | |
# If a major or minor version changed, reset patch counter | |
if [[ $TAG_MAJOR_PART -ne $TMPLT_MAJOR_PART || $TAG_MINOR_PART -ne $TMPLT_MAJOR_PART ]]; then | |
NEW_PATCH="0" | |
else | |
NEW_PATCH=$(expr $TAG_PATCH_PART + 1) | |
fi | |
# Tag and push | |
NEW_VER=$(cat version.prefix | sed "s/\#/${NEW_PATCH}/") | |
echo "Pushing new tag - $NEW_VER" | |
git tag -a $NEW_VER -m "Auto-tag created: $(date +'%Y-%m-%d_%H-%M-%S') - Prev tag ${LATEST_TAG}" | |
git push origin $NEW_VER | |
## Notify user about the newly created tag - via slack api |
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
12.4.# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment