-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrelease
executable file
·88 lines (75 loc) · 2.1 KB
/
release
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash
ECHO=echo
DEBUG=false
VERSION="$(node -e "console.log(require('./package.json').version)")"
SEMVER=./node_modules/.bin/semver
PREID=alpha
DIR=$(dirname "${BASH_SOURCE[0]}")
cd ${DIR}
FAILED=false
run() {
msg="$1"
shift
cmd="$@"
${ECHO} ${msg}
if ${DEBUG}; then
echo "> $cmd"
elif ${FAILED}; then
echo "'${cmd}' skipped due to earlier error."
else
eval "$cmd" || { echo "Error $? running '${cmd}'"; FAILED=true; }
fi
}
new() {
BRANCH=$(${SEMVER} -i minor ${VERSION})
run "Creating release branch ${BRANCH}" git checkout -b ${BRANCH}
run "Tagging release" npm version minor
run "Incrementing master version" git checkout master
run "" npm verison $(${SEMVER} --preid ${PREID} -i preminor ${VERSION})
run "Pushing to origin" git push origin --tags master ${BRANCH}
run "Publishing" git checkout ${BRANCH}
run "" npm publish
run "" git checkout master
}
patch() {
local release="$2"
run "Checking out release branch ${release}" git checkout ${release}
run "Tagging release" npm version patch
run "Pushing to origin" git push origin --tags ${release}
run "Publishing" npm publish
}
major() {
run "Incrementing master version" git checkout master
run "" npm version $(${SEMVER} --preid ${PREID} -i premajor ${VERSION})
run "Pushing to origin" git push origin --tags ${master}
}
usage() {
cat <<EOF
Usage
$0 [-n] [-q] new | patch <release-branch> | major
new: Run when ready to release a new version. Creates a new release branch,
tags, pushes to origin, and publishes. Increments minor verion on master.
patch: Run when ready to release a patch on release-branch. Creates a new patch
release tag on release-branch, pushes to origin, and publishes.
major: Run when commits have made the lib incompatible with previous releases.
Increments major version on master, pushes to origin.
-n: Echo commands that would be run. Don't execute them.
-q: Silent operation.
EOF
}
if [ "$1" == "-n" ]; then
DEBUG=true;
shift;
fi
if [ "$1" == "-q" ]; then
ECHO=false;
shift;
fi
cmd="$1"
case "$cmd" in
new) new;;
patch) patch "$@";;
major) major;;
"") usage;;
*) usage;;
esac