forked from streamlink/streamlink
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·184 lines (146 loc) · 4.19 KB
/
Copy pathrelease.sh
File metadata and controls
executable file
·184 lines (146 loc) · 4.19 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/env bash
script=$(basename -- "$0")
temp_dir=$(mktemp -d) && trap "rm -rf ${temp_dir}" EXIT || exit 255
usage() {
echo "usage: $script [OPTIONS]" >&2
}
help() {
usage
cat <<EOF >&2
Helper script for performing a release of Streamlink.
Options can be specified on the command line, or the user will
be prompted to enter the required options.
General options:
-h, --help
Show this help message and exit.
-u, --upstream REPO
Set the upstream repo (streamlink/streamlink)
-o, --origin REPO
Set the users fork of the upstream repo (gituser/streamlink)
-v, --version VERSION
Set the new version number.
EOF
}
test_getopt() {
getopt --test > /dev/null
if [[ $? -ne 4 ]]; then
echo "An updated version of getopt is required (gnu-getopt)." >&2
return 1
fi
}
test_available() {
which $1 > /dev/null
return $?
}
columns() {
cols=$(tput cols)
echo $((cols > 80 ? 80 : cols))
}
error() {
cols=$(columns)
tput hpa $((cols - 6))
echo -e "\e[39m[\e[31mFAIL\e[39m]"
}
success() {
cols=$(columns)
tput hpa $((cols - 4))
echo -e "\e[39m[\e[32mOK\e[39m]"
}
changelog() {
temp_changes=$(mktemp) && trap "rm -rf ${temp_changes}" EXIT || exit 255
date=$(date -u +"%Y-%m-%d")
shortlog=$(git shortlog --email --no-merges --pretty=%s ${1}..)
echo -e "\n## streamlink $2 ($date)\n\n!! WRITE RELEASE NOTES HERE !!\n\n\`\`\`text\n${shortlog}\n\`\`\`\n" > "${temp_changes}"
sed -i "/# Changelog/ r ${temp_changes}" "CHANGELOG.md"
return $?
}
check_changelog() {
grep "WRITE RELEASE NOTES HERE" "CHANGELOG.md" >/dev/null
if [[ "$?" == "0" ]]; then
echo "fatal: CHANGELOG.md contains the template text" >&2
return 1
fi
return 0
}
action() {
local msg temp_log
msg=$1
temp_log=$(mktemp) && trap "rm -rf ${temp_log}" EXIT || exit 255
echo -n "$msg "
shift
"$@" 2> "${temp_log}" 1>&2 && success || (error; cat "${temp_log}"; exit 1)
return $?
}
test_getopt || exit 255
# setup getopts
OPTIONS=hu:o:v:
LONGOPTIONS=help,upstream:,origin:,version:
PARSED=$(getopt --options $OPTIONS --longoptions=$LONGOPTIONS --name "$0" -- "$@")
if [[ $? -ne 0 ]]; then
usage
exit 2
fi
# read getopt’s output this way to handle the quoting right:
eval set -- "$PARSED"
# now enjoy the options in order and nicely split until we see --
while true; do
case "$1" in
-h|--help)
help
exit 0
;;
-u|--upstream)
upstream="$2"
shift 2
;;
-o|--origin)
origin="$2"
shift 2
;;
-v|--version)
version="$2"
shift 2
;;
--)
shift
break
;;
*)
echo "Programming error"
exit 3
;;
esac
done
echo -e "Streamlink Release Script\n"
action "User has git installed" test_available git
if [ -z "$upstream" ]; then
echo -n "Upstream repo [streamlink/streamlink]: "
read upstream
if [ -z "$upstream" ]; then
upstream="streamlink/streamlink"
fi
fi
if [ -z "$origin" ]; then
echo -n "Fork repo [$USER/streamlink]: "
read origin
if [ -z "$origin" ]; then
origin="$USER/streamlink"
fi
fi
while [ -z "$version" ]; do
echo -n "New version number: "
read version
done
action "Cloning ${upstream}..." git clone -q "ssh://[email protected]/${upstream}.git" "${temp_dir}"
pushd "${temp_dir}" >/dev/null
dirty_version=$(python setup.py --version)
current_version="${dirty_version%%+*}"
action "Adding ${origin} as origin" git remote set-url origin "[email protected]:${origin}.git" || exit 1
action "Adding release-${version} branch" git checkout -b "release-${version}" || exit 1
action "Updating CHANGELOG.md (${current_version}..HEAD}" changelog "${current_version}" "${version}" || exit 1
# launch editor to edit the file
"${VISUAL:-"${EDITOR:-vi}"}" "CHANGELOG.md"
action "Check CHANGELOG.md was updated" check_changelog || exit 1
action "Commit CHANGELOG.md to release-${version} branch" git commit CHANGELOG.md -m "Release ${version}" || exit 1
action "Push release-${version} branch to ${origin}" git push origin "release-${version}" || exit 1
popd >/dev/null