Debian Codegraph @

scripts/release/test.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} [options]"
33 print
34 print -- "Run non-publishing tests for the release automation."
35 print
36 print -- "Options:"
37 print -- " --release VERSION Simulated release version. Default: 1.19.0."
38 print -- " --next VERSION Simulated next development version. Default: 1.20.0."
39 print -- " --dist Also run autogen, configure, and make -j dist."
40 print -- " --distcheck Also run autogen, configure, and make -j distcheck."
41 print -- " --keep-worktree Keep the temporary worktree for inspection."
42 print -- " -h, --help Print this message."
43 }
44
45 release_version=1.19.0
46 next_version=1.20.0
47 typeset -i run_dist=0
48 typeset -i run_distcheck=0
49 typeset -i keep_worktree=0
50
51 while (( $# > 0 ))
52 do
53 case "$1" in
54 --release)
55 (( $# >= 2 )) || release_die "--release requires VERSION"
56 release_version=$2
57 shift 2
58 ;;
59 --next)
60 (( $# >= 2 )) || release_die "--next requires VERSION"
61 next_version=$2
62 shift 2
63 ;;
64 --dist)
65 run_dist=1
66 shift
67 ;;
68 --distcheck)
69 run_distcheck=1
70 shift
71 ;;
72 --keep-worktree)
73 keep_worktree=1
74 shift
75 ;;
76 -h|--help)
77 usage
78 exit 0
79 ;;
80 --)
81 shift
82 break
83 ;;
84 -*)
85 release_die "unknown option: $1"
86 ;;
87 *)
88 release_die "unexpected argument: $1"
89 ;;
90 esac
91 done
92
93 release_parse_version "${release_version}"
94 (( ! RELEASE_IS_DEVELOP )) ||
95 release_die "--release must be a releasable version, not -develop"
96
97 release_parse_version "${next_version}"
98 [[ -z "${RELEASE_VERSION_MODIFIER}" ]] ||
99 release_die "--next must be numeric X.Y.Z"
100
101 repo_root=$(release_repo_root)
102 cd "${repo_root}"
103
104 tmp_parent=$(mktemp -d /tmp/fswatch-release-test.XXXXXX)
105 tmp_worktree="${tmp_parent}/worktree"
106
107 cleanup()
108 {
109 local exit_status=$?
110
111 if (( keep_worktree ))
112 then
113 print -- "Kept temporary worktree: ${tmp_worktree}"
114 print -- "Remove it with: git worktree remove '${tmp_worktree}'"
115 else
116 git worktree remove --force "${tmp_worktree}" > /dev/null 2>&1 || true
117 rm -rf "${tmp_parent}"
118 fi
119
120 exit ${exit_status}
121 }
122
123 trap cleanup EXIT INT TERM
124
125 print -- "Creating temporary worktree: ${tmp_worktree}"
126 git worktree add --detach --quiet "${tmp_worktree}" HEAD
127
128 print -- "Overlaying current release scripts into temporary worktree."
129 rm -rf "${tmp_worktree}/scripts/release"
130 mkdir -p "${tmp_worktree}/scripts"
131 cp -R "${repo_root}/scripts/release" "${tmp_worktree}/scripts/"
132
133 cd "${tmp_worktree}"
134
135 print -- "Running shell syntax checks."
136 zsh -n scripts/release/*.zsh
137
138 print -- "Checking current development metadata."
139 current_version=$(release_m4_define m4/fswatch_version.m4 FSWATCH_VERSION)
140 scripts/release/check.zsh "${current_version}"
141
142 release_parse_version "${current_version}"
143 current_is_develop=${RELEASE_IS_DEVELOP}
144
145 print -- "Checking release guards."
146 if (( current_is_develop ))
147 then
148 if scripts/release/check.zsh --release "${current_version}" > release-check-develop.log 2>&1
149 then
150 release_die "--release unexpectedly accepted ${current_version}"
151 fi
152 else
153 scripts/release/check.zsh --release "${current_version}" > /dev/null
154 fi
155
156 if [[ "${current_version}" != "${release_version}" ]]
157 then
158 if scripts/release/check.zsh --release "${release_version}" > release-check-unprepared.log 2>&1
159 then
160 release_die "unprepared release check unexpectedly passed for ${release_version}"
161 fi
162 fi
163
164 print -- "Running dry-run helpers."
165 scripts/release/prepare.zsh "${release_version}" > /dev/null
166 scripts/release/post-release.zsh "${next_version}" > /dev/null
167
168 print -- "Preparing simulated release ${release_version}."
169 scripts/release/prepare.zsh --apply "${release_version}"
170
171 tmp_news=NEWS.tmp.$$
172 awk -v version="${release_version}" -v old_version="${current_version}" '
173 NR == 1 { print; next }
174 NR == 2 {
175 print
176 print ""
177 print "New in " version ":"
178 print ""
179 next
180 }
181 $0 == "New in " old_version ":" { next }
182 { print }
183 ' NEWS > "${tmp_news}"
184 mv "${tmp_news}" NEWS
185
186 scripts/release/check.zsh "${release_version}"
187
188 print -- "Generating and validating release notes."
189 scripts/release/notes.zsh --output release-notes.md "${release_version}"
190 scripts/release/check.zsh --release --notes release-notes.md "${release_version}"
191
192 print -- "Checking tarball-name validation with a dummy file."
193 touch "fswatch-${release_version}.tar.gz"
194 scripts/release/check.zsh --release --require-dist "${release_version}"
195 rm "fswatch-${release_version}.tar.gz"
196
197 print -- "Checking publish dry-run."
198 scripts/release/publish.zsh --notes release-notes.md "${release_version}" > publish-dry-run.log
199
200 if (( run_dist || run_distcheck ))
201 then
202 print -- "Bootstrapping and configuring the temporary release worktree."
203 ./autogen.sh
204 CC=${CC:-gcc} CXX=${CXX:-g++} ./configure
205 fi
206
207 if (( run_dist ))
208 then
209 print -- "Running make -j dist."
210 make -j dist
211 scripts/release/check.zsh --release --require-dist "${release_version}"
212 fi
213
214 if (( run_distcheck ))
215 then
216 print -- "Running make -j distcheck."
217 make -j distcheck
218 scripts/release/check.zsh --release --require-dist "${release_version}"
219 fi
220
221 print -- "Preparing simulated post-release development version ${next_version}-develop."
222 scripts/release/post-release.zsh --apply "${next_version}"
223 scripts/release/check.zsh "${next_version}-develop"
224
225 print -- "Release automation tests passed."