Debian Codegraph @

release_tools/release.sh

raw symbols SCIP
1 JENKINS_SITE='https://jenkins.open-scap.org'
2 GITHUB_ROOT='https://github.com/OpenSCAP/openscap'
3
4 test -f .env && . .env
5
6 SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7 OSCAP_REPO_ROOT="$(cd "$SCRIPT_DIR" && cd .. && pwd)"
8 LIBRARY_STASH="/tmp/library-stash"
9 BUILDDIR="$OSCAP_REPO_ROOT/build"
10
11 FILE_WITH_VERSIONS="$SCRIPT_DIR/versions.sh"
12
13 . "$FILE_WITH_VERSIONS"
14
15
16 die()
17 {
18 echo "$1"
19 exit 1
20 }
21
22
23 clean_repository()
24 {
25 make distclean
26 git clean -f
27 }
28
29
30 clean_repository_aggressively()
31 {
32 git reset --hard
33 git clean -x -f -d
34 }
35
36
37 # Args:
38 # $1: Python version
39 check_python_binding()
40 {
41 local _python_major
42 _python_major="${1%%.*}"
43 (
44 cd "$BUILDDIR"
45 if LD_PRELOAD="/usr/lib64/libpython$1.so" ldd -r "$BUILDDIR/swig/python$_python_major/_openscap_py.so" | grep -q '^undefined' ; then
46 die "Python $1 bindings seem to have undefined symbols"
47 fi
48 )
49 }
50
51
52 trigger_tests()
53 {
54 xdg-open "$JENKINS_SITE/job/openscap-parametrized/build"
55 }
56
57
58 trigger_docbuild()
59 {
60 xdg-open "$JENKINS_SITE/job/static_openscap_docs/build"
61 }
62
63
64 build_all()
65 {
66 (mkdir -p "$BUILDDIR" && cd "$BUILDDIR" && cmake -DENABLE_SCE=TRUE .. && make) || die "Error building pristine OpenSCAP"
67 }
68
69
70 execute_local_tests()
71 {
72 build_all
73 (cd "$BUILDDIR" && ctest || die "Error during test run")
74 check_python_binding 3
75 }
76
77
78 make_dist()
79 {
80 (
81 cd "$BUILDDIR"
82 make package_source
83 sha1sum openscap-$version.tar.gz > openscap-$version.tar.gz.sha1sum
84 sha512sum openscap-$version.tar.gz > openscap-$version.tar.gz.sha512sum
85 )
86 }
87
88
89 check_abi()
90 {
91 rpm -q abi-compliance-checker || sudo dnf install abi-compliance-checker
92 test -d openscap-abi-check || git clone --recurse-submodules [email protected]:OpenSCAP/openscap-abi-check.git
93 openscap_git_branch=$(git branch | grep '^\* ' | cut -f2 -d' ')
94 (
95 cd openscap-abi-check
96 perl run_check.pl "$previous_version" "$openscap_git_branch"
97 echo 'Read the report, if there is an ABI issue (some symbols were changed / removed), fix it before proceeding further!'
98 printf "%s\n" "Then, Change directory to '$(pwd)' and add the reports. Then, commit with the appropriate message:" "" "cd $(pwd)" "git add reports/${previous_version}_${openscap_git_branch}.html'" "git commit -m 'Report before $version release'"
99 )
100 }
101
102
103 parse_variable_assignment_from_file()
104 {
105 local _variable="$1" _fname="$2"
106 test "$(grep "set(\s*$_variable\s\+[0-9]\+\s*)" "$_fname" | wc -l)" = 1 || die "More than one occurence of numerical assignment to '$_variable'"
107 echo $(grep "set(\s*$_variable\s\+[0-9]\+\s*)" "$_fname" | sed -e "s/set(\s*$_variable\s\+\([0-9]\+\)\s*)/\1/")
108 }
109
110
111 substitute_variable_assignment_value_in_file()
112 {
113 local _variable="$1" _old_value="$2" _new_value="$3" _fname="$4"
114 sed -i "s/set(\s*$_variable\s\+$_old_value\s*)/set($_variable $_new_value)/" "$_fname"
115 }
116
117 # $1 ... File to probe
118 get_lt_triplet_from_file()
119 {
120 local _varname _fname="$1"
121 for _varname in LT_CURRENT LT_REVISION LT_AGE
122 do
123 printf "%s " "$(parse_variable_assignment_from_file "$_varname" "$_fname")"
124 done
125 echo
126 }
127
128 increment_on_backwards_compatible()
129 {
130 local triplet
131 triplet=( $1 )
132 (( triplet[0]++ ))
133 (( triplet[2]++ ))
134 printf "%s %s %s \n" "${triplet[@]}"
135 }
136
137
138 increment_on_bugfix()
139 {
140 local triplet
141 triplet=( $1 )
142 (( triplet[1]++ ))
143 printf "%s %s %s \n" "${triplet[@]}"
144 }
145
146
147 increment_on_breaking_change()
148 {
149 local triplet
150 triplet=( $1 )
151 (( triplet[0]++ ))
152 triplet[2]=0
153 printf "%s %s %s \n" "${triplet[@]}"
154 }
155
156 # Args:
157 # $1: Triplet to be replaced
158 # $2: The replacement
159 # $3: The concerned file
160 apply_triplets_to_file()
161 {
162 local _previous=( $1 ) _replacement=( $2 ) _file="$3" _varnames=(LT_CURRENT LT_REVISION LT_AGE)
163 for i in 0 1 2
164 do
165 substitute_variable_assignment_value_in_file "${_varnames[$i]}" "${_previous[$i]}" "${_replacement[$i]}" "$_file"
166 done
167 }
168
169
170 #
171 # $1: Strategy (backwards_compatible, bugfix, breaking_change)
172 increment_ltversions()
173 {
174 local _cmake_file="$OSCAP_REPO_ROOT/CMakeLists.txt" _old_versions _new_versions _new_soname _old_soname
175 # check_for_clean_repo
176 _old_versions="$(get_lt_triplet_from_file "$_cmake_file")" || die "Unable to get current LT versions"
177 _new_versions="$(increment_on_$1 "$_old_versions")" || die "Unable to get calculate refreshed LT version with strategy '$1'"
178 _old_soname="$(get_soname_from_triplet "$_old_versions")"
179 _new_soname="$(get_soname_from_triplet "$_new_versions")"
180
181 test "$_old_soname" = "$_new_soname" && die "The new and old sonames are the same '$_new_soname', which doesn't make sense."
182
183 check_for_clean_repo
184 clean_library_stash
185
186 echo "Building with the old soname"
187 build_all 2> /dev/null > /dev/null || die "Build with the old soname failed"
188 stash_library
189 check_stash_for_soname "$_old_soname" || die "Couldn't find the expected (old) soname $_old_soname, did it compile?"
190 check_stash_for_soname "$_new_soname" && die "Unexpectedly found new soname $_new_soname where only the old soname $_old_soname is supposed to be."
191
192 apply_triplets_to_file "$_old_versions" "$_new_versions" "$_cmake_file"
193
194 echo "Building with the new soname"
195 build_all 2> /dev/null > /dev/null || die "Build with the new soname failed"
196 stash_library
197 check_stash_for_soname "$_new_soname" || die "Couldn't find the expected (old) soname $_old_soname, did it compile?"
198 echo "Build went as expected, showing git diff."
199
200 git diff
201 printf "%s\n" "If you are satisfied with the diff, you can commit. Execute " "git add $_cmake_file" "" "Then 'git commit' with message" "" "Bump soname from $_old_soname to $_new_soname" "" "<X> new symbols were added, <Y> were removed."
202 }
203
204
205 # Args:
206 # $1: The string in form of "LT_CURRENT LT_REVISION LT_AGE"
207 get_soname_from_triplet()
208 {
209 local _triplet=( $1 )
210 printf "%s.%s.%s" $((_triplet[0] - _triplet[2])) ${_triplet[2]} ${_triplet[1]}
211 }
212
213
214 # Args:
215 # $1: Filename that contains possible duplications.
216 resolve_name_duplication()
217 {
218 . "$SCRIPT_DIR/naming.sh"
219 local _tempfile=/tmp/names-dedup
220 cp "$1" "$_tempfile"
221 for bad_name in "${!name_mapping[@]}"
222 do
223 sed -i "s/$bad_name/${name_mapping[$bad_name]}/" "$_tempfile"
224 done
225 cat "$_tempfile" | sort | uniq > "$1"
226 rm -- "$_tempfile"
227 }
228
229
230 get_new_authors()
231 {
232 local _all_time_authors="/tmp/all_time_authors" _recent_authors="$1" _new_authors="$2"
233 git log | grep '^Author' | cut -f 1 --complement -d ' ' | sort | uniq > "$_all_time_authors"
234 resolve_name_duplication "$_all_time_authors"
235 git log "$previous_version".. | grep '^Author' | sort | cut -f 1 --complement -d ' ' | uniq > "$_recent_authors"
236 resolve_name_duplication "$_recent_authors"
237 diff -U 0 "$_all_time_authors" "$_recent_authors" | grep -e '^+Author' | sort > "$_new_authors"
238 rm "$_all_time_authors"
239 }
240
241
242 clean_library_stash()
243 {
244 rm -rf "$LIBRARY_STASH"
245 }
246
247
248 stash_library()
249 {
250 mkdir -p "$LIBRARY_STASH"
251 cp "$BUILDDIR/src/"libopenscap.so.* "$LIBRARY_STASH/"
252 }
253
254 # Args:
255 # $1: The soname to check for (e.g. 1.2.3)
256 check_stash_for_soname()
257 {
258 local _regex
259 _regex="\.so\.$(echo "$1" | sed -e 's/\./\\./g')$"
260 ls "$LIBRARY_STASH" | grep -q "$_regex"
261 }
262
263
264 check_for_clean_repo()
265 {
266 # check that there is nothing to report by 'status' except untracked files.
267 git status --porcelain=v2 | grep -q --invert-match '^?' && die "The repository is not clean, stash your changes to proceed."
268 }
269
270
271 check_that_bump_is_appropriate()
272 {
273 check_for_clean_repo
274 # check that there is the tag
275 git tag | grep -q "$version" || die "The version '$version' doesn't have a tag, so I refuse to bump version that would make it the 'old' version."
276 # check that tarball with current version is already on GitHub.
277 curl --output /dev/null --silent --head --fail "$GITHUB_ROOT/releases/download/$version/openscap-$version.tar.gz" || die "There is not the tarball with '$version' available for download from GitHub."
278 }
279
280
281 release_to_git()
282 {
283 git tag | grep -q "$version" && die "Something is wrong - there already is a tag $version"
284 git tag "$version"
285 git push
286 git push --tags
287 }
288
289
290 # Args:
291 # $1: The filename
292 # $2: The next version
293 bump_release_in_release_script()
294 {
295 sed -i "s/\(^previous_version=\).*/\1$version/" "$1"
296 sed -i "s/\(^version=\).*/\1$2/" "$1"
297 }
298
299
300 # Args:
301 # $1: The filename
302 # $2: The next version
303 bump_release_in_cmake()
304 {
305 local _version_triplet=($(echo "$version" | tr "." "\n"))
306 local _version_names=(OPENSCAP_VERSION_MAJOR OPENSCAP_VERSION_MINOR OPENSCAP_VERSION_PATCH)
307 local _cmake="$OSCAP_REPO_ROOT/CMakeLists.txt"
308 for i in 0 1 2
309 do
310 sed -i "s/set(\s*${_version_names[$i]}\s\+\"[0-9]\+\"\s*)/set(${_version_names[$i]} \"${_version_triplet[$i]}\")/" $_cmake
311 done
312 }
313
314
315 # Args:
316 # $1: The next version
317 bump_release()
318 {
319 test $# -lt 2 || die "Provide the version number as an argument"
320 check_that_bump_is_appropriate
321 bump_release_in_cmake "$1"
322 bump_release_in_release_script "$FILE_WITH_VERSIONS" "$1"
323 git diff
324 git add "$OSCAP_REPO_ROOT/CMakeLists.txt" "$FILE_WITH_VERSIONS"
325 printf "Commit with this message:\n%s\n\n%s\n" "Version bump after release." "Next release from the maint-${1%.*} branch will be $1"
326 }
327
328 # Args:
329 # $1: Username
330 # $2: Repository owner
331 upload_to_git()
332 {
333 local _username="$1" _repo_owner="$2"
334 make_dist > /dev/null 2> /dev/null
335 curl -u ":$GITHUB_TOKEN" --data '{"tag_name":"'$version'"}' "https://api.github.com/repos/$_repo_owner/openscap/releases"
336
337 xdg-open "$GITHUB_ROOT/$_repo_owner/openscap/releases/$version"
338 }
339
340 # Args:
341 # $1: Token
342 # $2: Repository owner
343 # $3: The new version
344 flip_milestones()
345 {
346 "$SCRIPT_DIR/move-milestones.py" --owner "$2" --auth-token "$1" "$version" "$3"
347 }
348
349
350 make_news_template()
351 {
352 local _right_boundary=75 _oscap_version_string _oscap_version_length _news_template=NEWS.template _recent_authors="/tmp/recent_authors" _new_authors="/tmp/new_authors"
353
354 get_new_authors "$_recent_authors" "$_new_authors"
355
356 _oscap_version_string="openscap-$version"
357 _oscap_version_length="$(echo "$_oscap_version_string" | wc -m)"
358 printf "%s%$((_right_boundary - _oscap_version_length))s\n" "$_oscap_version_string" "$(date +%d-%m-%Y)" > "$_news_template"
359
360 printf " - %s\n" "Stats@STATS@" "New features" "Maintenance" >> "$_news_template"
361 stats=
362 stats="$stats\n - $(git log "$previous_version".. | grep '^Author' | wc -l) commits from $(cat "$_recent_authors" | wc -l) distinct persons."
363 stats="$stats\n - $(cat "$_new_authors" | wc -l) new contributors."
364 stats="$stats\n - $("$SCRIPT_DIR/query-milestones.py" --auth-token "$GITHUB_TOKEN" "$version" issues-closed | wc -l) issues closed, $("$SCRIPT_DIR/query-milestones.py" --auth-token "$GITHUB_TOKEN" "$version" prs-merged | wc -l) PRs merged."
365 sed -i "s/@STATS@/$stats/" "$_news_template"
366
367 echo >> "$_news_template"
368 echo >> "$_news_template"
369 echo "####################### Summaries #######################" >> "$_news_template"
370 echo >> "$_news_template"
371
372 echo "Closed issues:" >> "$_news_template"
373 "$SCRIPT_DIR/query-milestones.py" --auth-token "$GITHUB_TOKEN" "$version" issues-closed | sed -e 's/^/ - /' >> "$_news_template"
374
375 echo "Merged PRs:" >> "$_news_template"
376 "$SCRIPT_DIR/query-milestones.py" --auth-token "$GITHUB_TOKEN" "$version" prs-merged | sed -e 's/^/ - /' >> "$_news_template"
377
378 echo "New authors:" >> "$_news_template"
379 sed -e 's/^/ - /' "$_new_authors" >> "$_news_template"
380
381 echo "Recent authors:" >> "$_news_template"
382 sed -e 's/^/ - /' "$_recent_authors" >> "$_news_template"
383
384 rm -- "$_recent_authors" "$_new_authors"
385 }
386
387
388 check_release_is_ok()
389 {
390 grep -q "^openscap-$version" "$OSCAP_REPO_ROOT/NEWS" || die "The version '$version' isn't mentioned in the NEWS file."
391 git log -1 | grep -q "^\s*openscap-$version$" || die "The openscap release commit is not the previous commit."
392 }
393
394
395 # Args:
396 # $1: The future version number
397 release_to_git_and_bump_release()
398 {
399 local _new_version="$1"
400 test -n "$GITHUB_TOKEN" || die "We don't know your GitHub token, so we can't proceed. Get one on https://github.com/settings/tokens and put it in the .env file, so it contains the line GITHUB_TOKEN='<your token here>'"
401 test "$1" = "$version" && die "The new version is the same as current version, I am not doing anything."
402 check_release_is_ok
403 # release_to_git # GH now add tags to the release automatically
404 # upload_to_git # to be done when https://github.com/PyGithub/PyGithub/pull/525 is merged.
405 flip_milestones "$GITHUB_TOKEN" openscap "$_new_version"
406 bump_release "$_new_version"
407 }