This repository has been archived by the owner on Dec 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
release.sh
executable file
·82 lines (67 loc) · 1.5 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
#!/bin/bash
dirname=$(dirname $0)
CHANGELOG_MD=${dirname}/CHANGELOG.md
VERSION_PROPERTIES=${dirname}/version.properties
apply_version() {
local VERSION=$1
echo "version='${VERSION}'" > $VERSION_PROPERTIES
}
usage() {
echo $0 [-f] version
exit 1
}
commit() {
local OLD_VERSION=$1
local VERSION=$2
local FORCE=$3
local CHANGELOG_MD_NEW=${CHANGELOG_MD}.template
echo "### ${VERSION} ($(env LC_ALL=C date +%F)) ###" > ${CHANGELOG_MD_NEW}
GITLOG=`git log --pretty=format:%s v$OLD_VERSION..`
(
IFS=$'\n'
for L in $GITLOG
do
echo ' * '$L
done
) >> ${CHANGELOG_MD_NEW}
echo >> ${CHANGELOG_MD_NEW}
cat ${CHANGELOG_MD} >> ${CHANGELOG_MD_NEW}
mv -f ${CHANGELOG_MD_NEW} ${CHANGELOG_MD}
TEMPFILE=`mktemp gitlog-XXXXX`
git log v$OLD_VERSION.. > $TEMPFILE
vim -c "new|e ${CHANGELOG_MD}|2" $TEMPFILE
rm -f $TEMPFILE
git diff ${CHANGELOG_MD} ${VERSION_PROPERTIES}
if [ $FORCE -eq 0 ]; then
echo -n Do you want to commit? [Y/n]
read R
if [ x$R != x'Y' ];then
git checkout ${CHANGELOG_MD} ${VERSION_PROPERTIES}
echo "aborted!" >&2
return
fi
fi
git add ${CHANGELOG_MD} ${VERSION_PROPERTIES}
git commit -s -m "version $VERSION release"
git tag -f v${VERSION}
}
FORCE=0
while getopts ":f" opt; do
case $opt in
f)
FORCE=1
;;
\?)
usage
;;
esac
done
shift $((OPTIND-1))
if [ $# -eq 0 ];then
usage
fi
VERSION=$@
source $VERSION_PROPERTIES
OLD_VERSION=$version
apply_version $VERSION
commit $OLD_VERSION $VERSION $FORCE