bitops icon indicating copy to clipboard operation
bitops copied to clipboard

Github Tag/Release/Versioning on successful run

Open mickmcgrath13 opened this issue 3 years ago • 0 comments

from @ConnorGraham

Inspired by SemanticRelease in a past job, but frustrated it didn't work properly with my use case, I wrote my own lite version that generates a new git tag based on the previous one + commit message. Marking successful bitops/operations repo runs with a git tag and even a git release would be a good candidate for the environment level bitops.config.yml

Here is a lite version by @ConnorGraham :

# Get latest tag
TAG=$(git describe --tags --abbrev=0 || echo v0.0.0)
MAJOR=$(cut -d '.' -f1 <<< "$TAG" | tr -d 'v')
MINOR=$(cut -d '.' -f2 <<< "$TAG")
PATCH=$(cut -d '.' -f3 <<< "$TAG")
OTHER=$(cut -d '.' -f4 <<< "$TAG")
# Determine next tag
BRANCH=$(git rev-parse --abbrev-ref HEAD)
COMMIT_MSG=$(git log --format=%B -n1 HEAD)
echo MAJOR: $MAJOR
echo MINOR: $MINOR
echo PATCH: $PATCH
echo OTHER: $OTHER
echo BRANCH: $BRANCH
echo COMMIT_MSG: $COMMIT_MSG
if [[ $COMMIT_MSG == major* ]]; then 
    echo "Major Build Detected"
    MAJOR=$(($MAJOR+1))
    MINOR=0
    PATCH=0
    OTHER=""
elif [[ $COMMIT_MSG == minor* ]]; then
    echo "Minor Build Detected"
    MINOR=$(($MINOR+1))
    PATCH=0
    OTHER=""
elif [[ $COMMIT_MSG == patch* ]]; then
    echo "Patch Build Detected"
    PATCH=$(($PATCH+1))
    OTHER=""
else
    OTHER=".$BRANCH"
fi
export NEW_TAG="v$MAJOR.$MINOR.$PATCH$OTHER"
echo NEW TAG: $NEW_TAG

mickmcgrath13 avatar Mar 09 '21 16:03 mickmcgrath13