-
Notifications
You must be signed in to change notification settings - Fork 108
/
Copy pathpublish.sh
executable file
·67 lines (52 loc) · 1.49 KB
/
publish.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
#!/bin/bash
set -ex
function die() {
echo ERROR: "$1"
exit 1
}
function workspace_is_clean() {
git diff-index --quiet HEAD
return $?
}
function git_branch_name() {
git rev-parse --abbrev-ref HEAD
}
function is_up_to_date() {
git fetch
[[ $(git rev-parse HEAD) == $(git rev-parse @{u}) ]]
}
if ! workspace_is_clean; then
die "workspace has uncommitted changes, please commit them and try again"
fi
if [[ "$(git_branch_name)" != "master" ]]; then
die "releases can only be made from the 'master' branch, you currently have '$(git_branch_name)' checked out"
fi
if ! is_up_to_date; then
die "workspace has un-pushed commits, please push them and try again"
fi
PKG_VERSION=$(node -p "require('./package.json').version")
npm install
if ! workspace_is_clean; then
die "workspace changes detected after npm install; please commit these changes and try again"
fi
CHANGELOG_FIRST_LINE=$(head -n 1 CHANGELOG.md)
if [[ "${CHANGELOG_FIRST_LINE}" != "## ${PKG_VERSION}" ]]; then
die "Expected first line of the CHANGELOG to be '## ${PKG_VERSION}' but was '${CHANGELOG_FIRST_LINE}'"
fi
echo
head -n 10 CHANGELOG.md | sed 's/^/> /'
echo
read -p "Above are the first 10 lines of the CHANGELOG; does this look correct? " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
die "Aborting based on user input"
fi
npm run lint
npm run test
npm run build
git add .
git commit -m "Release v${PKG_VERSION}"
git push origin master
git tag "v${PKG_VERSION}"
git push origin "refs/tags/v${PKG_VERSION}"
npm publish