-
Notifications
You must be signed in to change notification settings - Fork 6
/
make-release.sh
executable file
·108 lines (86 loc) · 3.55 KB
/
make-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
#!/bin/bash
# This script updates the version number in the manifest file,
# commits and tags the changes and then exports a ZIP
# archive of the new version
VERSION_NUMBER=$1
VERSION_DESC=$2
_CLR_GREEN='\e[1;32m'
_CLR_RED='\e[1;31m'
_CLR_NONE='\e[0m'
if $(git tag | grep -q "^v${VERSION_NUMBER}$"); then
echo -e "${_CLR_RED}Version '${VERSION_NUMBER}' already exists, please choose another or exit with Ctrl+C.${_CLR_NONE}" >&2
VERSION_NUMBER=""
fi
while [[ "" == $VERSION_NUMBER ]]; do
echo -n "Please enter the version number: "
read VERSION_NUMBER
if $(git tag | grep -q "^v${VERSION_NUMBER}$"); then
echo -e "${_CLR_RED}Version '${VERSION_NUMBER}' already exists, please choose another or exit with Ctrl+C.${_CLR_NONE}" >&2
VERSION_NUMBER=""
fi
done
while [[ "" == $VERSION_DESC ]]; do
echo -n "Please enter a description for the release (e.g. 'bugfix release'): "
read VERSION_DESC
done
echo -n "Updating manifest file to version '${VERSION_NUMBER}' and committing changes. Continue? [y/N] "
read response
if [[ "y" != $response ]] && [[ "Y" != $response ]]; then
echo -e "${_CLR_RED}Exiting without changes.${_CLR_NONE}"
exit
fi
# Update manifest
echo -e "${_CLR_GREEN}Stashing working directory...${_CLR_NONE}"
changesStashed=true
if [ -z $(git status --porcelain) ]; then
changesStashed=false
else
git stash
fi
echo -e "${_CLR_GREEN}Updating manifest...${_CLR_NONE}"
manifest=$(< addon.xml)
echo "$manifest" | sed 's/ name="Massengeschmack" version="[^"]\+" / name="Massengeschmack" version="'"${VERSION_NUMBER}"'" /' > addon.xml
# Update changelog
echo -e "${_CLR_GREEN}Updating changelog...${_CLR_NONE}"
changelog=$(git log $(git describe --tags --abbrev=0)..HEAD --oneline -E -i --grep=" \+cl$" --format=" - %s" | sed 's/ +cl$//')
if [[ "" == $changelog ]]; then
echo -e "${_CLR_RED}No commits marked for changelog inclusion, trying to assemble changelog automatically...${_CLR_NONE}" >&2
changelog=$(git log $(git describe --tags --abbrev=0)..HEAD --oneline -E -i --grep="^(Add|Fix|Update|Remove) " --format=" - %s" | grep -Ev " -cl")
fi
if [[ "" == $changelog ]]; then
echo -e "${_CLR_RED}No changelog could be generated, skipping...${_CLR_NONE}" >&2
else
oldChangelog=$(<changelog.txt)
newEntries=$(echo "$changelog" | sed 's/ +cl$//')
changelog="${VERSION_NUMBER}
${changelog}
${oldChangelog}"
echo "$changelog" > changelog.txt
fi
echo -e "${_CLR_GREEN}Opening changelog for manual editing...${_CLR_NONE}"
vim changelog.txt
# Commit and tag changes
echo -e "${_CLR_GREEN}Committing changes...${_CLR_NONE}"
git add addon.xml
git commit -m "Bump version number to ${VERSION_NUMBER} -cl"
git add changelog.txt
git commit -m "Update changelog -cl"
echo -e "${_CLR_GREEN}Tagging release...${_CLR_NONE}"
git tag -a "v${VERSION_NUMBER}" -m "Version ${VERSION_NUMBER} (${VERSION_DESC})"
if $changesStashed; then
echo -e "${_CLR_GREEN}Re-applying and popping stash...${_CLR_NONE}"
git stash pop
fi
# Export ZIP file
filename="plugin.video.massengeschmack-${VERSION_NUMBER}.zip"
echo -e "${_CLR_GREEN}Exporting release to '${filename}'...${_CLR_NONE}"
if [ -e "${filename}" ]; then
echo -n "File '${filename}' already exists. Overwrite? [y/N] "
read response
if [[ "y" != $response ]] && [[ "Y" != $response ]]; then
echo -e "${_CLR_RED}Exiting without changes.${_CLR_NONE}"
exit
fi
fi
git archive --output="plugin.video.massengeschmack-${VERSION_NUMBER}.zip" --format=zip --prefix="plugin.video.massengeschmack/" "v${VERSION_NUMBER}"
echo -e "${_CLR_GREEN}Done.${_CLR_NONE}"