forked from salomvary/soundcleod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.sh
executable file
·88 lines (77 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
#!/bin/sh
print_version() {
node -e "console.log(require('./app/package.json').version)"
}
# Increment version in package.json
increment_version() {
cd app && npm version --git-tag-version false patch && cd ..
}
# Updates the current version in README.markdown
update_readme_version() {
version=$(print_version)
date=$(date '+%B %e, %Y')
sed -i '' -E -e\
"s/Current version is [^[:space:]]+ \([^(]+\)/Current version is $version ($date)/"\
README.markdown
}
# Read changes from git log and open it in an editor
read_changes() {
tmp_history=$(mktemp -t soundcleod-history)
git log\
--first-parent --pretty=format:"%s"\
"$(git describe --abbrev=0 --tags)..master"\
> "$tmp_history"
$EDITOR "$tmp_history" < /dev/tty > /dev/tty || exit $?
cat "$tmp_history"
}
# Reads history from stdin (one entry per line) and prepends it to CHANGELOG.md
update_changelog() {
format_changelog_markdown | write_changelog
}
format_changelog_markdown() {
while read line; do
echo "- $line"
done
}
write_changelog() {
history=$(cat)
tmp_changelog=$(mktemp -t soundleod-changelog)
version=$(print_version)
date=$(date '+%B %e, %Y')
{
echo "## $version ($date)"
echo "$history"
echo
cat CHANGELOG.md
} > "$tmp_changelog"
mv "$tmp_changelog" CHANGELOG.md
}
print_usage() {
echo "Usage: $(basename "$0") increment_version Bump app version before build"
echo " $(basename "$0") print_version Print app version"
echo " $(basename "$0") update_readme_version Update version information in the README"
echo " $(basename "$0") history Update README, CHANGELOG and appcast.xml"
}
main() {
case "$1" in
print_version)
print_version
;;
increment_version)
increment_version
;;
update_readme_version)
update_readme_version
;;
history)
update_readme_version
changes=$(read_changes)
echo "$changes" | update_changelog
;;
*)
print_usage
exit 1
;;
esac
}
main "$@"