Debian Codegraph @

scripts/release/watch.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 -- "Watch the GitHub release workflow and verify uploaded release assets."
35 print -- "When VERSION is omitted, read it from m4/fswatch_version.m4."
36 print
37 print -- "Options:"
38 print -- " --repo OWNER/REPO GitHub repository. Default: ${RELEASE_REPO}."
39 print -- " --workflow NAME Workflow file or name. Default: release-tarball.yml."
40 print -- " --run-id ID Use an explicit GitHub Actions run ID."
41 print -- " --no-watch Do not wait; only inspect the current run state."
42 print -- " --timeout SECONDS Wait up to this long for the run to appear. Default: 120."
43 print -- " --poll SECONDS Poll interval while waiting for the run. Default: 5."
44 print -- " -h, --help Print this message."
45 }
46
47 repo=${RELEASE_REPO}
48 workflow=release-tarball.yml
49 run_id=
50 typeset -i do_watch=1
51 typeset -i timeout_seconds=120
52 typeset -i poll_seconds=5
53
54 while (( $# > 0 ))
55 do
56 case "$1" in
57 --repo)
58 (( $# >= 2 )) || release_die "--repo requires OWNER/REPO"
59 repo=$2
60 shift 2
61 ;;
62 --workflow)
63 (( $# >= 2 )) || release_die "--workflow requires a workflow file or name"
64 workflow=$2
65 shift 2
66 ;;
67 --run-id)
68 (( $# >= 2 )) || release_die "--run-id requires a GitHub Actions run ID"
69 run_id=$2
70 shift 2
71 ;;
72 --no-watch)
73 do_watch=0
74 shift
75 ;;
76 --timeout)
77 (( $# >= 2 )) || release_die "--timeout requires seconds"
78 [[ "$2" == <-> ]] || release_die "--timeout requires a non-negative integer"
79 timeout_seconds=$2
80 shift 2
81 ;;
82 --poll)
83 (( $# >= 2 )) || release_die "--poll requires seconds"
84 [[ "$2" == <-> ]] || release_die "--poll requires a non-negative integer"
85 (( $2 > 0 )) || release_die "--poll must be greater than zero"
86 poll_seconds=$2
87 shift 2
88 ;;
89 -h|--help)
90 usage
91 exit 0
92 ;;
93 --)
94 shift
95 break
96 ;;
97 -*)
98 release_die "unknown option: $1"
99 ;;
100 *)
101 break
102 ;;
103 esac
104 done
105
106 (( $# <= 1 )) || {
107 usage
108 exit 1
109 }
110
111 if (( $# == 1 ))
112 then
113 release_version=$1
114 else
115 repo_root=$(release_repo_root)
116 cd "${repo_root}"
117 release_version=$(release_m4_define m4/fswatch_version.m4 FSWATCH_VERSION)
118 [[ -n "${release_version}" ]] ||
119 release_die "could not read FSWATCH_VERSION from m4/fswatch_version.m4"
120 fi
121
122 release_parse_version "${release_version}"
123 (( ! RELEASE_IS_DEVELOP )) ||
124 release_die "release workflow checks require a releasable version, not -develop"
125
126 command -v gh > /dev/null ||
127 release_die "gh is required to inspect GitHub Actions and releases"
128
129 if [[ -z "${run_id}" ]]
130 then
131 typeset -i waited_seconds=0
132 while true
133 do
134 run_id=$(gh run list \
135 --repo "${repo}" \
136 --workflow "${workflow}" \
137 --event release \
138 --limit 20 \
139 --json databaseId,headBranch \
140 --jq ".[] | select(.headBranch == \"${RELEASE_VERSION}\") | .databaseId" |
141 sed -n '1p')
142
143 [[ -n "${run_id}" ]] && break
144
145 (( waited_seconds >= timeout_seconds )) && break
146
147 print -- "Waiting for ${workflow} release run for ${RELEASE_VERSION}..."
148 sleep "${poll_seconds}"
149 waited_seconds+=poll_seconds
150 done
151
152 [[ -n "${run_id}" ]] || {
153 gh run list \
154 --repo "${repo}" \
155 --workflow "${workflow}" \
156 --event release \
157 --limit 10
158 release_die "could not find a ${workflow} release run for ${RELEASE_VERSION}"
159 }
160 fi
161
162 print -- "Release workflow run for ${RELEASE_VERSION}: ${run_id}"
163
164 if (( do_watch ))
165 then
166 gh run watch "${run_id}" --repo "${repo}" --exit-status
167 fi
168
169 run_status=$(gh run view "${run_id}" --repo "${repo}" --json status --jq .status)
170 run_conclusion=$(gh run view "${run_id}" --repo "${repo}" --json conclusion --jq .conclusion)
171 run_url=$(gh run view "${run_id}" --repo "${repo}" --json url --jq .url)
172
173 print -- "Workflow status: ${run_status}"
174 print -- "Workflow conclusion: ${run_conclusion}"
175 print -- "Workflow URL: ${run_url}"
176
177 [[ "${run_status}" == "completed" ]] ||
178 release_die "workflow run has not completed"
179
180 [[ "${run_conclusion}" == "success" ]] ||
181 release_die "workflow run did not succeed"
182
183 release_url=$(gh release view "${RELEASE_VERSION}" --repo "${repo}" --json url --jq .url)
184 release_tag=$(gh release view "${RELEASE_VERSION}" --repo "${repo}" --json tagName --jq .tagName)
185 asset_names=$(gh release view "${RELEASE_VERSION}" --repo "${repo}" --json assets --jq '.assets[].name')
186
187 [[ "${release_tag}" == "${RELEASE_VERSION}" ]] ||
188 release_die "GitHub release tag is ${release_tag}, expected ${RELEASE_VERSION}"
189
190 expected_tarball="fswatch-${RELEASE_VERSION}.tar.gz"
191 expected_static_binary="fswatch-${RELEASE_VERSION}-linux-x86_64-static.tar.gz"
192 expected_pdf="fswatch-${RELEASE_VERSION}.pdf"
193 expected_doxygen_html="fswatch-${RELEASE_VERSION}-libfswatch-doxygen-html.tar.gz"
194 typeset -i failures=0
195
196 for expected_asset in \
197 "${expected_tarball}" \
198 "${expected_static_binary}" \
199 "${expected_pdf}" \
200 "${expected_doxygen_html}"
201 do
202 if print -r -- "${asset_names}" | grep -Fxq "${expected_asset}"
203 then
204 print -- "ok: release asset exists: ${expected_asset}"
205 else
206 print -u2 -- "FAIL: release asset is missing: ${expected_asset}"
207 failures+=1
208 fi
209 done
210
211 extra_assets=$(print -r -- "${asset_names}" |
212 grep -Fvx \
213 -e "${expected_tarball}" \
214 -e "${expected_static_binary}" \
215 -e "${expected_pdf}" \
216 -e "${expected_doxygen_html}" || true)
217
218 if [[ -n "${extra_assets}" ]]
219 then
220 release_warn "unexpected explicit release assets:"
221 print -u2 -- "${extra_assets}"
222 fi
223
224 (( failures == 0 )) ||
225 release_die "release asset verification failed"
226
227 print -- "GitHub release URL: ${release_url}"
228 print -- "Release workflow and assets verified for ${RELEASE_VERSION}."