Skip to content

Commit

Permalink
Merge pull request #5 from screwdriver-cd/versionUp
Browse files Browse the repository at this point in the history
Add shell script to auto increment version number
  • Loading branch information
jer authored Jul 26, 2016
2 parents 822c331 + cbbe542 commit 0d71253
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
44 changes: 44 additions & 0 deletions incrementVersion.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

# Constants
TAGS=$(git tag -l --sort="version:refname")
INDEX=${#TAGS}
let "INDEX--"
VERSION=0
MAJOR=0
MINOR=0
PATCH=0

# Functions
function findNextPeriod() {
while [[ ${VERSION:$INDEX:1} != "." ]]
do
let "INDEX++"
done
}

# Find the highest version tag
while [[ ${TAGS:$INDEX:1} != "v" ]]
do
let "INDEX--"
done
VERSION=${TAGS:$INDEX+1}

# Find the Major number
INDEX=0
findNextPeriod
MAJOR=${VERSION:0:$INDEX}

# Find the Minor number
VERSION=${VERSION:$INDEX+1}
findNextPeriod
MINOR=${VERSION:0:$INDEX}

# Find the Patch number and increment
VERSION=${VERSION:$INDEX+1}
PATCH=$VERSION
let "PATCH++"

# Return the incremented version
VERSION=v$MAJOR.$MINOR.$PATCH
echo $VERSION
12 changes: 9 additions & 3 deletions wercker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ build:
deploy:
steps:
- script:
name: get version from VERSION file
code: export VERSION=$(cat VERSION)
name: get highest version from tags
code: export VERSION=$(sh incrementVersion.sh)
- script:
name: add new annotated tag
code: git tag -a $VERSION -m "Tagging release version $VERSION"
- script:
name: push newly added tag
code: git push origin $VERSION
- github-create-release:
token: $GITHUB_TOKEN
tag: v$VERSION
tag: $VERSION
- github-upload-asset:
token: $GITHUB_TOKEN
file: launch
Expand Down

0 comments on commit 0d71253

Please sign in to comment.