Skip to content

Commit ca93543

Browse files
committed
Automate the release process.
Make it less likely that I'll forget to do something.
1 parent c843426 commit ca93543

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

build/release.sh

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/env bash
2+
3+
file_has_changed () {
4+
if [ ! -f $1 ]; then
5+
return 1
6+
fi
7+
8+
for f in `git ls-files --modified`; do
9+
[[ "$f" == "$1" ]] && return 0
10+
done
11+
12+
return 1
13+
}
14+
15+
version_is_unique () {
16+
for v in `git tag -l`; do
17+
[[ "$v" == "v$1" ]] && return 1
18+
done
19+
20+
return 0
21+
}
22+
23+
on_master_branch () {
24+
[[ $(git symbolic-ref --short -q HEAD) == "master" ]] && return 0
25+
return 1
26+
}
27+
28+
version=$(cat VERSION)
29+
previous_version=$(git tag -l | tail -n 1)
30+
31+
if ! on_master_branch; then
32+
echo -e "\033[0;31mRefusing to release from non master branch.\033[0m"
33+
exit 1
34+
fi
35+
36+
if ! file_has_changed "VERSION"; then
37+
echo -e "\033[0;31mRefusing to release because VERSION has not changed.\033[0m"
38+
exit 1
39+
fi
40+
41+
if ! file_has_changed "CHANGELOG.mdown"; then
42+
echo -e "\033[0;31mRefusing to release because CHANGELOG.ms has not been updated.\033[0m"
43+
exit 1
44+
fi
45+
46+
if ! file_has_changed "package.json"; then
47+
echo -e "\033[0;31mRefusing to release because package.json has not been updated.\033[0m"
48+
exit 1
49+
fi
50+
51+
if ! version_is_unique $version; then
52+
echo -e "\033[0;31mRefusing to release because VERSION is not unique.\033[0m"
53+
exit 1
54+
fi
55+
56+
echo -e "\033[1mAbout to release v$version with the following changes:\033[0m"
57+
git log --date=short --pretty=format:"%ad %h%x09%an%x09%s" $previous_version..HEAD
58+
59+
echo
60+
61+
echo -e "\033[1mThe following files will be part of the release commit:\033[0m"
62+
git ls-files --modified
63+
64+
echo
65+
66+
read -e -p "Are you sure you want to release? " -n 1 -r
67+
echo
68+
if [[ $REPLY =~ ^[Yy]$ ]]; then
69+
echo -e "\033[0;32mReleasing...\033[0m"
70+
echo
71+
git commit -a -m "Build version $version"
72+
git tag -a v$version -m "Version $version"
73+
git push origin master
74+
git push --tags
75+
76+
npm publish
77+
else
78+
echo -e "\033[0;31mCancelling...\033[0m"
79+
fi

0 commit comments

Comments
 (0)