Debian Codegraph @

scripts/release/check.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] VERSION"
33 print
34 print -- "Validate fswatch release metadata without modifying the repository."
35 print
36 print -- "Options:"
37 print -- " --release Require VERSION to be a releasable version, not -develop."
38 print -- " --require-clean Require no tracked working-tree changes."
39 print -- " --require-dist Require fswatch-VERSION.tar.gz to exist."
40 print -- " --require-annotated-tag Require VERSION to exist as an annotated local tag."
41 print -- " --require-libfswatch-news Require NEWS.libfswatch top section to match VERSION."
42 print -- " --notes FILE Validate a GitHub release notes file."
43 print -- " -h, --help Print this message."
44 }
45
46 typeset -i release_mode=0
47 typeset -i require_clean=0
48 typeset -i require_dist=0
49 typeset -i require_annotated_tag=0
50 typeset -i require_libfswatch_news=0
51 notes_file=
52
53 while (( $# > 0 ))
54 do
55 case "$1" in
56 --release)
57 release_mode=1
58 shift
59 ;;
60 --require-clean)
61 require_clean=1
62 shift
63 ;;
64 --require-dist)
65 require_dist=1
66 shift
67 ;;
68 --require-annotated-tag)
69 require_annotated_tag=1
70 shift
71 ;;
72 --require-libfswatch-news)
73 require_libfswatch_news=1
74 shift
75 ;;
76 --notes)
77 (( $# >= 2 )) || release_die "--notes requires a file"
78 notes_file=$2
79 shift 2
80 ;;
81 -h|--help)
82 usage
83 exit 0
84 ;;
85 --)
86 shift
87 break
88 ;;
89 -*)
90 release_die "unknown option: $1"
91 ;;
92 *)
93 break
94 ;;
95 esac
96 done
97
98 (( $# == 1 )) || {
99 usage
100 exit 1
101 }
102
103 release_parse_version "$1"
104
105 repo_root=$(release_repo_root)
106 cd "${repo_root}"
107
108 typeset -i failures=0
109
110 fail()
111 {
112 print -u2 -- "FAIL: $*"
113 failures+=1
114 }
115
116 pass()
117 {
118 print -- "ok: $*"
119 }
120
121 check_equal()
122 {
123 local label=$1
124 local expected=$2
125 local actual=$3
126
127 if [[ "${actual}" == "${expected}" ]]
128 then
129 pass "${label} is ${expected}"
130 else
131 fail "${label}: expected '${expected}', found '${actual}'"
132 fi
133 }
134
135 if (( release_mode && RELEASE_IS_DEVELOP ))
136 then
137 fail "--release does not allow -develop versions"
138 fi
139
140 if (( require_clean ))
141 then
142 tracked_status=$(git status --short --untracked-files=no)
143 if [[ -z "${tracked_status}" ]]
144 then
145 pass "tracked working tree is clean"
146 else
147 fail "tracked working tree has changes"
148 print -u2 -- "${tracked_status}"
149 fi
150 fi
151
152 fswatch_version=$(release_m4_define m4/fswatch_version.m4 FSWATCH_VERSION)
153 libfswatch_version=$(release_m4_define m4/libfswatch_version.m4 LIBFSWATCH_VERSION)
154 libfswatch_api_version=$(release_m4_define m4/libfswatch_version.m4 LIBFSWATCH_API_VERSION)
155 cmake_project_version=$(release_cmake_project_version)
156 cmake_version_modifier=$(release_cmake_version_modifier)
157 news_version=$(release_news_top_version NEWS)
158 libfswatch_news_version=$(release_news_top_version NEWS.libfswatch)
159
160 check_equal "FSWATCH_VERSION" "${RELEASE_VERSION}" "${fswatch_version}"
161 check_equal "LIBFSWATCH_VERSION" "${RELEASE_VERSION}" "${libfswatch_version}"
162 check_equal "CMake project version" "${RELEASE_BASE_VERSION}" "${cmake_project_version}"
163 check_equal "CMake VERSION_MODIFIER" "${RELEASE_VERSION_MODIFIER}" "${cmake_version_modifier}"
164 check_equal "NEWS top version" "${RELEASE_VERSION}" "${news_version}"
165
166 if [[ "${libfswatch_news_version}" == "${RELEASE_VERSION}" ]]
167 then
168 pass "NEWS.libfswatch top version is ${RELEASE_VERSION}"
169 elif (( require_libfswatch_news ))
170 then
171 fail "NEWS.libfswatch: expected top version '${RELEASE_VERSION}', found '${libfswatch_news_version}'"
172 else
173 release_warn "NEWS.libfswatch top version is '${libfswatch_news_version}', not '${RELEASE_VERSION}'"
174 fi
175
176 if [[ "${libfswatch_api_version}" == <->:<->:<-> ]]
177 then
178 pass "LIBFSWATCH_API_VERSION is ${libfswatch_api_version}"
179 else
180 fail "LIBFSWATCH_API_VERSION is not current:revision:age: '${libfswatch_api_version}'"
181 fi
182
183 if (( require_dist ))
184 then
185 dist_file="fswatch-${RELEASE_VERSION}.tar.gz"
186 if [[ -f "${dist_file}" ]]
187 then
188 pass "distribution tarball exists: ${dist_file}"
189 else
190 fail "distribution tarball is missing: ${dist_file}"
191 fi
192 fi
193
194 if (( require_annotated_tag ))
195 then
196 tag_type=$(release_tag_type "${RELEASE_VERSION}")
197 if [[ "${tag_type}" == "tag" ]]
198 then
199 pass "local tag ${RELEASE_VERSION} is annotated"
200 elif [[ -z "${tag_type}" ]]
201 then
202 fail "local tag ${RELEASE_VERSION} does not exist"
203 else
204 fail "local tag ${RELEASE_VERSION} is '${tag_type}', not an annotated tag"
205 fi
206 fi
207
208 if [[ -n "${notes_file}" ]]
209 then
210 if [[ ! -f "${notes_file}" ]]
211 then
212 fail "release notes file does not exist: ${notes_file}"
213 else
214 expected_title="# What's New in fswatch v. ${RELEASE_VERSION}:"
215 if grep -Fqx "${expected_title}" "${notes_file}"
216 then
217 pass "release notes title matches ${RELEASE_VERSION}"
218 else
219 fail "release notes title is missing: ${expected_title}"
220 fi
221
222 expected_intro="\`fswatch\` v. ${RELEASE_VERSION} introduces the following features and bug fixes:"
223 if grep -Fqx "${expected_intro}" "${notes_file}"
224 then
225 pass "release notes fswatch intro matches ${RELEASE_VERSION}"
226 else
227 fail "release notes fswatch intro is missing"
228 fi
229 fi
230 fi
231
232 if (( failures > 0 ))
233 then
234 print -u2 -- "${failures} release check(s) failed."
235 exit 1
236 fi
237
238 print -- "All release checks passed for ${RELEASE_VERSION}."