Approach for implementing git-flow releasing model

Background

Implementation — tools

|-- build
|-- deployment
| |-- release_finish.sh
| |-- release_finish_bamboo.sh
| |-- release_start.sh
| `-- release_start_bamboo.sh
|-- bump-version-drynext.sh
|-- bump-version.sh
|-- package.sh
|-- unpackage.sh
`-- version.txt

version.txt

0.0.1

bump-version-drynext.sh

➜  releasing  ./bump-version-drynext.sh
0.0.2
#!/bin/bash# credits: http://stackoverflow.com/questions/8653126/how-to-increment-version-number-in-a-shell-scriptincrement_version ()
{
declare -a part=( ${1//\./ } )
declare new
declare -i carry=1
for (( CNTR=${#part[@]}-1; CNTR>=0; CNTR-=1 )); do
len=${#part[CNTR]}
new=$((part[CNTR]+carry))
[ ${#new} -gt $len ] && carry=1 || carry=0
[ $CNTR -gt 0 ] && part[CNTR]=${new: -len} || part[CNTR]=${new}
done
new="${part[*]}"
echo -e "${new// /.}"
}
VERSION=`cat version.txt`increment_version $VERSION

bump-version.sh

#!/bin/bashset -eCURRENT_DIR=`pwd`
VERSION=$1
echo $VERSION > version.txt#Optionally - Update your app version in app files, like package.json, bower.json , etc
# Example for nodejs package.json:
#sed -i.bak "s/[[:space:]]*\"version\"[[:space:]]*:[[:space:]]*\".*\",/ \"version\":\"$VERSION\",/g" $CURRENT_DIR/package.json
#rm $CURRENT_DIR/package.json.bak || true

package.sh

#!/bin/sh
if [ -z "$1" ]
then
SUFFIX=""
else
SUFFIX="-$1"
fi
PROJECT=project-namerm -rf ./build || true
rm ${PROJECT}-*.tgz || true
mkdir -p ./build || true
VERSION=`cat version.txt`
GITCOMMIT=`git rev-parse --short HEAD`
DATE=`date +%Y-%m-%d:%H:%M:%S`
# do build here, that produces necessary files for artifact under build/ folderecho "major_version=$VERSION" > build/version.txt
echo "minor_version=$1" >> build/version.txt
echo "git_hash=$GITCOMMIT" >> build/version.txt
echo "built=$DATE" >> build/version.txt
echo PRODUCING ARTIFACT $PROJECT-$VERSION$SUFFIX.tgz in build/
tar cfz $PROJECT-$VERSION$SUFFIX.tgz build

Unpackage.sh

#!/bin/sh
PROJECT=project-name
rm -rf ./build || true
current_artefact=$(find ./${PROJECT}*.tgz -type f -exec stat -c "%n" {} + | sort | head -n1)
echo Working with artefact: $current_artefact
tar xvzf $current_artefact
echo artefact unpacked: $current_artefact

deployment/release_start.sh

#!/bin/shcd ${PWD}/../
VERSION=$1
if [ -z $1 ]
then
VERSION=`cat version.txt`
fi
#Initialize gitflow
git flow init -f -d
# ensure you are on latest develop & master
git checkout develop
git pull origin develop
git checkout -
git checkout master
git pull origin master
git checkout develop
git flow release start $VERSION# bump released version to server
git push
git checkout develop# COMMENT LINES BELOW IF YOU BUMP VERSION AT THE END
NEXTVERSION=`./bump-version-drynext.sh`
./bump-version.sh $NEXTVERSION
git commit -am "Bumps version to $NEXTVERSION"
git push origin develop

deployment/release_finish.sh

#!/bin/shcd ${PWD}/../# PREVENT INTERACTIVE MERGE MESSAGE PROMPT AT A FINAL STEP
GIT_MERGE_AUTOEDIT=no
export GIT_MERGE_AUTOEDIT
GITBRANCHFULL=`git rev-parse --abbrev-ref HEAD`
GITBRANCH=`echo "$GITBRANCHFULL" | cut -d "/" -f 1`
RELEASETAG=`echo "$GITBRANCHFULL" | cut -d "/" -f 2`
echo $GITBRANCH
echo $RELEASETAG
if [ $GITBRANCH != "release" ] ; then
echo "Release can be finished only on release branch!"
return 1
fi
if [ -z $RELEASETAG ]
then
echo We expect gitflow to be followed, make sure release branch called release/x.x.x
exit 1
fi
#Initialize gitflow
git flow init -f -d
# ensure you are on latest develop & master and return back
git checkout develop
git pull origin develop
git checkout -
git checkout master
git pull origin master
git checkout -
# UNCOMMENT THESE TWO LINES IF YOU BUMP VERSION AT THE END
#./bump-version.sh $RELEASETAG
#git commit -am "Bumps version to $RELEASETAG"
git flow release finish -m "release $RELEASETAG" $RELEASETAGgit push origin develop && git push origin master --tags

Linking to build server

deployment/release_start_bamboo.sh

#!/bin/shcd ${PWD}/../VERSION=$1
if [ -z $1 ]
then
VERSION=`cat version.txt`
fi
# PREVENT INTERACTIVE MERGE MESSAGE PROMPT
GIT_MERGE_AUTOEDIT=no
export GIT_MERGE_AUTOEDIT
GIT_REMOTE=git@github.com:Voronenko/gitflow-release.git
# add remote due to bamboo git cache shit
git remote add central "$GIT_REMOTE"
#Initialize gitflow
git flow init -f -d
# ensure you are on latest develop & master
git checkout develop
git pull central develop
git checkout -
git checkout master
git pull central master
git checkout develop
git flow release start $VERSION# bump released version to server
git push central release/$VERSION
git checkout develop# COMMENT LINES BELOW IF YOU BUMP VERSION AT THE END
NEXTVERSION=`./bump-version-drynext.sh`
./bump-version.sh $NEXTVERSION
git commit -am "Bumps version to $NEXTVERSION"
git push central develop

deployment/release_finish_bamboo.sh

#!/bin/sh# IMPORTANT - THIS FILE IS INTENDED TO BE EXECUTED ONLY IN BAMBOO ENVIRONMENTcd ${PWD}/../# PREVENT INTERACTIVE MERGE MESSAGE PROMPT AT A FINAL STEP
GIT_MERGE_AUTOEDIT=no
export GIT_MERGE_AUTOEDIT
GITBRANCHFULL=`git rev-parse --abbrev-ref HEAD`
GITBRANCH=`echo "$GITBRANCHFULL" | cut -d "/" -f 1`
RELEASETAG=`echo "$GITBRANCHFULL" | cut -d "/" -f 2`
GIT_REMOTE=git@github.com:Voronenko/gitflow-release.git
echo $GITBRANCH
echo $RELEASETAG
if [ $GITBRANCH != "release" ] ; then
echo "Release can be finished only on release branch!"
return 1
fi
if [ -z $RELEASETAG ]
then
echo We expect gitflow to be followed, make sure release branch called release/x.x.x.x
exit 1
fi
# add remote due to bamboo git cache shit
git remote add central "$GIT_REMOTE"
#Initialize gitflow
git flow init -f -d
# ensure you are on latest develop & master and return back
git checkout develop
git pull central develop
git checkout -
git checkout master
git pull central master
git checkout -
# UNCOMMENT THESE TWO LINES IF YOU BUMP VERSION AT THE END
#./bump-version.sh $RELEASETAG
#git commit -am "Bumps version to $RELEASETAG"
git flow release finish -m "release $RELEASETAG" $RELEASETAGgit push central develop && git push central master --tags

Points of Interest

--

--

--

Software engineer, with project management background. Founder @ softasap.com — cool automation for the people :) — have a problem that needs to be solved?

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

What I’ve learnt from working on a platform that serves millions of users ?

Engine Yard Kontainers and NoOps

Perform Realtime and Periodic ETL with WSO2 Stream Processor

Agile methodology: an overview

4 Tips from an Engineering Director to Build Reliable Automation

HTTP/2 What is it & Why should we care?

Day 2 Of Coding Every Day Until I Get A Job In Tech

Everything you need to know about Helm — Part I

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Vyacheslav Voronenko

Vyacheslav Voronenko

Software engineer, with project management background. Founder @ softasap.com — cool automation for the people :) — have a problem that needs to be solved?

More from Medium

How to integrate custom logs with Elastic Agent

Protect Elasticsearch from Apache Log4j Vulnerability #

Auditing WSO2 Micro-integrator with audit logs

PART 1 Install of Saas based Appdynamics client on Linux for app server agent