Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #103 from bigbitecreative/feature/autoversion
Browse files Browse the repository at this point in the history
Add version bump helper script
  • Loading branch information
ampersarnie authored Jan 14, 2019
2 parents 021fadd + 3164dfb commit 98db51d
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
4 changes: 3 additions & 1 deletion bin/build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env sh

yarn && yarn build && zip -r ../benenson.zip . \
yarn \
&& yarn build \
&& zip -r ../benenson.zip . \
-x .\* \
-x CODE_OF_CONDUCT.md \
-x ISSUE_TEMPLATE.md \
Expand Down
53 changes: 53 additions & 0 deletions bin/version-bump.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env sh

# ./bin/bump.sh [<version>]
# <version> The version release version to increment.
# default: patch
# options: major|minor|patch
#
# Increments the package version by 1 across the following files:
# - /gulp/tasks/styles.js
# - /includes/scripts-and-styles.php
#
# EXAMPLE USAGE:
# ./bin/bump.sh minor

# escape a version number for sed
_v() {
echo "$(echo "$1" | tr -d '\n' | sed 's/\./\\\./g')";
}

# cross-compatible sed in-place
_sedi() {
isGnu=$(sed --version > /dev/null 2>&1)
if [ "$isGnu" ]; then
sed -i -- "$@"
else
sed -i "" "$@";
fi
}

_bump() {
bumptype="${1:-patch}"

# retrieve old version
oldversion=$(grep '^\tVersion: ' "$PWD/gulp/tasks/styles.js" | awk '{print $2}');

# bump it
case "$bumptype" in
major) newversion=$(echo "$oldversion" | awk '{split($NF,v,/[.]/); $NF=++v[1]"."v[2]"."v[3]}1');;
minor) newversion=$(echo "$oldversion" | awk '{split($NF,v,/[.]/); $NF=v[1]"."++v[2]"."v[3]}1');;
patch) newversion=$(echo "$oldversion" | awk '{split($NF,v,/[.]/); $NF=v[1]"."v[2]"."++v[3]}1');;
*) newversion=$(echo "$oldversion" | awk '{split($NF,v,/[.]/); $NF=v[1]"."v[2]"."++v[3]}1');;
esac

# escape versions for use in sed
oldversion=$(_v "$oldversion")
newversion=$(_v "$newversion")

# find/replace old/new versions in required files
_sedi "s/$oldversion/$newversion/g" "$PWD/gulp/tasks/styles.js";
_sedi "s/$oldversion/$newversion/g" "$PWD/includes/scripts-and-styles.php";
}

_bump "$1"

0 comments on commit 98db51d

Please sign in to comment.