Last active
July 22, 2022 16:12
-
-
Save blbacelar/badb2cb84173494ed61826486ad79ebb to your computer and use it in GitHub Desktop.
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
release-rc () { | |
rctag=$1 | |
project=$2 | |
# Validates tag name | |
regex='^[0-9]+\.[0-9]+\.[0-9]+' | |
if [[ ! $rctag =~ $regex ]]; then | |
echo "Tag version is not following the pattern" | |
return | |
fi | |
if [[ ! $rctag == *"RC"* ]]; then | |
echo "Tag version should contain RC in it" | |
return | |
fi | |
if [ $(git tag -l "$rctag") ]; then | |
echo "Tag $rctag version already exists" | |
else | |
echo "Connecting to API endpoint to get the release note" | |
# Check cURL command if available (required), abort if does not exists | |
type curl >/dev/null 2>&1 || { echo >&2 "Required curl but it's not installed. Aborting."; exit 1; } | |
RESPONSE=`curl -s --request GET -H "Content-Type:application/json" https://teamwork-fansunite.herokuapp.com/create-release-note/$project` | |
RELEASE=`echo $RESPONSE` | |
if [ $RELEASE = '']; then | |
echo "Error trying to get release note. Release note will be empty. Add it manualy" | |
fi | |
echo "Starting to create new tag and release note" | |
# $@ is the argument passed to this function. | |
# In this case, it's tag version. | |
git checkout dev && | |
git pull origin dev && | |
git checkout -b release$rctag dev && # create a temporary release branch | |
git commit -a -m "Release RC Version $rctag" --allow-empty -n && | |
git checkout RC && # checkout to RC | |
git merge release$rctag --no-ff -m "Merge release$rctag to RC" && # merge release branch to RC | |
git push origin RC && # push changes to RC | |
git tag -a $rctag -m "Version $rctag" && # Tag RC branch with release tag version | |
git push origin $rctag # Push tag version to remote | |
gh release create $rctag --notes $RELEASE --draft=false | |
git branch -d release$rctag # Delete temp release branch | |
fi | |
} | |
release-prod () { | |
# $1 is the RC tag that will me merged to master | |
# $2 is the tag that will be based on the master branch | |
rctag=$1 | |
prodtag=$2 | |
# Validates tag name | |
regex='^[0-9]+\.[0-9]+\.[0-9]+' | |
if [[ ! $prodtag =~ $regex ]]; then | |
echo "Tag version is not following the pattern" | |
return | |
fi | |
if [[ ! $rctag == *"RC"* ]]; then | |
echo "RC Tag version should contain RC in it" | |
return | |
fi | |
if [ $(git tag -l "$rctag") ]; then | |
git checkout master && | |
git pull origin master && | |
git merge $rctag --no-ff -m "Merged $rctag tag to master" && # merge release branch to master | |
git push origin master && # push changes to master | |
git tag -a $prodtag -m "Version $prodtag" && # Tag MASTER branch with release tag version | |
git push origin $prodtag # Push tag version to remote | |
return | |
else | |
echo "Tag $rctag doesn't exists" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to use this script
### Always checks on github releases what was the last tag released and make sure to follow the version order.