-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmake_release.sh
executable file
·209 lines (179 loc) · 5.08 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
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/bin/bash
set -eu
R="$(printf "\033[31m")"
B="$(printf "\033[34m")"
W="$(printf "\033[37m")"
M="$(printf "\033[35m")"
NC="$(printf "\033[0m")"
BOLD="$(printf "\033[1m")"
print_usage() {
echo "Usage: $0 [-h|--help] [--no-tag] [--no-edit] --do"
}
print_help() {
print_usage
echo
echo "Create release commits and tags, including regeneration"
echo
echo "-h, --help Show this message"
echo "--no-tag Don't create a tag for the release commit"
echo "--no-edit Don't pause to allow CHANGELOG editing"
echo "--do Actually run. Safety so that no arguments doesnt commit"
# echo "--dry-run, -n Don't do anything"
echo
echo "ARG.... Arguments to pass to bump2version"
}
quietly() {
echo "${W}+ $@"
if ! "$@" 2>&1 | sed 's/\x1b\[[0-9;]*m//g'; then
printf $NC
return 1
fi
printf $NC
}
silently() {
echo "${W}+ $@$NC"
if ! _output="$("$@" 2>&1)"; then
echo "${R}Error:"
echo "$_output" | sed 's/\x1b\[[0-9;]*m//g'
printf $NC
return 1
fi
}
DRY_RUN=""
ALLOW_NONMAIN=""
ALLOW_DIRTY=""
NO_TAG=""
NO_EDIT=""
DO=""
_positionals=()
while [[ $# -gt 0 ]]; do
_key="$1"
case "$_key" in
-h|--help)
print_help
exit 0
;;
-h*)
print_help
exit 0
;;
-n|--dry-run)
DRY_RUN=true
;;
--allow-nonmain)
ALLOW_NONMAIN=true
;;
--allow-dirty)
ALLOW_DIRTY=true
;;
--no-tag)
NO_TAG=true
;;
--no-edit)
NO_EDIT=true
;;
--do)
DO=true
;;
*)
_positionals+=("$1")
;;
esac
shift
done
if [[ ${#_positionals[@]} -gt 0 ]]; then
echo "${R}Error: Unknown positional arguments: ${_positionals[@]}"
exit 1
fi
if [[ $DO != true ]]; then
print_usage
echo "${R}Error: You must pass --do to actually make a release$NC"
exit 1
fi
if [[ $DRY_RUN == true ]]; then
echo "Error: Sorry, dry-run isn't implemented yet"
exit 1
fi
# Verify we are on main
if [[ $ALLOW_NONMAIN != true && "$(git rev-parse --abbrev-ref HEAD)" != "main" ]]; then
echo "${R}Error: Not on branch ${BOLD}main${NC}${R}, cannot make release"
exit 1
fi
# Check we aren't dirty
if [[ $ALLOW_DIRTY != true && -n "$(git status --porcelain | grep -v '??')" ]]; then
echo "${R}Error: Working branch is dirty. Cannot continue."
exit 1
fi
# Check that _this file_ isn't dirty
if [[ -n "$(git status --porcelain | grep make_release.sh)" ]]; then
echo "${R}Fatal Error: Release generation file make_release.sh is dirty$NC"
exit
fi
_start_commit="$(git rev-parse HEAD)"
echo "Starting release process"
bump2version_args=(release --list)
if [[ $ALLOW_DIRTY == true ]]; then
bump2version_args+=(--allow-dirty)
fi
if ! _output="$(set -x; bump2version "${bump2version_args[@]}")"; then
echo "${R}Error: Bump2version failed"
echo "$_output" $NC
exit 1
fi
new_version="$(echo "$_output" | grep new_version | sed -r s,"^.*=",,)"
echo "New version: $BOLD$M$new_version$NC"
echo "Regenerating SWIG files$W"
silently ./regenerate_pycbf.py
# On M1 mac, there are no wheels for numpy, and it doesn't build.
# Numpy is only a runtime requirement so this is safe
echo "Removing numpy from dependencies"
silently cp pyproject.toml pyproject.toml.bak
silently sed -i'' -e 's/numpy = ">=1.17"/# numpy = ">=1.17"/' pyproject.toml
echo "Installing base environment"
silently poetry install
# Restore back for the build
echo "Restoring original pyproject"
silently mv pyproject.toml.bak pyproject.toml
echo "Re-running build for Cython"
silently poetry build
echo "Running towncrier"
silently towncrier --yes --version="$new_version"
if [[ $NO_EDIT != true ]]; then
echo "Pausing for CHANGELOG editing"
${EDITOR:-vi} CHANGELOG.rst
else
echo "No editing phase requested; using CHANGELOG as-is"
fi
echo "Running pre-commit to clean up"
quietly pre-commit run --all || true
echo "${BOLD}Making commit$NC"
quietly git add --update
quietly git commit -n -m "pycbf $new_version"
if [[ $NO_TAG != "true" ]]; then
echo "Making tag ${M}v${new_version}$NC"
quietly git tag "v${new_version}"
fi
echo "$NC"
echo "Advancing to new development release"
if ! _output="$(set -x; bump2version minor --list)"; then
echo "${R}Error: Advancing release tag to next development release"
echo "$_output" $NC
exit 1
fi
new_dev_version="$(echo "$_output" | grep new_version | sed -r s,"^.*=",,)"
echo "New development version: $BOLD$M$new_dev_version$NC"
echo "Regenerating SWIG files$W"
silently ./regenerate_pycbf.py
echo "Re-running build for Cython"
silently poetry build
echo "${BOLD}Making new development commit$NC"
( set -x
git add --update
git commit -n -m "Advance to ${new_dev_version} development series"
)
echo
echo "Successfully released $M$new_version$NC and advanced to $M$new_dev_version$NC"
echo
if [[ $NO_TAG != true ]]; then
echo "Please remember to ${B}git push origin main v$new_version$NC"
fi