Debian Codegraph @

scripts/release/prepare.zsh

raw
1 #!/bin/zsh
2 # -*- vim:fenc=utf-8:et:sw=2:ts=2:sts=2
3 #
4 # Copyright (c) 2026 Enrico M. Crisostomo
5 #
6 # This program is free software; you can redistribute it and/or modify it under
7 # the terms of the GNU General Public License as published by the Free Software
8 # Foundation; either version 3, or (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 # details.
14 #
15 # You should have received a copy of the GNU General Public License along with
16 # this program. If not, see <http://www.gnu.org/licenses/>.
17
18 setopt local_options
19 setopt local_traps
20 unsetopt glob_subst
21
22 set -o errexit
23 set -o nounset
24
25 PROGNAME=${0:t}
26 PROGDIR=${0:A:h}
27
28 . "${PROGDIR}/lib.zsh"
29
30 usage()
31 {
32 print -- "Usage: ${PROGNAME} [--apply] VERSION"
33 print
34 print -- "Prepare version files for VERSION."
35 print -- "Without --apply, only print the edits that would be made."
36 print
37 print -- "VERSION may be X.Y.Z, X.Y.Z-rcN, or X.Y.Z-develop."
38 }
39
40 typeset -i apply=0
41
42 while (( $# > 0 ))
43 do
44 case "$1" in
45 --apply)
46 apply=1
47 shift
48 ;;
49 --dry-run)
50 apply=0
51 shift
52 ;;
53 -h|--help)
54 usage
55 exit 0
56 ;;
57 --)
58 shift
59 break
60 ;;
61 -*)
62 release_die "unknown option: $1"
63 ;;
64 *)
65 break
66 ;;
67 esac
68 done
69
70 (( $# == 1 )) || {
71 usage
72 exit 1
73 }
74
75 release_parse_version "$1"
76
77 repo_root=$(release_repo_root)
78 cd "${repo_root}"
79
80 print -- "Version file preparation:"
81 print -- " FSWATCH_VERSION=${RELEASE_VERSION}"
82 print -- " LIBFSWATCH_VERSION=${RELEASE_VERSION}"
83 print -- " CMake project version=${RELEASE_BASE_VERSION}"
84 print -- " CMake VERSION_MODIFIER=${RELEASE_VERSION_MODIFIER}"
85
86 if (( ! apply ))
87 then
88 print -- "Dry run only. Re-run with --apply to edit files."
89 exit 0
90 fi
91
92 tmp_file=m4/fswatch_version.m4.tmp.$$
93 awk -v value="${RELEASE_VERSION}" '
94 /^m4_define\(\[FSWATCH_VERSION\], \[/ {
95 print "m4_define([FSWATCH_VERSION], [" value "])"
96 next
97 }
98 { print }
99 ' m4/fswatch_version.m4 > "${tmp_file}"
100 mv "${tmp_file}" m4/fswatch_version.m4
101
102 tmp_file=m4/libfswatch_version.m4.tmp.$$
103 awk -v value="${RELEASE_VERSION}" '
104 /^m4_define\(\[LIBFSWATCH_VERSION\], \[/ {
105 print "m4_define([LIBFSWATCH_VERSION], [" value "])"
106 next
107 }
108 { print }
109 ' m4/libfswatch_version.m4 > "${tmp_file}"
110 mv "${tmp_file}" m4/libfswatch_version.m4
111
112 tmp_file=CMakeLists.txt.tmp.$$
113 awk -v base="${RELEASE_BASE_VERSION}" -v modifier="${RELEASE_VERSION_MODIFIER}" '
114 /^project\(fswatch VERSION / {
115 print "project(fswatch VERSION " base " LANGUAGES C CXX)"
116 next
117 }
118 /^set\(VERSION_MODIFIER / {
119 print "set(VERSION_MODIFIER \"" modifier "\")"
120 next
121 }
122 { print }
123 ' CMakeLists.txt > "${tmp_file}"
124 mv "${tmp_file}" CMakeLists.txt
125
126 [[ "$(release_m4_define m4/fswatch_version.m4 FSWATCH_VERSION)" == "${RELEASE_VERSION}" ]] ||
127 release_die "failed to update FSWATCH_VERSION"
128 [[ "$(release_m4_define m4/libfswatch_version.m4 LIBFSWATCH_VERSION)" == "${RELEASE_VERSION}" ]] ||
129 release_die "failed to update LIBFSWATCH_VERSION"
130 [[ "$(release_cmake_project_version)" == "${RELEASE_BASE_VERSION}" ]] ||
131 release_die "failed to update CMake project version"
132 [[ "$(release_cmake_version_modifier)" == "${RELEASE_VERSION_MODIFIER}" ]] ||
133 release_die "failed to update CMake VERSION_MODIFIER"
134
135 print -- "Updated version files. Review LIBFSWATCH_API_VERSION and changelogs manually."
136 print -- "When a changelog item comes from a GitHub PR or issue, include those numbers."