Auspice fork from github of
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
3.8 KiB

#!/usr/bin/env bash
read -r -d '' purposeMsg <<'EOF'
Bumping Auspice version & deploying to Heroku
This script attempts to do 9 things. It will exit if any steps fail...
(1) checkout master & ensure it is up to date with github
(2) increment Version number (in `src/version.js` and `package.json`) by prompting the user
(3) add a title with the version number to the CHANGELOG
(4) commit to master
(5) checkout `release` branch from github (will fail if it exists locally)
(6) merge master -> release
(7) tag release with new version
(8) push release branch to github (this triggers Travis CI to build, upload and trigger Heroku deploy)
(9) checkout `master` and remove local `release` branch
function errorFound {
echo -e "\nScript Failed at step $step (Line $1)\nYou are responsible for clean up (sorry!)"
exit 2
trap 'errorFound $LINENO' ERR
echo "$purposeMsg"
echo -e "\n"
# exit if release branch exists locally
if git rev-parse --verify --quiet release
echo "release branch already exists locally - fatal"
exit 2
# step 1: check master is up to date with github
git diff-index --quiet HEAD -- # $? = 1 if uncommited changes
git checkout master
git fetch origin
git status -uno | grep "up-to-date\|up to date" # $? = 1 if not up-to-date OR up to date
git diff-index --quiet HEAD -- # $? = 1 if uncommited changes
# step 2: increment version number (req user input)
packagesVersion=$(grep "\"version\":" package.json | perl -pe 's/.*([0-9]+.[0-9]+.[0-9]+).*/\1/')
srcVersion=$(grep "const version" src/version.js | perl -pe 's/.*([0-9]+.[0-9]+.[0-9]+).*/\1/')
if [ ${packagesVersion} != ${srcVersion} ]
echo "packages.json version (${packagesVersion}) doesn't match version.js version (${srcVersion}). Fatal."
exit 2
parts=(${srcVersion//./ }) # magic
bumps=($((${parts[0]}+1)) $((${parts[1]}+1)) $((${parts[2]}+1)))
echo -e "\nCurrent version: ${srcVersion}. Is this a major new release (${bumps[0]}.0.0), a feature release (${parts[0]}.${bumps[1]}.0) or a minor fix (${parts[0]}.${parts[1]}.${bumps[2]})?\n"
select yn in "major-new-release" "feature-release" "minor-fix"; do
case $yn in
major-new-release ) msg="major new release"; newVersion="${bumps[0]}.0.0"; break;;
feature-release ) msg="feature release"; newVersion="${parts[0]}.${bumps[1]}.0"; break;;
minor-fix ) msg="minor fix"; newVersion="${parts[0]}.${parts[1]}.${bumps[2]}"; break;;
echo -e "\n"
# now replace the version in packages.json and version.js (inplace!)
perl -pi -e "s/\"version\": \"${packagesVersion}\"/\"version\": \"${newVersion}\"/" package.json
perl -pi -e "s/version = \"${srcVersion}\";/version = \"${newVersion}\";/" src/version.js
unset packagesVersion srcVersion parts bumps yn
# step 3: add h2 title to with newVersion & date, while preserving YAML frontmatter for docs
today=$(date +'%Y/%m/%d')
echo -e "---\ntitle: Changelog\n---\n\n## version ${newVersion} - ${today}\n\n$(tail -n +4" >
unset today
# step 4: commit to current branch (master) & push to github (origin)
git add .
git commit -m "version bump to ${newVersion} for release"
git push origin master # push master, with the updated version number...
echo -e "Master successfully updated and pushed to github"
# step 5: checkout release branch from github
git checkout -b release origin/release
# step 6: merge master into release
git merge --ff-only master
# # step 7: tag
git tag -a v${newVersion} -m "${msg}"
# step 8: push to github, including the tag
git push --follow-tags origin release
# step 10: go back to master & delete release branch (locally)
git checkout master
git branch -d release
echo -e "\nScript completed. $msg (version ${newVersion}) pushed to github:release and github:master\n"