-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease.sh
executable file
·134 lines (109 loc) · 2.48 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/bash -x
VERSION=$1
SKIP_CHANGELOG=$2
BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [[ "${BRANCH}" == "master" ]] && [[ "${BRANCH}" == "main" ]]
then
echo "ERROR: releases can only be done from the master/main branch"
exit 1
fi
behind=$(git log HEAD..origin/${BRANCH} --oneline)
if [[ "${behind}" != "" ]] ; then
echo "WARNING: local is not up to date with remote!"
echo "${behind}"
read -p "Press enter to continue anyway... "
fi
if [[ -z ${VERSION} ]]; then
echo "ERROR: missing first argument (release version)"
exit 1
fi
if git rev-parse "$VERSION" >/dev/null 2>&1; then
echo "ERROR: tag/release already exists. Cannot over overwrite it"
exit 1
fi
echo "INFO: tag and release ${VERSION}"
TARGET=deploy
do_push() {
echo "INFO: PUSHING changes."
git push
}
do_push_tag() {
echo "INFO: PUSHING tag ${VERSION}."
git push origin ${VERSION}
}
create_tag() {
echo "INFO: CREATING tag ${VERSION}."
git tag ${VERSION}
}
tag_release() {
# make the release tag
(git add . ; git commit -m "release ${VERSION}"; do_push; create_tag; do_push_tag)
}
do_tag() {
echo "INFO: TAGGING ${VERSION}"
tag_release
echo
}
update_changelog() {
changelog_file="CHANGELOG.md"
text="$1"
sed -i.bck "2i\\
${text}
" ${changelog_file}
}
do_changelog() {
changelog_ready="n"
while [[ "${changelog_ready}" == "n" ]]
do
release_headline="## [${VERSION}] - $(date +%Y-%m-%d)"
added='### Added'
changed='### Changed'
newline="placeholder"
while true
do
read -p "added (empty line to stop writing): " newline
if [[ -z $newline ]]
then
break
else
added=${added}' \
- '${newline}
fi
done
newline="placeholder"
while true
do
read -p "changed (empty line to stop writing): " newline
if [[ -z $newline ]]
then
break
else
changed=${changed}'\
- '${newline}
fi
done
full_changelog=${release_headline}'\
'${added}'\
'${changed}
printf "Your new CHANGELOG entry is:\n\n${full_changelog}\n\n"
read -p "continue? (y/n): " changelog_ready
done
update_changelog "${full_changelog}"
}
cleanup() {
git status
}
#
# add entries to CHANGELOG.md
#
if [[ -z $SKIP_CHANGELOG ]]; then
do_changelog
fi
#
# tag release
#
do_tag
#
# cleanup
#
cleanup