-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathrelease.sh
executable file
·102 lines (84 loc) · 1.94 KB
/
release.sh
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#! /bin/bash
function assertions {
if [ -z "$1" ]; then
echo Usage: $0 "<version>"
exit 1
fi
if ! git diff --quiet --exit-code; then
echo Current branch "isn't" clean. Use '`git status` for more details.'
echo Quiting...
exit 1
fi
if git rev-parse --verify --quiet $1 > /dev/null; then
echo 'Target tag `'$1'` already exists.'
echo Quiting...
exit 1
fi
if [ ! -z `git branch --list $TARGET_BRANCH` ]; then
echo 'Target branch `'$TARGET_BRANCH'` already exists.'
echo Quiting...
exit 1
fi
CURRENT_BRANCH=`git name-rev --name-only HEAD`
if [ :$CURRENT_BRANCH != :master ]; then
echo 'Current branch `'$CURRENT_BRANCH'`' "isn't" '`master`.'
echo Quiting...
exit 1
fi
echo Preparing release for '`'$1'`'
echo -n Proceed? "[Y|n] "
read input
test :$input = :N -o :$input = :n && exit 1
h1 Test
npm run build
}
function h1 {
echo
echo '## '$*
}
function error {
echo 'ERROR: '$*
exit 2
}
function update_version {
h1 Update package.json '`versions`' attribute
SED=sed
if [ :`uname` = :Darwin ]; then
SED=gsed
fi
$SED -i.orig 's/"version": "[^"]\+"/"version": "'$1'"/' package.json &&
git commit -a -m $1 &&
git show
}
function build {
h1 Include distribution files
# Yeap, again. Now including the new version in the dist files.
npm run build > /dev/null || error Build failed
git add -f dist/* dist-esm/* > /dev/null &&
git commit -a -m "Build: Include distribution files" > /dev/null &&
git show --stat ||
error Failed including distribution files
}
function tag {
h1 'Tag `'$1'` (detached)'
git tag -a -m $1 $1 > /dev/null
}
function checkout_back_to_master {
git checkout master > /dev/null
}
function final_message {
h1 Done
echo
echo Now you need to:
echo git push --tags origin
echo npm publish
echo git checkout master
echo git branch -D $TARGET_BRANCH
}
TARGET_BRANCH=b$1
assertions $1 &&
update_version $1 &&
git checkout -b $TARGET_BRANCH &&
build &&
tag $1 &&
final_message