Skip to content

Instantly share code, notes, and snippets.

@infinityplusone
Created September 29, 2016 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save infinityplusone/1cb6108d52dc7d12d0a2ebf4b303f7b6 to your computer and use it in GitHub Desktop.
Save infinityplusone/1cb6108d52dc7d12d0a2ebf4b303f7b6 to your computer and use it in GitHub Desktop.
Build script
#!/bin/sh
# Formatting variables
blackBG='\033[1;40m'
cyan='\033[1;36m'$blackBG
gray='\033[1;37m'$blackBG
green='\033[1;32m'$blackBG
purple='\033[1;35m'$blackBG
red='\033[0;31m'$blackBG
yellow='\033[1;33m'$blackBG
nc='\033[0m'$blackBG
bumped=false
project=$(pwd | sed -e "s/.*\///g")
branch=$(git rev-parse --abbrev-ref HEAD)
reBump='^([0-9]+\.[0-9]+\.[0-9]+|patch|minor|major)$'
# if a bump was specified, bump the version and push that first
if [ "$#" == 1 ]; then
if [[ $1 =~ $reBump ]]; then
grunt bump:$1
bumped=true
else
echo "\n${red}Fatal error: Invalid bump value!${nc}\n"
exit 1
fi
fi
# get everything ready
echo "Updating bower components and generating build file.\n"
bower update
grunt build
# figure out the version
version=$(cat VERSION)
# if we bumped, push this branch too
if [[ $bumped ]]; then
echo "Pushing updated version to ${cyan}${branch}${nc}.\n"
git commit -am "bump to v${version}"
git push origin $branch
fi
# checkout a branch for this version
echo "Checking out ${cyan}latest${nc} branch for ${cyan}v${version}${nc}.\n"
git branch -D latest
git checkout -b latest
# add the distribution file & push it
echo "Adding build file to latest branch and pushing to remote.\n"
git add ${project}.min.js
git commit -am "v${version}"
git push origin latest --force
# remove "latest" tag on the remote & create a new local one
echo "Creating new tag for ${cyan}v${version}${nc} and pushing to remote.\n"
git tag -f v${version}
# push up new tags
echo "Pushing tags up to remote.\n"
git push origin --tags
# cleanup
echo "Cleaning up and checking out ${cyan}${branch}${nc}.\n"
rm -rf VERSION
# go back to where you started
git checkout $branch
echo "${green}Done!${nc}\n\n"
@infinityplusone
Copy link
Author

This build script makes a lot of assumptions. The biggest assumption is that there is a build Grunt task, and it will create a file called VERSION that contains the version number.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment