├── README.md ├── build └── .gitkeep ├── bump-minorversion-drynext.sh ├── bump-version-drynext.sh ├── bump-version.sh ├── deployment-bump-at-start ├── auto_confict_resolve.sh ├── hotfix_finish_bamboo.sh ├── hotfix_start_bamboo.sh ├── release_finish_bamboo.sh └── release_start_bamboo.sh ├── deployment-single-makefile ├── Makefile ├── Readme.md ├── clean_build.sh └── make_helper.sh ├── deployment ├── hotfix_finish.sh ├── hotfix_finish_bamboo.sh ├── hotfix_start.sh ├── hotfix_start_bamboo.sh ├── release_finish.sh ├── release_finish_bamboo.sh ├── release_start.sh └── release_start_bamboo.sh ├── images ├── bamboo_release_branch.png ├── bamboo_release_finish.png ├── bamboo_release_start.png └── git-workflow-release-cycle-4maintenance.png ├── package.sh ├── unpackage.sh └── version.txt /README.md: -------------------------------------------------------------------------------- 1 | ## Introduction 2 | 3 | Perhaps most of developers are familiar with git-flow model, that makes release process controlled. In this article I would demonstrate one of approaches to introduce git-flow releasing in your project, capable to be integrated with continious integration tool of your choice, like Atlassian Bamboo provided as an example 4 | 5 | ## Background 6 | 7 | If you never heard about git-flow previously, I suggest to study classic post [http://nvie.com/posts/a-successful-git-branching-model/](http://nvie.com/posts/a-successful-git-branching-model/) && how Atlassian interpret the same idea [https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow](https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow) 8 | 9 | For those, who aware, let me remind well known diagram: 10 | 11 |  12 | 13 | ## Implementation - tools 14 | 15 | Usually I introduce approach with set of file-helpers that migrate & evolve with each next project. I support idea, that code infrastructure should be stored alongside the project code. Thus usually I have deployment folder where devops scenarios live (usually I use Ansible tool, althouth had experience with CHEF deployments too), and suppose that developers provide me with build logic that outputs target artifact files under buiild/ folder. As a result, typical devops magic structure looks like: 16 | 17 |
|-- build
18 | |-- deployment
19 | | |-- release_finish.sh
20 | | |-- release_finish_bamboo.sh
21 | | |-- release_start.sh
22 | | `-- release_start_bamboo.sh
23 | |-- bump-version-drynext.sh
24 | |-- bump-version.sh
25 | |-- package.sh
26 | |-- unpackage.sh
27 | `-- version.txt
28 |
29 |
30 | Let's take a look on files contents & purpose.
31 |
32 | #### version.txt
33 |
34 | Simple text file, containing current project version. I like idea with git tags in git-flow, but really would prefer to have the possibility to control versioning on my own. Typical version example is x.y.z:
35 |
36 | 37 | 0.0.1 38 |39 | 40 | #### bump-version-drynext.sh 41 | 42 | In most of scenarios of continious integration, subsequent releases change only minor version. Thanks to handy bash script credited in source we have possibility to get value of the next minor version 43 | 44 |
➜ releasing ./bump-version-drynext.sh 45 | 0.0.246 | 47 | Logic is simple enough - we read current version from version.txt & apply shell magic to get next value. 48 | 49 | ```shell-script 50 | #!/bin/bash 51 | 52 | # credits: http://stackoverflow.com/questions/8653126/how-to-increment-version-number-in-a-shell-script 53 | 54 | increment_version () 55 | { 56 | declare -a part=( ${1//\./ } ) 57 | declare new 58 | declare -i carry=1 59 | 60 | for (( CNTR=${#part[@]}-1; CNTR>=0; CNTR-=1 )); do 61 | len=${#part[CNTR]} 62 | new=$((part[CNTR]+carry)) 63 | [ ${#new} -gt $len ] && carry=1 || carry=0 64 | [ $CNTR -gt 0 ] && part[CNTR]=${new: -len} || part[CNTR]=${new} 65 | done 66 | new="${part[*]}" 67 | echo -e "${new// /.}" 68 | } 69 | 70 | 71 | VERSION=`cat version.txt` 72 | 73 | increment_version $VERSION 74 | 75 | ``` 76 | 77 | #### bump-version.sh 78 | 79 | Very important file. Usually I prefer that app version in my project files (like bower.json, package.json) to match current project version. This is the place were patching could be implemented. 80 | 81 | What the code does - it applies version parameter to files, and writes new one into version.txt 82 | 83 | ```shell-script 84 | #!/bin/bash 85 | 86 | set -e 87 | 88 | CURRENT_DIR=`pwd` 89 | VERSION=$1 90 | 91 | echo $VERSION > version.txt 92 | 93 | #Optionally - Update your app version in app files, like package.json, bower.json , etc 94 | # Example for nodejs package.json: 95 | 96 | #sed -i.bak "s/[[:space:]]*\"version\"[[:space:]]*:[[:space:]]*\".*\",/ \"version\":\"$VERSION\",/g" $CURRENT_DIR/package.json 97 | #rm $CURRENT_DIR/package.json.bak || true 98 | 99 | ``` 100 | 101 | #### package.sh 102 | 103 | This logic allows to create tgz-ipped artifact file either in form project-name-version.tgz or in form project-name-version-buildnumber.tgz ; The latest case could be important, if you need to store artifacts history for every build. 104 | 105 | File can be adjusted by changing PROJECT variable to match your project name. In addition, if you ever wanted to know more information about artifact, it packs version.txt file, which contains information about major_version, minor_version, git_hash, and built date. With this info you can identify commit that was used to produce the build. 106 | 107 | In addition, such files can be easily read by build servers like bamboo or jenkins & transformed into internal variables. 108 | 109 | Resulting files are placed in build/ and packed. 110 | 111 | ```shell-script 112 | #!/bin/sh 113 | if [ -z "$1" ] 114 | then 115 | SUFFIX="" 116 | else 117 | SUFFIX="-$1" 118 | fi 119 | 120 | PROJECT=project-name 121 | 122 | rm -rf ./build || true 123 | rm ${PROJECT}-*.tgz || true 124 | mkdir -p ./build || true 125 | 126 | VERSION=`cat version.txt` 127 | GITCOMMIT=`git rev-parse --short HEAD` 128 | DATE=`date +%Y-%m-%d:%H:%M:%S` 129 | 130 | # do build here, that produces necessary files for artifact under build/ folder 131 | 132 | echo "major_version=$VERSION" > build/version.txt 133 | echo "minor_version=$1" >> build/version.txt 134 | echo "git_hash=$GITCOMMIT" >> build/version.txt 135 | echo "built=$DATE" >> build/version.txt 136 | 137 | echo PRODUCING ARTIFACT $PROJECT-$VERSION$SUFFIX.tgz in build/ 138 | tar cfz $PROJECT-$VERSION$SUFFIX.tgz build 139 | ``` 140 | 141 | #### Unpackage.sh 142 | 143 | This file is usually executed on a next step in build process, when artifact was previously packed by build step, and now you need to do smth with content, for example initiate deployment. In 100% scenarios I would expect only one artifact file, but if there are several versions, I pick only the most recent one. 144 | 145 | In a result, you will get unpacked artifact in build folder. 146 | 147 | ```shell-script 148 | #!/bin/sh 149 | PROJECT=project-name 150 | rm -rf ./build || true 151 | current_artefact=$(find ./${PROJECT}*.tgz -type f -exec stat -c "%n" {} + | sort | head -n1) 152 | echo Working with artefact: $current_artefact 153 | tar xvzf $current_artefact 154 | echo artefact unpacked: $current_artefact 155 | 156 | ``` 157 | 158 | #### deployment/release_start.sh 159 | 160 | What it does - it creates the release, and pushes release branch to server, so the continious integration tool can pick it up and build. I have to say that some portion of holy war is present here: when to bump version. I had two types of the customers: customer - BEGIN insist, that version.txt contains version he is going to release, thus once I start release process, I should immediate bump version up in the develop, as all new features there will belong to the next release. From other hand, customer-END usually does not care on version.txt, and per his understanding, bumping the version is the final step in the release - i.e. after that push everything that was commited previously was 0.0.1 ongoing development and now we have released 0.0.2\. I would prefer to bump version at the end. As you see both approaches are supported with litle commenting. 161 | 162 | This batch implements release start by either providing new release version as a parameter, or getting the one from version.txt 163 | 164 | ```shell-script 165 | #!/bin/sh 166 | 167 | cd ${PWD}/../ 168 | VERSION=$1 169 | if [ -z $1 ] 170 | then 171 | VERSION=`cat version.txt` 172 | fi 173 | 174 | #Initialize gitflow 175 | git flow init -f -d 176 | 177 | # ensure you are on latest develop & master 178 | git checkout develop 179 | git pull origin develop 180 | git checkout - 181 | 182 | git checkout master 183 | git pull origin master 184 | git checkout develop 185 | 186 | git flow release start $VERSION 187 | 188 | # bump released version to server 189 | git push 190 | 191 | git checkout develop 192 | 193 | # COMMENT LINES BELOW IF YOU BUMP VERSION AT THE END 194 | NEXTVERSION=`./bump-version-drynext.sh` 195 | ./bump-version.sh $NEXTVERSION 196 | git commit -am "Bumps version to $NEXTVERSION" 197 | git push origin develop 198 | 199 | ``` 200 | 201 | #### deployment/release_finish.sh 202 | 203 | Fortunately, this step does not require any external parameters. Current release version is detected from the branch name (release/0.0.2) and rest of the steps are clear. Again here, if you follow the classic bump-the-version approach - you would need to uncomment "./bump-version.sh $RELEASETAG" 204 | 205 | ```shell-script 206 | #!/bin/sh 207 | 208 | cd ${PWD}/../ 209 | 210 | # PREVENT INTERACTIVE MERGE MESSAGE PROMPT AT A FINAL STEP 211 | GIT_MERGE_AUTOEDIT=no 212 | export GIT_MERGE_AUTOEDIT 213 | 214 | GITBRANCHFULL=`git rev-parse --abbrev-ref HEAD` 215 | GITBRANCH=`echo "$GITBRANCHFULL" | cut -d "/" -f 1` 216 | RELEASETAG=`echo "$GITBRANCHFULL" | cut -d "/" -f 2` 217 | 218 | echo $GITBRANCH 219 | echo $RELEASETAG 220 | 221 | if [ $GITBRANCH != "release" ] ; then 222 | echo "Release can be finished only on release branch!" 223 | return 1 224 | fi 225 | 226 | if [ -z $RELEASETAG ] 227 | then 228 | echo We expect gitflow to be followed, make sure release branch called release/x.x.x 229 | exit 1 230 | fi 231 | 232 | #Initialize gitflow 233 | git flow init -f -d 234 | 235 | # ensure you are on latest develop & master and return back 236 | git checkout develop 237 | git pull origin develop 238 | git checkout - 239 | 240 | git checkout master 241 | git pull origin master 242 | git checkout - 243 | 244 | # UNCOMMENT THESE TWO LINES IF YOU BUMP VERSION AT THE END 245 | #./bump-version.sh $RELEASETAG 246 | #git commit -am "Bumps version to $RELEASETAG" 247 | 248 | git flow release finish -m "release $RELEASETAG" $RELEASETAG 249 | 250 | git push origin develop && git push origin master --tags 251 | 252 | ``` 253 | 254 | ## Linking to build server 255 | 256 | All popular build servers support branches detecting and building. For example, Atlassian Bamboo has this easily configurable via UI , while, for example, for Jenkins you will need to play more. 257 | 258 |  259 | 260 | Process on a build server could be implemented in a way, that allows to initiate release from the develop branch using optional build step: 261 | 262 |  263 | 264 | And introduce possiblility to finalize release as a optional step on a release branch: 265 | 266 |  267 | 268 | If you try to use recipes without adjustments, you will get into trouble, as almost any build server for speed and size advantages does not checkout complete repository history, thus steps will fail. 269 | 270 | For bamboo, following "hack" might be introduced: we are manually setting the new remote, with command **git remote add central "$GIT_REMOTE" **, and all subsequent operations implement with custom remote. 271 | 272 | #### deployment/release_start_bamboo.sh 273 | 274 | Please find below slightly modified release_start for bamboo: 275 | 276 | ```shell-script 277 | #!/bin/sh 278 | 279 | cd ${PWD}/../ 280 | 281 | VERSION=$1 282 | if [ -z $1 ] 283 | then 284 | VERSION=`cat version.txt` 285 | fi 286 | 287 | # PREVENT INTERACTIVE MERGE MESSAGE PROMPT 288 | GIT_MERGE_AUTOEDIT=no 289 | export GIT_MERGE_AUTOEDIT 290 | GIT_REMOTE=git@github.com:Voronenko/gitflow-release.git 291 | 292 | # add remote due to bamboo git cache shit 293 | git remote add central "$GIT_REMOTE" 294 | 295 | #Initialize gitflow 296 | git flow init -f -d 297 | 298 | # ensure you are on latest develop & master 299 | git checkout develop 300 | git pull central develop 301 | git checkout - 302 | 303 | git checkout master 304 | git pull central master 305 | git checkout develop 306 | 307 | git flow release start $VERSION 308 | 309 | # bump released version to server 310 | git push central release/$VERSION 311 | 312 | git checkout develop 313 | 314 | # COMMENT LINES BELOW IF YOU BUMP VERSION AT THE END 315 | NEXTVERSION=`./bump-version-drynext.sh` 316 | ./bump-version.sh $NEXTVERSION 317 | git commit -am "Bumps version to $NEXTVERSION" 318 | git push central develop 319 | 320 | ``` 321 | 322 | #### deployment/release_finish_bamboo.sh 323 | 324 | ```shell-script 325 | #!/bin/sh 326 | 327 | # IMPORTANT - THIS FILE IS INTENDED TO BE EXECUTED ONLY IN BAMBOO ENVIRONMENT 328 | 329 | cd ${PWD}/../ 330 | 331 | # PREVENT INTERACTIVE MERGE MESSAGE PROMPT AT A FINAL STEP 332 | GIT_MERGE_AUTOEDIT=no 333 | export GIT_MERGE_AUTOEDIT 334 | 335 | GITBRANCHFULL=`git rev-parse --abbrev-ref HEAD` 336 | GITBRANCH=`echo "$GITBRANCHFULL" | cut -d "/" -f 1` 337 | RELEASETAG=`echo "$GITBRANCHFULL" | cut -d "/" -f 2` 338 | GIT_REMOTE=git@github.com:Voronenko/gitflow-release.git 339 | 340 | echo $GITBRANCH 341 | echo $RELEASETAG 342 | 343 | if [ $GITBRANCH != "release" ] ; then 344 | echo "Release can be finished only on release branch!" 345 | return 1 346 | fi 347 | 348 | if [ -z $RELEASETAG ] 349 | then 350 | echo We expect gitflow to be followed, make sure release branch called release/x.x.x.x 351 | exit 1 352 | fi 353 | 354 | # add remote due to bamboo git cache shit 355 | git remote add central "$GIT_REMOTE" 356 | 357 | #Initialize gitflow 358 | git flow init -f -d 359 | 360 | # ensure you are on latest develop & master and return back 361 | git checkout develop 362 | git pull central develop 363 | git checkout - 364 | 365 | git checkout master 366 | git pull central master 367 | git checkout - 368 | 369 | # UNCOMMENT THESE TWO LINES IF YOU BUMP VERSION AT THE END 370 | #./bump-version.sh $RELEASETAG 371 | #git commit -am "Bumps version to $RELEASETAG" 372 | 373 | git flow release finish -m "release $RELEASETAG" $RELEASETAG 374 | 375 | git push central develop && git push central master --tags 376 | 377 | ``` 378 | 379 | ## Points of Interest 380 | 381 | Potentially, you can reuse approach to your own projects with minimal adaptation. If you would use that approach with different build server, I would be grateful if you share your experience. If you need to implement continious integration on your project - you are welcome. 382 | 383 | Mentioned samples could be seen or forked from [https://github.com/Voronenko/gitflow-release](https://github.com/Voronenko/gitflow-release) 384 | -------------------------------------------------------------------------------- /build/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Voronenko/gitflow-release/63ff2ab2eb18febe78ba9a66423a3e0b0684945e/build/.gitkeep -------------------------------------------------------------------------------- /bump-minorversion-drynext.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # credits: http://stackoverflow.com/questions/8653126/how-to-increment-version-number-in-a-shell-script 4 | # increments minor version, i.e. 0.17.1 => 0.17.2 5 | 6 | increment_version () 7 | { 8 | declare -a part=( ${1//\./ } ) 9 | declare new 10 | declare -i carry=1 11 | 12 | for (( CNTR=${#part[@]}-1; CNTR>=0; CNTR-=1 )); do 13 | len=${#part[CNTR]} 14 | new=$((part[CNTR]+carry)) 15 | [ ${#new} -gt $len ] && carry=1 || carry=0 16 | [ $CNTR -gt 0 ] && part[CNTR]=${new: -len} || part[CNTR]=${new} 17 | done 18 | new="${part[*]}" 19 | echo -e "${new// /.}" 20 | } 21 | 22 | VERSION=`cat version.txt` 23 | 24 | increment_version $VERSION 25 | -------------------------------------------------------------------------------- /bump-version-drynext.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # credits: http://stackoverflow.com/questions/8653126/how-to-increment-version-number-in-a-shell-script 4 | # increments major version and zerorifies minor, i.e. 0.17.1 => 0.18.0 5 | 6 | increment_version () 7 | { 8 | declare -a part=( ${1//\./ } ) 9 | declare new 10 | declare -i carry=1 11 | 12 | for (( CNTR=${#part[@]}-2; CNTR>=0; CNTR-=1 )); do 13 | len=${#part[CNTR]} 14 | new=$((part[CNTR]+carry)) 15 | [ ${#new} -gt $len ] && carry=1 || carry=0 16 | [ $CNTR -gt 0 ] && part[CNTR]=${new: -len} || part[CNTR]=${new} 17 | done 18 | part[2]=0 #zerorify minor version 19 | new="${part[*]}" 20 | echo -e "${new// /.}" 21 | } 22 | 23 | VERSION=`cat version.txt` 24 | 25 | increment_version $VERSION 26 | -------------------------------------------------------------------------------- /bump-version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | CURRENT_DIR=`pwd` 6 | VERSION=$1 7 | 8 | if [ ! -d "./.git" ];then cd $(git rev-parse --show-cdup); fi; 9 | 10 | echo $VERSION > version.txt 11 | 12 | #Optionally - Update your app version in app files, like package.json, bower.json , etc 13 | # Example for nodejs package.json: 14 | 15 | #sed -i.bak "s/[[:space:]]*\"version\"[[:space:]]*:[[:space:]]*\".*\",/ \"version\":\"$VERSION\",/g" $CURRENT_DIR/package.json 16 | #rm $CURRENT_DIR/package.json.bak || true 17 | -------------------------------------------------------------------------------- /deployment-bump-at-start/auto_confict_resolve.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | if [ ! -d "./.git" ];then cd $(git rev-parse --show-cdup); fi; 6 | 7 | FILES_IN_CONFLICT=`git diff --name-only --diff-filter=U | wc -l` 8 | echo "Conflicted files: $FILES_IN_CONFLICT" 9 | 10 | if [ $FILES_IN_CONFLICT -gt 2 ] ; then 11 | echo "Looks like hotfix introduced conflicts( $FILES_IN_CONFLICT ). Please resolve manually" 12 | exit 1 13 | fi 14 | 15 | if [ "$FILES_IN_CONFLICT" = "2" ] ; then 16 | 17 | VERSION_IN_CONFLICT=`git diff --name-only --diff-filter=U | grep version.txt` 18 | if [ "$VERSION_IN_CONFLICT" = "version.txt" ] ; then 19 | git checkout --ours version.txt 20 | git add version.txt 21 | fi 22 | 23 | PACKAGE_JSON_IN_CONFLICT=`git diff --name-only --diff-filter=U | grep package.json` 24 | if [ "$PACKAGE_JSON_IN_CONFLICT" = "package.json" ] ; then 25 | git checkout --ours package.json 26 | git add package.json 27 | fi 28 | 29 | git commit -am "automatic version fix by hotfix-finish routine" 30 | 31 | fi 32 | 33 | FILES_IN_CONFLICT=`git diff --name-only --diff-filter=U | wc -l` 34 | 35 | if [ "$FILES_IN_CONFLICT" = "0" ] ; then 36 | echo "EVERYTHING SMOOTHLY - NO CONFLICTS" 37 | fi 38 | 39 | if [ "$FILES_IN_CONFLICT" != "0" ] ; then 40 | echo "PROBLEM: STILL FILES IN CONFLICT" 41 | git diff --name-only --diff-filter=U 42 | exit 1 43 | fi 44 | 45 | 46 | git push central develop && git push central master --tags 47 | -------------------------------------------------------------------------------- /deployment-bump-at-start/hotfix_finish_bamboo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | # IMPORTANT - THIS FILE IS INTENDED TO BE EXECUTED ONLY IN BAMBOO ENVIRONMENT 6 | 7 | if [ ! -d "./.git" ];then cd $(git rev-parse --show-cdup); fi; 8 | 9 | # PREVENT INTERACTIVE MERGE MESSAGE PROMPT AT A FINAL STEP 10 | GIT_MERGE_AUTOEDIT=no 11 | export GIT_MERGE_AUTOEDIT 12 | 13 | GITBRANCHFULL=`git rev-parse --abbrev-ref HEAD` 14 | GITBRANCH=`echo "$GITBRANCHFULL" | cut -d "/" -f 1` 15 | HOTFIXTAG=`echo "$GITBRANCHFULL" | cut -d "/" -f 2` 16 | 17 | echo $GITBRANCH 18 | echo $HOTFIXTAG 19 | 20 | if [ $GITBRANCH != "hotfix" ] ; then 21 | echo "Hotfix can be finished only on hotfix branch!" 22 | return 1 23 | fi 24 | 25 | if [ -z $HOTFIXTAG ] 26 | then 27 | echo We expect gitflow to be followed, make sure hotfix branch called hotfix/ISSUE_NUMBER 28 | exit 1 29 | fi 30 | 31 | 32 | # add remote due to bamboo git cache shit 33 | git remote add central "git@github.com:Voronenko/gitflow-release.git" || true 34 | 35 | #Initialize gitflow 36 | git flow init -f -d 37 | 38 | # ensure you are on latest develop & master and return back 39 | git checkout develop 40 | git pull central develop 41 | git checkout - 42 | 43 | git checkout master 44 | git pull central master 45 | git checkout - 46 | 47 | set +e 48 | git checkout develop 49 | git merge $GITBRANCHFULL 50 | set -e 51 | 52 | # attempt automatic conflict resolve 53 | 54 | FILES_IN_CONFLICT=`git diff --name-only --diff-filter=U | wc -l` 55 | echo "Conflicted files: $FILES_IN_CONFLICT" 56 | 57 | if [ $FILES_IN_CONFLICT -gt 2 ] ; then 58 | echo "Looks like hotfix introduced conflicts( $FILES_IN_CONFLICT ). Please resolve manually" 59 | exit 1 60 | fi 61 | 62 | if [ "$FILES_IN_CONFLICT" = "2" ] ; then 63 | 64 | VERSION_IN_CONFLICT=`git diff --name-only --diff-filter=U | grep version.txt` 65 | if [ "$VERSION_IN_CONFLICT" = "version.txt" ] ; then 66 | git checkout --ours version.txt 67 | git add version.txt 68 | fi 69 | 70 | PACKAGE_JSON_IN_CONFLICT=`git diff --name-only --diff-filter=U | grep package.json` 71 | if [ "$PACKAGE_JSON_IN_CONFLICT" = "package.json" ] ; then 72 | git checkout --ours package.json 73 | git add package.json 74 | fi 75 | 76 | git commit -am "automatic version fix by hotfix-finish routine" 77 | 78 | fi 79 | 80 | FILES_IN_CONFLICT=`git diff --name-only --diff-filter=U | wc -l` 81 | 82 | if [ "$FILES_IN_CONFLICT" = "0" ] ; then 83 | echo "EVERYTHING SMOOTHLY - NO CONFLICTS" 84 | fi 85 | 86 | if [ "$FILES_IN_CONFLICT" != "0" ] ; then 87 | echo "PROBLEM: STILL FILES IN CONFLICT" 88 | git diff --name-only --diff-filter=U 89 | git reset --hard 90 | exit 1 91 | fi 92 | 93 | git checkout $GITBRANCHFULL 94 | 95 | git flow hotfix finish -m "hotfix $HOTFIXTAG" $HOTFIXTAG 96 | 97 | 98 | git push central develop && git push central master --tags 99 | -------------------------------------------------------------------------------- /deployment-bump-at-start/hotfix_start_bamboo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | if [ ! -d "./.git" ];then cd $(git rev-parse --show-cdup); fi; 6 | 7 | VERSION=$1 8 | if [ -z $1 ] 9 | then 10 | echo "Please provide uniqie hotfix name. Jira ticket number is a good candidate" 11 | exit 1 12 | fi 13 | 14 | # PREVENT INTERACTIVE MERGE MESSAGE PROMPT 15 | GIT_MERGE_AUTOEDIT=no 16 | export GIT_MERGE_AUTOEDIT 17 | 18 | # add remote due to bamboo git cache shit 19 | git remote add central "git@github.com:Voronenko/gitflow-release.git" || true 20 | 21 | #Initialize gitflow 22 | git flow init -f -d 23 | 24 | # ensure you are on latest develop & master 25 | git checkout develop 26 | git pull central develop 27 | git checkout - 28 | 29 | git checkout master 30 | git pull central master 31 | git checkout develop 32 | 33 | git flow hotfix start $VERSION 34 | 35 | NEXTVERSION=`./bump-minorversion-drynext.sh` 36 | ./bump-version.sh $NEXTVERSION 37 | git commit -am "Bumps version to $NEXTVERSION" 38 | 39 | # bump hotfixed version to server 40 | git push central hotfix/$VERSION 41 | -------------------------------------------------------------------------------- /deployment-bump-at-start/release_finish_bamboo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # IMPORTANT - THIS FILE IS INTENDED TO BE EXECUTED ONLY IN BAMBOO ENVIRONMENT 4 | 5 | set -e 6 | 7 | if [ ! -d "./.git" ];then cd $(git rev-parse --show-cdup); fi; 8 | 9 | # PREVENT INTERACTIVE MERGE MESSAGE PROMPT AT A FINAL STEP 10 | GIT_MERGE_AUTOEDIT=no 11 | export GIT_MERGE_AUTOEDIT 12 | 13 | GITBRANCHFULL=`git rev-parse --abbrev-ref HEAD` 14 | GITBRANCH=`echo "$GITBRANCHFULL" | cut -d "/" -f 1` 15 | RELEASETAG=`echo "$GITBRANCHFULL" | cut -d "/" -f 2` 16 | 17 | echo $GITBRANCH 18 | echo $RELEASETAG 19 | 20 | if [ $GITBRANCH != "release" ] ; then 21 | echo "Release can be finished only on release branch!" 22 | return 1 23 | fi 24 | 25 | if [ -z $RELEASETAG ] 26 | then 27 | echo We expect gitflow to be followed, make sure release branch called release/x.x.x.x 28 | exit 1 29 | fi 30 | 31 | 32 | # add remote due to bamboo git cache shit 33 | git remote add central "git@github.com:Voronenko/gitflow-release.git" || true 34 | 35 | #Initialize gitflow 36 | git flow init -f -d 37 | 38 | # ensure you are on latest develop & master and return back 39 | git checkout develop 40 | git pull central develop 41 | git checkout - 42 | 43 | git checkout master 44 | git pull central master 45 | git checkout - 46 | 47 | # UNCOMMENT THESE TWO LINES IF YOU BUMP VERSION AT THE END 48 | #./bump-version.sh $RELEASETAG 49 | #git commit -am "Bumps version to $RELEASETAG" 50 | 51 | git flow release finish -m "release $RELEASETAG" $RELEASETAG 52 | 53 | git push central develop && git push central master --tags 54 | -------------------------------------------------------------------------------- /deployment-bump-at-start/release_start_bamboo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | if [ ! -d "./.git" ];then cd $(git rev-parse --show-cdup); fi; 6 | 7 | VERSION=$1 8 | if [ -z $1 ] 9 | then 10 | VERSION=`cat version.txt` 11 | fi 12 | 13 | # PREVENT INTERACTIVE MERGE MESSAGE PROMPT 14 | GIT_MERGE_AUTOEDIT=no 15 | export GIT_MERGE_AUTOEDIT 16 | 17 | # add remote due to bamboo git cache shit 18 | git remote add central "git@github.com:Voronenko/gitflow-release.git" || true 19 | 20 | #Initialize gitflow 21 | git flow init -f -d 22 | 23 | # ensure you are on latest develop & master 24 | git checkout develop 25 | git pull central develop 26 | git checkout - 27 | 28 | git checkout master 29 | git pull central master 30 | git checkout develop 31 | 32 | git flow release start $VERSION 33 | 34 | # bump released version to server 35 | git push central release/$VERSION 36 | 37 | git checkout develop 38 | 39 | # COMMENT LINES BELOW IF YOU BUMP VERSION AT THE END 40 | NEXTVERSION=`./bump-version-drynext.sh` 41 | ./bump-version.sh $NEXTVERSION 42 | git commit -am "Bumps version to $NEXTVERSION" 43 | git push central develop 44 | -------------------------------------------------------------------------------- /deployment-single-makefile/Makefile: -------------------------------------------------------------------------------- 1 | # Make gitflow helper https://github.com/Voronenko/gitflow-release 2 | python = python2.7 3 | SHELL=/bin/bash 4 | MAKE_HELPER := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))/make_helper.sh 5 | 6 | PROJECT_NAME=project-name 7 | PROJECT_VERSION=$(shell cat $(PWD)/version.txt) 8 | 9 | .PHONY: info build package 10 | 11 | info: 12 | @echo $(PROJECT_VERSION) 13 | 14 | build: 15 | @./clean_build.sh 16 | 17 | test: 18 | @echo "Add tests there if you have any" 19 | 20 | package: 21 | @PROJECT_NAME=$(PROJECT_NAME) PROJECT_VERSION=$(PROJECT_VERSION) $(MAKE_HELPER) package 22 | 23 | unpackage: 24 | @$(MAKE_HELPER) unpackage $(PROJECT_NAME) 25 | 26 | release-start: 27 | @$(MAKE_HELPER) gitflow_release_start 28 | 29 | release-finish: 30 | @$(MAKE_HELPER) gitflow_release_finish 31 | 32 | hotfix-start: 33 | @$(MAKE_HELPER) gitflow_hotfix_start $(filter-out $@,$(MAKECMDGOALS)) 34 | 35 | hotfix-finish: 36 | @$(MAKE_HELPER) gitflow_hotfix_finish 37 | 38 | %: # a bit hackish way 39 | @: # to pass parameters from command line to action 40 | -------------------------------------------------------------------------------- /deployment-single-makefile/Readme.md: -------------------------------------------------------------------------------- 1 | # Boilerplate usage 2 | 3 | 1. Implement project specific `clean_build.sh` to build project artifact inside `/build` folder. 4 | 5 | 2. Put semantic version file `version.txt` in the root (starting with `0.0.1` at the beginning of the development) 6 | 7 | 3. If you want to write project version into some custom files - adjust `bump_version` inside `make_helper.sh` 8 | 9 | 4. Adjust Makefile, set `PROJECT_NAME` constant to match project name 10 | 11 | 5. make file actions 12 | 13 | 5.1 `make build` - builds project (by invoking `clean_build.sh`) 14 | 15 | 5.2 `make test` - if implemented, runs tests over project 16 | 17 | 5.3 `make package $suffix` - packages artifact into `${PROJECT_NAME}(${PROJECT_VERSION}${SUFFIX}.tgz` , suffix optional, can be build number, if you need to distinguish artifacts between builds. In other case, build overwrites previous artifact. Make sure you've build project before. 18 | 19 | 5.4 `make unpackage` - looks for last file that matches mask `${PROJECT_NAME}(${PROJECT_VERSION}${SUFFIX}.tgz` and unpacks it. 20 | 21 | 5.5 `make release-start` - starts release from develop branch via `gitflow release start` 22 | 23 | 5.6 `make release-finish` - finishes release from release branch via `gitflow release finish` 24 | 25 | 5.7 `make hotfix-start HOTFIX_NAME` - starts hotfix named HOTFIX_NAME from master branch via `gitflow hotfix start` 26 | 27 | 5.8 `make hotfix-finish` - finishes hotfix from hotfix branch via `gitflow hotfix finish` 28 | -------------------------------------------------------------------------------- /deployment-single-makefile/clean_build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | exists() 4 | { 5 | command -v "$1" >/dev/null 2>&1 6 | } 7 | 8 | . ~/.nvm/nvm.sh 9 | 10 | node_version="$(nvm version)" 11 | nvmrc_path="$(nvm_find_nvmrc)" 12 | 13 | npm=npm 14 | 15 | if [ -n "$nvmrc_path" ]; then 16 | nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")") 17 | 18 | if [ "$nvmrc_node_version" != "N/A" ] && [ "$nvmrc_node_version" != "$node_version" ]; then 19 | nvm use 20 | fi 21 | elif [ "$node_version" != "$(nvm version default)" ]; then 22 | echo "Reverting to nvm default version" 23 | nvm use default 24 | fi 25 | 26 | node --version 27 | 28 | if exists yarn; then 29 | echo 'Yarn exists!' 30 | else 31 | echo 'Your system does not have Yarn, installing' 32 | npm install -g yarn 33 | fi 34 | 35 | yarn 36 | if [ $? -eq 0 ]; then 37 | echo yarn reports node version ok 38 | npm=yarn 39 | else 40 | echo yarn does not like your node version, using native npm 41 | fi 42 | 43 | 44 | rm -rf ./node_modules 45 | $npm install 46 | cp -r bin build 47 | cp -r node_modules build 48 | cp -r public build 49 | cp -r routes build 50 | cp -r views build 51 | cp app.js build 52 | -------------------------------------------------------------------------------- /deployment-single-makefile/make_helper.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | function bump_version(){ 6 | 7 | if [ -z "$1" ] 8 | then 9 | echo "Pass version as param 1" 10 | return 1 11 | fi 12 | 13 | CURRENT_DIR=`pwd` 14 | VERSION=$1 15 | 16 | if [ ! -d "./.git" ];then cd $(git rev-parse --show-cdup); fi; 17 | 18 | echo $VERSION > version.txt 19 | 20 | #Optionally - Update your app version in app files, like package.json, bower.json , etc 21 | # Example for nodejs package.json: 22 | 23 | #sed -i.bak "s/[[:space:]]*\"version\"[[:space:]]*:[[:space:]]*\".*\",/ \"version\":\"$VERSION\",/g" $CURRENT_DIR/package.json 24 | #rm $CURRENT_DIR/package.json.bak || true 25 | 26 | 27 | } 28 | 29 | 30 | 31 | # ================================================= 32 | # BELOW THIS LINE STARTS UNCHANGABLE PART OF SCRIPT 33 | # ================================================= 34 | 35 | # ===================================== 36 | # 0.0.1 => 0.0.2 37 | function _bump_minor_version_dry(){ 38 | if [ -z "$1" ] 39 | then 40 | echo "Pass version as param 1" 41 | return 1 42 | fi 43 | 44 | declare -a part=( ${1//\./ } ) 45 | declare new 46 | declare -i carry=1 47 | 48 | for (( CNTR=${#part[@]}-1; CNTR>=0; CNTR-=1 )); do 49 | len=${#part[CNTR]} 50 | new=$((part[CNTR]+carry)) 51 | [ ${#new} -gt $len ] && carry=1 || carry=0 52 | [ $CNTR -gt 0 ] && part[CNTR]=${new: -len} || part[CNTR]=${new} 53 | done 54 | new="${part[*]}" 55 | echo -e "${new// /.}" 56 | } 57 | 58 | # ===================================== 59 | # 0.0.1 => 0.1.0 60 | 61 | function _bump_version_dry(){ 62 | if [ -z "$1" ] 63 | then 64 | echo "Pass version as param 1" 65 | return 1 66 | fi 67 | 68 | declare -a part=( ${1//\./ } ) 69 | declare new 70 | declare -i carry=1 71 | 72 | for (( CNTR=${#part[@]}-2; CNTR>=0; CNTR-=1 )); do 73 | len=${#part[CNTR]} 74 | new=$((part[CNTR]+carry)) 75 | [ ${#new} -gt $len ] && carry=1 || carry=0 76 | [ $CNTR -gt 0 ] && part[CNTR]=${new: -len} || part[CNTR]=${new} 77 | done 78 | part[2]=0 #zerorify minor version 79 | new="${part[*]}" 80 | echo -e "${new// /.}" 81 | } 82 | 83 | # ===================================== 84 | 85 | function package(){ 86 | if [ -z "$1" ] 87 | then 88 | SUFFIX="" 89 | else 90 | SUFFIX="-$1" 91 | fi 92 | 93 | if [ -z "$PROJECT_NAME" ] 94 | then 95 | echo "Please set PROJECT_NAME" 96 | return 1 97 | fi 98 | 99 | if [ -z "$PROJECT_VERSION" ] 100 | then 101 | echo "Please set PROJECT_VERSION" 102 | return 1 103 | fi 104 | 105 | 106 | echo "Packaging ${PROJECT_NAME}(${PROJECT_VERSION}${SUFFIX})" 107 | 108 | rm -rf ./build || true 109 | rm -f ${PROJECT_NAME}-*.tgz || true 110 | mkdir -p ./build || true 111 | 112 | GITCOMMIT=`git rev-parse --short HEAD` 113 | GITTAG=`git describe --exact-match --tags $(git log -n1 --pretty='%h') 2>/dev/null || true` 114 | DATE=`date +%Y-%m-%d:%H:%M:%S` 115 | 116 | echo "major_version=${PROJECT_VERSION}" > build/version.txt 117 | echo "minor_version=$1" >> build/version.txt 118 | echo "git_hash=$GITCOMMIT" >> build/version.txt 119 | echo "git_tag=$GITTAG" >> build/version.txt 120 | echo "built=$DATE" >> build/version.txt 121 | 122 | echo PRODUCING ARTIFACT ${PROJECT_NAME}-${PROJECT_VERSION}$SUFFIX.tgz in build/ 123 | cd build && tar cfz ../${PROJECT_NAME}-${PROJECT_VERSION}$SUFFIX.tgz . 124 | 125 | } 126 | 127 | # ===================================== 128 | 129 | function unpackage(){ 130 | if [ -z "$1" ] 131 | then 132 | echo "Please pass PROJECT_NAME as parameter" 133 | return 1 134 | else 135 | PROJECT_NAME="$1" 136 | fi 137 | 138 | current_artefact=$(find ./${PROJECT_NAME}*.tgz -type f -exec stat -c "%n" {} + | sort | head -n1) 139 | echo Working with artefact: $current_artefact 140 | tar xvzf $current_artefact 141 | echo artefact unpacked: $current_artefact 142 | } 143 | 144 | 145 | # =GITFLOW SUPPORT================================== 146 | 147 | function gitflow_release_start(){ 148 | if [ ! -d "./.git" ];then cd $(git rev-parse --show-cdup); fi; 149 | VERSION=$1 150 | if [ -z $1 ] 151 | then 152 | VERSION=`cat version.txt` 153 | fi 154 | 155 | #Initialize gitflow 156 | git flow init -f -d 157 | 158 | # ensure you are on latest develop & master 159 | git checkout develop 160 | git pull origin develop 161 | git checkout - 162 | 163 | git checkout master 164 | git pull origin master 165 | git checkout develop 166 | 167 | git flow release start $VERSION 168 | 169 | # bump released version to server 170 | git push 171 | 172 | git checkout develop 173 | 174 | # COMMENT LINES BELOW IF YOU BUMP VERSION AT THE END 175 | NEXTVERSION=$(_bump_version_dry $VERSION) 176 | $(bump_version $NEXTVERSION) 177 | 178 | git commit -am "Bumps version to $NEXTVERSION" 179 | git push origin develop 180 | 181 | # return to release version for further operations 182 | git checkout - 183 | } 184 | 185 | function gitflow_release_finish(){ 186 | 187 | if [ ! -d "./.git" ];then cd $(git rev-parse --show-cdup); fi; 188 | 189 | # PREVENT INTERACTIVE MERGE MESSAGE PROMPT AT A FINAL STEP 190 | GIT_MERGE_AUTOEDIT=no 191 | export GIT_MERGE_AUTOEDIT 192 | 193 | GITBRANCHFULL=`git rev-parse --abbrev-ref HEAD` 194 | GITBRANCH=`echo "$GITBRANCHFULL" | cut -d "/" -f 1` 195 | RELEASETAG=`echo "$GITBRANCHFULL" | cut -d "/" -f 2` 196 | 197 | echo $GITBRANCH 198 | echo $RELEASETAG 199 | 200 | if [ $GITBRANCH != "release" ] ; then 201 | echo "Release can be finished only on release branch!" 202 | return 1 203 | fi 204 | 205 | if [ -z $RELEASETAG ] 206 | then 207 | echo We expect gitflow to be followed, make sure release branch called release/x.x.x 208 | exit 1 209 | fi 210 | 211 | #Initialize gitflow 212 | git flow init -f -d 213 | 214 | # ensure you are on latest develop & master and return back 215 | git checkout develop 216 | git pull origin develop 217 | git checkout - 218 | 219 | git checkout master 220 | git pull origin master 221 | git checkout - 222 | 223 | # UNCOMMENT THESE TWO LINES IF YOU BUMP VERSION AT THE END 224 | #./bump-version.sh $RELEASETAG 225 | #git commit -am "Bumps version to $RELEASETAG" 226 | 227 | git flow release finish -m "release $RELEASETAG" $RELEASETAG 228 | 229 | git push origin develop && git push origin master --tags 230 | 231 | 232 | } 233 | 234 | 235 | function gitflow_hotfix_start(){ 236 | if [ ! -d "./.git" ];then cd $(git rev-parse --show-cdup); fi; 237 | 238 | if [ -z $1 ] 239 | then 240 | echo "Please provide uniqie hotfix name. Jira ticket number is a good candidate" 241 | exit 1 242 | else 243 | HOTFIX_NAME=$1 244 | fi 245 | 246 | if [ -z $2 ] 247 | then 248 | VERSION=`cat version.txt` 249 | NEXTVERSION=$(_bump_minor_version_dry $VERSION) 250 | $(bump_version $NEXTVERSION) 251 | else 252 | NEXTVERSION=$2 253 | fi 254 | 255 | #Initialize gitflow 256 | git flow init -f -d 257 | 258 | # ensure you are on latest develop & master 259 | git checkout develop 260 | git pull origin develop 261 | git checkout - 262 | 263 | git checkout master 264 | git pull origin master 265 | git checkout develop 266 | 267 | git flow hotfix start $HOTFIX_NAME 268 | 269 | git commit -am "Bumps version to $NEXTVERSION" 270 | 271 | # bump hotfix version to server 272 | git push 273 | } 274 | 275 | function gitflow_hotfix_finish(){ 276 | 277 | if [ ! -d "./.git" ];then cd $(git rev-parse --show-cdup); fi; 278 | 279 | # PREVENT INTERACTIVE MERGE MESSAGE PROMPT AT A FINAL STEP 280 | GIT_MERGE_AUTOEDIT=no 281 | export GIT_MERGE_AUTOEDIT 282 | 283 | GITBRANCHFULL=`git rev-parse --abbrev-ref HEAD` 284 | GITBRANCH=`echo "$GITBRANCHFULL" | cut -d "/" -f 1` 285 | HOTFIXTAG=`echo "$GITBRANCHFULL" | cut -d "/" -f 2` 286 | 287 | echo $GITBRANCH 288 | echo $HOTFIXTAG 289 | 290 | if [ $GITBRANCH != "hotfix" ] ; then 291 | echo "Hotfix can be finished only on a hotfix branch!" 292 | return 1 293 | fi 294 | 295 | if [ -z $HOTFIXTAG ] 296 | then 297 | echo We expect gitflow to be followed, make sure hotfix branch called hotfix/x.x.x.x 298 | exit 1 299 | fi 300 | 301 | #Initialize gitflow 302 | git flow init -f -d 303 | 304 | # ensure you are on latest develop & master and return back 305 | git checkout develop 306 | git pull origin develop 307 | git checkout - 308 | 309 | git checkout master 310 | git pull origin master 311 | git checkout - 312 | 313 | git flow hotfix finish -m "hotfix $HOTFIXTAG" $HOTFIXTAG 314 | 315 | git push origin develop && git push origin master --tags 316 | 317 | } 318 | 319 | # Allows to call a function based on arguments passed to the script 320 | # ./make_helper.sh package "243" 321 | $* 322 | -------------------------------------------------------------------------------- /deployment/hotfix_finish.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ ! -d "./.git" ];then cd $(git rev-parse --show-cdup); fi; 4 | 5 | # PREVENT INTERACTIVE MERGE MESSAGE PROMPT AT A FINAL STEP 6 | GIT_MERGE_AUTOEDIT=no 7 | export GIT_MERGE_AUTOEDIT 8 | 9 | GITBRANCHFULL=`git rev-parse --abbrev-ref HEAD` 10 | GITBRANCH=`echo "$GITBRANCHFULL" | cut -d "/" -f 1` 11 | HOTFIXTAG=`echo "$GITBRANCHFULL" | cut -d "/" -f 2` 12 | 13 | echo $GITBRANCH 14 | echo $HOTFIXTAG 15 | 16 | if [ $GITBRANCH != "hotfix" ] ; then 17 | echo "Hotfix can be finished only on a hotfix branch!" 18 | return 1 19 | fi 20 | 21 | if [ -z $HOTFIXTAG ] 22 | then 23 | echo We expect gitflow to be followed, make sure hotfix branch called hotfix/x.x.x.x 24 | exit 1 25 | fi 26 | 27 | #Initialize gitflow 28 | git flow init -f -d 29 | 30 | # ensure you are on latest develop & master and return back 31 | git checkout develop 32 | git pull origin develop 33 | git checkout - 34 | 35 | git checkout master 36 | git pull origin master 37 | git checkout - 38 | 39 | git flow hotfix finish -m "hotfix $HOTFIXTAG" $HOTFIXTAG 40 | 41 | git push origin develop && git push origin master --tags 42 | -------------------------------------------------------------------------------- /deployment/hotfix_finish_bamboo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # IMPORTANT - THIS FILE IS INTENDED TO BE EXECUTED ONLY IN BAMBOO ENVIRONMENT 4 | 5 | if [ ! -d "./.git" ];then cd $(git rev-parse --show-cdup); fi; 6 | 7 | # PREVENT INTERACTIVE MERGE MESSAGE PROMPT AT A FINAL STEP 8 | GIT_MERGE_AUTOEDIT=no 9 | export GIT_MERGE_AUTOEDIT 10 | 11 | GITBRANCHFULL=`git rev-parse --abbrev-ref HEAD` 12 | GITBRANCH=`echo "$GITBRANCHFULL" | cut -d "/" -f 1` 13 | HOTFIXTAG=`echo "$GITBRANCHFULL" | cut -d "/" -f 2` 14 | GIT_REMOTE=git@github.com:Voronenko/bamboo-release.git 15 | 16 | echo $GITBRANCH 17 | echo $HOTFIXTAG 18 | 19 | if [ $GITBRANCH != "hotfix" ] ; then 20 | echo "Hotfix can be finished only on hotfix branch!" 21 | return 1 22 | fi 23 | 24 | if [ -z $HOTFIXTAG ] 25 | then 26 | echo We expect gitflow to be followed, make sure hotfix branch called hotfix/ISSUE_NUMBER 27 | exit 1 28 | fi 29 | 30 | # add remote due to bamboo git cache shit 31 | git remote add central "$GIT_REMOTE" 32 | 33 | #Initialize gitflow 34 | git flow init -f -d 35 | 36 | # ensure you are on latest develop & master and return back 37 | git checkout develop 38 | git pull central develop 39 | git checkout - 40 | 41 | git checkout master 42 | git pull central master 43 | git checkout - 44 | 45 | git flow hotfix finish -m "hotfix $HOTFIXTAG" $HOTFIXTAG 46 | 47 | git push central develop && git push central master --tags 48 | -------------------------------------------------------------------------------- /deployment/hotfix_start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ ! -d "./.git" ];then cd $(git rev-parse --show-cdup); fi; 4 | 5 | VERSION=$1 6 | if [ -z $1 ] 7 | then 8 | echo "Please provide uniqie hotfix name. Jira ticket number is a good candidate" 9 | exit 1 10 | fi 11 | 12 | #Initialize gitflow 13 | git flow init -f -d 14 | 15 | # ensure you are on latest develop & master 16 | git checkout develop 17 | git pull origin develop 18 | git checkout - 19 | 20 | git checkout master 21 | git pull origin master 22 | git checkout develop 23 | 24 | git flow hotfix start $VERSION 25 | 26 | NEXTVERSION=`./bump-minorversion-drynext.sh` 27 | ./bump-version.sh $NEXTVERSION 28 | git commit -am "Bumps version to $NEXTVERSION" 29 | 30 | 31 | # bump hotfix version to server 32 | git push 33 | -------------------------------------------------------------------------------- /deployment/hotfix_start_bamboo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ ! -d "./.git" ];then cd $(git rev-parse --show-cdup); fi; 4 | 5 | VERSION=$1 6 | if [ -z $1 ] 7 | then 8 | echo "Please provide uniqie hotfix name. Jira ticket number is a good candidate" 9 | exit 1 10 | fi 11 | 12 | # PREVENT INTERACTIVE MERGE MESSAGE PROMPT 13 | GIT_MERGE_AUTOEDIT=no 14 | export GIT_MERGE_AUTOEDIT 15 | GIT_REMOTE=git@github.com:Voronenko/bamboo-release.git 16 | 17 | # add remote due to bamboo git cache shit 18 | git remote add central "$GIT_REMOTE" 19 | 20 | #Initialize gitflow 21 | git flow init -f -d 22 | 23 | # ensure you are on latest develop & master 24 | git checkout develop 25 | git pull central develop 26 | git checkout - 27 | 28 | git checkout master 29 | git pull central master 30 | git checkout develop 31 | 32 | git flow hotfix start $VERSION 33 | 34 | NEXTVERSION=`./bump-minorversion-drynext.sh` 35 | ./bump-version.sh $NEXTVERSION 36 | git commit -am "Bumps version to $NEXTVERSION" 37 | 38 | # bump hotfixed version to server 39 | git push central hotfix/$VERSION 40 | -------------------------------------------------------------------------------- /deployment/release_finish.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ ! -d "./.git" ];then cd $(git rev-parse --show-cdup); fi; 4 | 5 | # PREVENT INTERACTIVE MERGE MESSAGE PROMPT AT A FINAL STEP 6 | GIT_MERGE_AUTOEDIT=no 7 | export GIT_MERGE_AUTOEDIT 8 | 9 | GITBRANCHFULL=`git rev-parse --abbrev-ref HEAD` 10 | GITBRANCH=`echo "$GITBRANCHFULL" | cut -d "/" -f 1` 11 | RELEASETAG=`echo "$GITBRANCHFULL" | cut -d "/" -f 2` 12 | 13 | echo $GITBRANCH 14 | echo $RELEASETAG 15 | 16 | if [ $GITBRANCH != "release" ] ; then 17 | echo "Release can be finished only on release branch!" 18 | return 1 19 | fi 20 | 21 | if [ -z $RELEASETAG ] 22 | then 23 | echo We expect gitflow to be followed, make sure release branch called release/x.x.x 24 | exit 1 25 | fi 26 | 27 | #Initialize gitflow 28 | git flow init -f -d 29 | 30 | # ensure you are on latest develop & master and return back 31 | git checkout develop 32 | git pull origin develop 33 | git checkout - 34 | 35 | git checkout master 36 | git pull origin master 37 | git checkout - 38 | 39 | # UNCOMMENT THESE TWO LINES IF YOU BUMP VERSION AT THE END 40 | #./bump-version.sh $RELEASETAG 41 | #git commit -am "Bumps version to $RELEASETAG" 42 | 43 | git flow release finish -m "release $RELEASETAG" $RELEASETAG 44 | 45 | git push origin develop && git push origin master --tags 46 | -------------------------------------------------------------------------------- /deployment/release_finish_bamboo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # IMPORTANT - THIS FILE IS INTENDED TO BE EXECUTED ONLY IN BAMBOO ENVIRONMENT 4 | 5 | if [ ! -d "./.git" ];then cd $(git rev-parse --show-cdup); fi; 6 | 7 | # PREVENT INTERACTIVE MERGE MESSAGE PROMPT AT A FINAL STEP 8 | GIT_MERGE_AUTOEDIT=no 9 | export GIT_MERGE_AUTOEDIT 10 | 11 | GITBRANCHFULL=`git rev-parse --abbrev-ref HEAD` 12 | GITBRANCH=`echo "$GITBRANCHFULL" | cut -d "/" -f 1` 13 | RELEASETAG=`echo "$GITBRANCHFULL" | cut -d "/" -f 2` 14 | GIT_REMOTE=git@github.com:Voronenko/gitflow-release.git 15 | 16 | echo $GITBRANCH 17 | echo $RELEASETAG 18 | 19 | if [ $GITBRANCH != "release" ] ; then 20 | echo "Release can be finished only on release branch!" 21 | return 1 22 | fi 23 | 24 | if [ -z $RELEASETAG ] 25 | then 26 | echo We expect gitflow to be followed, make sure release branch called release/x.x.x.x 27 | exit 1 28 | fi 29 | 30 | # add remote due to bamboo git cache shit 31 | git remote add central "$GIT_REMOTE" 32 | 33 | #Initialize gitflow 34 | git flow init -f -d 35 | 36 | # ensure you are on latest develop & master and return back 37 | git checkout develop 38 | git pull central develop 39 | git checkout - 40 | 41 | git checkout master 42 | git pull central master 43 | git checkout - 44 | 45 | # UNCOMMENT THESE TWO LINES IF YOU BUMP VERSION AT THE END 46 | #./bump-version.sh $RELEASETAG 47 | #git commit -am "Bumps version to $RELEASETAG" 48 | 49 | git flow release finish -m "release $RELEASETAG" $RELEASETAG 50 | 51 | git push central develop && git push central master --tags 52 | -------------------------------------------------------------------------------- /deployment/release_start.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ ! -d "./.git" ];then cd $(git rev-parse --show-cdup); fi; 4 | VERSION=$1 5 | if [ -z $1 ] 6 | then 7 | VERSION=`cat version.txt` 8 | fi 9 | 10 | #Initialize gitflow 11 | git flow init -f -d 12 | 13 | # ensure you are on latest develop & master 14 | git checkout develop 15 | git pull origin develop 16 | git checkout - 17 | 18 | git checkout master 19 | git pull origin master 20 | git checkout develop 21 | 22 | git flow release start $VERSION 23 | 24 | # bump released version to server 25 | git push 26 | 27 | git checkout develop 28 | 29 | # COMMENT LINES BELOW IF YOU BUMP VERSION AT THE END 30 | NEXTVERSION=`./bump-version-drynext.sh` 31 | ./bump-version.sh $NEXTVERSION 32 | git commit -am "Bumps version to $NEXTVERSION" 33 | git push origin develop 34 | -------------------------------------------------------------------------------- /deployment/release_start_bamboo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ ! -d "./.git" ];then cd $(git rev-parse --show-cdup); fi; 4 | 5 | VERSION=$1 6 | if [ -z $1 ] 7 | then 8 | VERSION=`cat version.txt` 9 | fi 10 | 11 | # PREVENT INTERACTIVE MERGE MESSAGE PROMPT 12 | GIT_MERGE_AUTOEDIT=no 13 | export GIT_MERGE_AUTOEDIT 14 | GIT_REMOTE=git@github.com:Voronenko/bamboo-release.git 15 | 16 | # add remote due to bamboo git cache shit 17 | git remote add central "$GIT_REMOTE" 18 | 19 | #Initialize gitflow 20 | git flow init -f -d 21 | 22 | # ensure you are on latest develop & master 23 | git checkout develop 24 | git pull central develop 25 | git checkout - 26 | 27 | git checkout master 28 | git pull central master 29 | git checkout develop 30 | 31 | git flow release start $VERSION 32 | 33 | # bump released version to server 34 | git push central release/$VERSION 35 | 36 | git checkout develop 37 | 38 | # COMMENT LINES BELOW IF YOU BUMP VERSION AT THE END 39 | NEXTVERSION=`./bump-version-drynext.sh` 40 | ./bump-version.sh $NEXTVERSION 41 | git commit -am "Bumps version to $NEXTVERSION" 42 | git push central develop 43 | -------------------------------------------------------------------------------- /images/bamboo_release_branch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Voronenko/gitflow-release/63ff2ab2eb18febe78ba9a66423a3e0b0684945e/images/bamboo_release_branch.png -------------------------------------------------------------------------------- /images/bamboo_release_finish.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Voronenko/gitflow-release/63ff2ab2eb18febe78ba9a66423a3e0b0684945e/images/bamboo_release_finish.png -------------------------------------------------------------------------------- /images/bamboo_release_start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Voronenko/gitflow-release/63ff2ab2eb18febe78ba9a66423a3e0b0684945e/images/bamboo_release_start.png -------------------------------------------------------------------------------- /images/git-workflow-release-cycle-4maintenance.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Voronenko/gitflow-release/63ff2ab2eb18febe78ba9a66423a3e0b0684945e/images/git-workflow-release-cycle-4maintenance.png -------------------------------------------------------------------------------- /package.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | if [ -z "$1" ] 3 | then 4 | SUFFIX="" 5 | else 6 | SUFFIX="-$1" 7 | fi 8 | 9 | set -x 10 | 11 | PROJECT=project-name 12 | 13 | rm -rf ./build || true 14 | rm ${PROJECT}-*.tgz || true 15 | mkdir -p ./build || true 16 | 17 | CI_SUGGESTED_BRANCH=${CI_COMMIT_BRANCH} 18 | echo "Do we run on supported CI system to detect current branch being built? - ${CI_SUGGESTED_BRANCH}" 19 | 20 | if [ -z "$CI_SUGGESTED_BRANCH" ] 21 | then 22 | VERSION=$(git describe --exact-match 2> /dev/null || echo "`git symbolic-ref HEAD 2> /dev/null | cut -b 12-`-`git log --pretty=format:\"%h\" -1`") 23 | GITBRANCH=$(git symbolic-ref HEAD 2> /dev/null | sed -e 's,.*/\(.*\),\1,') 24 | else 25 | VERSION=$CI_SUGGESTED_BRANCH 26 | GITBRANCH=$CI_SUGGESTED_BRANCH 27 | fi 28 | 29 | GITCOMMIT=`git rev-parse --short HEAD` 30 | GITTAG=`git describe --exact-match --tags $(git log -n1 --pretty='%h') 2>/dev/null` 31 | DATE=`date +%Y-%m-%d:%H:%M:%S` 32 | 33 | # do build here, that produces necessary files for artifact under build/ folder 34 | 35 | echo "project=$PROJECT" > build/version.txt 36 | echo "major_version=$VERSION" >> build/version.txt 37 | echo "minor_version=$1" >> build/version.txt 38 | echo "git_hash=$GITCOMMIT" >> build/version.txt 39 | echo "git_tag=$GITTAG" >> build/version.txt 40 | echo "git_branch=$GITBRANCH" >> build/version.txt 41 | echo "built=$DATE" >> build/version.txt 42 | 43 | echo PRODUCING ARTIFACT $PROJECT-$VERSION$SUFFIX.tgz in build/ 44 | cd build 45 | tar cfz ../$PROJECT-$VERSION$SUFFIX.tgz . 46 | -------------------------------------------------------------------------------- /unpackage.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | PROJECT=project-name 3 | rm -rf ./build || true 4 | current_artefact=$(find ./${PROJECT}*.tgz -type f -exec stat -c "%n" {} + | sort | head -n1) 5 | echo Working with artefact: $current_artefact 6 | tar xvzf $current_artefact 7 | echo artefact unpacked: $current_artefact 8 | -------------------------------------------------------------------------------- /version.txt: -------------------------------------------------------------------------------- 1 | 0.1.1 2 | --------------------------------------------------------------------------------