UNPKG

3.92 kBapplication/x-shView Raw
1#!/usr/bin/env bash
2
3# VARIABLES
4read -r -d '' purposeMsg <<'EOF'
5Bumping Auspice version & deploying to Heroku
6
7This script attempts to do 9 things. It will exit if any steps fail...
8(1) checkout master & ensure it is up to date with github
9(2) increment Version number (in `src/version.js` and `package.json`) by prompting the user
10(3) add a title with the version number to the CHANGELOG
11(4) commit to master
12(5) checkout `release` branch from github (will fail if it exists locally)
13(6) merge master -> release
14(7) tag release with new version
15(8) push release branch to github (this triggers Travis CI to build, upload and trigger Heroku deploy)
16(9) checkout `master` and remove local `release` branch
17
18EOF
19
20# FUNCTIONS:
21
22function errorFound {
23 echo -e "\nScript Failed at step $step (Line $1)\nYou are responsible for clean up (sorry!)"
24 exit 2
25}
26
27# TRAPS
28trap 'errorFound $LINENO' ERR
29
30# MAIN
31echo "$purposeMsg"
32echo -e "\n"
33
34# exit if release branch exists locally
35if git rev-parse --verify --quiet release
36 then
37 echo "release branch already exists locally - fatal"
38 exit 2
39fi
40
41# step 1: check master is up to date with github
42step="1"
43git diff-index --quiet HEAD -- # $? = 1 if uncommited changes
44git checkout master
45git fetch origin
46git status -uno | grep "up-to-date\|up to date" # $? = 1 if not up-to-date OR up to date
47git diff-index --quiet HEAD -- # $? = 1 if uncommited changes
48
49# step 2: increment version number (req user input)
50step="2"
51packagesVersion=$(grep "\"version\":" package.json | perl -pe 's/.*([0-9]+.[0-9]+.[0-9]+).*/\1/')
52srcVersion=$(grep "const version" src/version.js | perl -pe 's/.*([0-9]+.[0-9]+.[0-9]+).*/\1/')
53if [ ${packagesVersion} != ${srcVersion} ]
54 then
55 echo "packages.json version (${packagesVersion}) doesn't match version.js version (${srcVersion}). Fatal."
56 exit 2
57fi
58parts=(${srcVersion//./ }) # magic
59bumps=($((${parts[0]}+1)) $((${parts[1]}+1)) $((${parts[2]}+1)))
60echo -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"
61select yn in "major-new-release" "feature-release" "minor-fix"; do
62 case $yn in
63 major-new-release ) msg="major new release"; newVersion="${bumps[0]}.0.0"; break;;
64 feature-release ) msg="feature release"; newVersion="${parts[0]}.${bumps[1]}.0"; break;;
65 minor-fix ) msg="minor fix"; newVersion="${parts[0]}.${parts[1]}.${bumps[2]}"; break;;
66 esac
67done
68echo -e "\n"
69# now replace the version in packages.json and version.js (inplace!)
70perl -pi -e "s/\"version\": \"${packagesVersion}\"/\"version\": \"${newVersion}\"/" package.json
71perl -pi -e "s/version = \"${srcVersion}\";/version = \"${newVersion}\";/" src/version.js
72unset packagesVersion srcVersion parts bumps yn
73
74# step 3: add h2 title to CHANGELOG.md with newVersion & date, while preserving YAML frontmatter for docs
75today=$(date +'%Y/%m/%d')
76echo -e "---\ntitle: Changelog\n---\n\n## version ${newVersion} - ${today}\n\n$(tail -n +4 CHANGELOG.md)" > CHANGELOG.md
77unset today
78
79# step 4: commit to current branch (master) & push to github (origin)
80step="4"
81git add .
82git commit -m "version bump to ${newVersion} for release"
83git push origin master # push master, with the updated version number...
84echo -e "Master successfully updated and pushed to github"
85
86# step 5: checkout release branch from github
87step="5"
88git checkout -b release origin/release
89
90# step 6: merge master into release
91step="6"
92git merge --ff-only master
93
94# # step 7: tag
95step="7"
96git tag -a v${newVersion} -m "${msg}"
97
98# step 8: push to github, including the tag
99step="8"
100git push --follow-tags origin release
101
102# step 10: go back to master & delete release branch (locally)
103step="9"
104git checkout master
105git branch -d release
106
107echo -e "\nScript completed. $msg (version ${newVersion}) pushed to github:release and github:master\n"