Skip to content

Instantly share code, notes, and snippets.

@blbacelar
Last active July 22, 2022 16:12
Show Gist options
  • Save blbacelar/badb2cb84173494ed61826486ad79ebb to your computer and use it in GitHub Desktop.
Save blbacelar/badb2cb84173494ed61826486ad79ebb to your computer and use it in GitHub Desktop.
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
}
@blbacelar
Copy link
Author

blbacelar commented Jul 22, 2022

How to use this script

Install GitHub CLI (https://github.com/cli/cli#installation)
copy & paste the release-rc and release-pro function into your .bashrc or .zshrc or whatever you use

release-rc receives 2 parameters:

The first is the new TAG version that will be created. (ie: 2.1.47.RC)
The second is the Project ID on Teamwork (i.e: Backoffice is 312381 and CSB is 312380)
This function get the project ID and connects to teamwork and get all the cards in QA passed and create the release notes.
After that updates the dev branch and updates RC branch and creates a new tag based on RC.
As soon as it finishes gets the new tag go to jenkins and deploy that tag to RC.

release-prod receives 2 parameters:

The first is the RC TAG version that will be merged to master. (ie: 2.1.47.RC)
The second is the new TAG that will be created based on RC tag. Usually is the same number without RC. (ie: 2.1.47)
This functions merges the RC tag to master and creates a new tag based on master
As soon as it finishes gets the new tag go to jenkins and deploy that tag to production.

### Always checks on github releases what was the last tag released and make sure to follow the version order.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment