Skip to content

Instantly share code, notes, and snippets.

@ayhid
Forked from jrbenito/release.sh
Created August 23, 2016 13:35
Show Gist options
  • Save ayhid/e7b53e3dd86efb138ab158b619f79927 to your computer and use it in GitHub Desktop.
Save ayhid/e7b53e3dd86efb138ab158b619f79927 to your computer and use it in GitHub Desktop.
Bash script to automate the Git Flow tag/release process
#!/bin/bash
# current Git branch
branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
# v1.0.0, v1.5.2, etc.
versionLabel=v$1
# establish branch and tag name variables
devBranch=develop
masterBranch=master
releaseBranch=release-$versionLabel
# create the release branch from the -develop branch
git checkout -b $releaseBranch $devBranch
# store commits in one line with "\r\n" as line break, this shall be literal
# and will be interpreted by Jira later.
commits=`git --no-pager log --pretty=format:'%aN - Commit %h - %f' master...HEAD| sed ':a;N;$!ba;s/\n/\\\\r\\\\n/g'`
# file in which to update version number
versionFile="version.txt"
# find version number assignment ("= v1.5.5" for example)
# and replace it with newly specified version number
sed -i.backup -E "s/\= v[0-9.]+/\= $versionLabel/" $versionFile $versionFile
# remove backup file created by sed command
rm $versionFile.backup
# commit version number increment
git commit -am "Incrementing version number to $versionLabel"
# merge release branch with the new version number into master
git checkout $masterBranch
git merge --no-ff $releaseBranch
# create tag for new version from -master
git tag $versionLabel
# merge release branch with the new version number back into develop
git checkout $devBranch
#git merge --no-ff $releaseBranch
# Merge Master branch with new version number back into develop
git merge $masterBranch
# generate archives
git clone . rel
cd rel
tar cfvz ../releases/checklist-${versionLabel}.tar.gz *
cd -
rm -rf rel
# update Jira issue with new release and comment
# read password and username from jira options.ini
while IFS='= ' read var val
do
if [[ $var == \[*] ]]
then
section=$var
elif [[ $val ]]
then
declare "$var$section=$val"
fi
done < ./jira-options.ini
comment="{\"body\": \"{color:red}Release ${versionLabel}{color}\r\n${commits}\"}"
#attach tarball to Jira Ticket
curl -D- -u $username$SESSION:$password$SESSION -X POST -H "X-Atlassian-Token: nocheck" -F "file=@./releases/checklist-${versionLabel}.tar.gz" http://<host.jira>/rest/api/2/issue/<issueKey>/attachments
#Comment Jira Ticket with git log information and release number
curl -D- -u $username$SESSION:$password$SESSION -X POST -H "Content-Type: application/json" --data "$comment" http://<host.jira>/rest/api/2/issue/<issueKey>/comment
# remove release branch
git branch -d $releaseBranch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment