返回 CodeWhale
check-versions.sh
根目录 / scripts / release / check-versions.sh
1 #!/usr/bin/env bash
2 # Fails CI if version state is inconsistent across the workspace, npm
3 # wrapper, and Cargo.lock. Every full ci.yml run includes it so silent drift
4 # can't ship.
5 #
6 # Checks performed:
7 # 1. No `crates/*/Cargo.toml` carries a literal `version = "x.y.z"`; every
8 # crate must inherit `version.workspace = true`.
9 # 2. Every crate inherits the workspace MSRV through
10 # `rust-version.workspace = true`.
11 # 3. Release package manifests, the npm wrapper's binary pin, and their
12 # workspace lock records match the workspace `version` in the root
13 # `Cargo.toml`.
14 # (If legacy `npm/deepseek-tui/package.json` is present, it must stay
15 # private and unpublished.)
16 # 4. Internal `codewhale-*` path dependency pins match the workspace version.
17 # 5. The TUI crate's packaged changelog copy matches root `CHANGELOG.md`.
18 # 6. The current version has either an explicit source-candidate entry or a
19 # dated Keep a Changelog release entry and a matching compare link.
20 # 7. README contributor additions are mentioned in the current release entry.
21 # 8. `.github/SECURITY.md` keeps the dedicated security contact.
22 # 9. Generated website facts carry the workspace version.
23 # 10. Public install and version snippets point at the current release.
24 # 11. `codewhale-app-server` stays library-only; the shipped app-server
25 # entrypoint belongs to `codewhale-cli`.
26 # 12. Issue-linked feature commits have a durable changelog receipt.
27 # 13. `Cargo.lock` is in sync with the manifests (`cargo metadata --locked`
28 # fails if not).
29 # 14. Version-stamped contract fixtures (`providers-export.golden.json` and
30 # the config-policy status baseline) match the workspace version.
31 set -euo pipefail
32
33 require_dated_release=0
34 # Checks 7 and 12 audit a *commit range* (previous tag..HEAD), not the working
35 # tree. Debt left by an already-landed commit therefore reddens this gate for
36 # every unrelated run. ci.yml passes --range-audit-advisory so that class of
37 # failure reports without blocking; every release path (release-candidate.yml,
38 # auto-tag.yml, release.yml, prepare-release.sh) still runs them blocking, so
39 # nothing can be published without its receipt.
40 range_audit_advisory=0
41 while [[ "$#" -gt 0 ]]; do
42 case "$1" in
43 --require-dated-release) require_dated_release=1; shift ;;
44 --range-audit-advisory) range_audit_advisory=1; shift ;;
45 *)
46 echo "Usage: $0 [--require-dated-release] [--range-audit-advisory]" >&2
47 exit 2
48 ;;
49 esac
50 done
51 if [[ "${require_dated_release}" == "1" && "${range_audit_advisory}" == "1" ]]; then
52 echo "::error::--range-audit-advisory must not be combined with --require-dated-release; publication requires the range audit to block." >&2
53 exit 2
54 fi
55
56 cd "$(dirname "$0")/../.."
57
58 fail=0
59
60 # 1) Literal versions in crate manifests.
61 literals="$(grep -nE '^version = "' crates/*/Cargo.toml || true)"
62 if [[ -n "${literals}" ]]; then
63 echo "::error::Crate manifests must use 'version.workspace = true', not literal versions:" >&2
64 echo "${literals}" >&2
65 fail=1
66 fi
67
68 # 2) Workspace MSRV inheritance. A workspace value is not included in package
69 # metadata unless every member opts in, which would silently omit the MSRV from
70 # all crates.io manifests.
71 missing_rust_version=""
72 for manifest in crates/*/Cargo.toml; do
73 if ! grep -qxF 'rust-version.workspace = true' "${manifest}"; then
74 missing_rust_version+="${manifest}"$'\n'
75 fi
76 done
77 if [[ -n "${missing_rust_version}" ]]; then
78 echo "::error::Every crate manifest must inherit the workspace MSRV with 'rust-version.workspace = true':" >&2
79 printf '%s' "${missing_rust_version}" >&2
80 fail=1
81 fi
82
83 # 3) Workspace ↔ npm package.json/version + binary pin ↔ root package lock.
84 workspace_version="$(grep -E '^version = "' Cargo.toml | head -n1 | sed -E 's/^version = "([^"]+)".*/\1/')"
85 npm_version="$(node -p "require('./npm/codewhale/package.json').version")"
86 npm_binary_version="$(node -p "require('./npm/codewhale/package.json').codewhaleBinaryVersion ?? ''")"
87 if [[ "${workspace_version}" != "${npm_version}" ]]; then
88 echo "::error::npm/codewhale/package.json version (${npm_version}) does not match workspace Cargo.toml (${workspace_version})." >&2
89 fail=1
90 fi
91 if ! ./scripts/release/check-npm-binary-version.sh \
92 "${workspace_version}" "${npm_binary_version}"; then
93 fail=1
94 fi
95 lock_npm_version="$(node -p "require('./package-lock.json').packages?.['npm/codewhale']?.version ?? ''")"
96 if [[ "${workspace_version}" != "${lock_npm_version}" ]]; then
97 echo "::error::package-lock.json npm/codewhale version (${lock_npm_version:-<missing>}) does not match workspace Cargo.toml (${workspace_version})." >&2
98 echo "Run: npm install --package-lock-only --ignore-scripts" >&2
99 fail=1
100 fi
101 runtime_sdk_version="$(node -p "require('./npm/runtime-sdk/package.json').version")"
102 lock_runtime_sdk_version="$(node -p "require('./package-lock.json').packages?.['npm/runtime-sdk']?.version ?? ''")"
103 vscode_version="$(node -p "require('./extensions/vscode/package.json').version")"
104 vscode_lock_version="$(node -p "require('./extensions/vscode/package-lock.json').version ?? ''")"
105 vscode_lock_workspace_version="$(node -p "require('./extensions/vscode/package-lock.json').packages?.['']?.version ?? ''")"
106 for pair in \
107 "npm/runtime-sdk/package.json:${runtime_sdk_version}" \
108 "package-lock.json npm/runtime-sdk:${lock_runtime_sdk_version}" \
109 "extensions/vscode/package.json:${vscode_version}" \
110 "extensions/vscode/package-lock.json:${vscode_lock_version}" \
111 "extensions/vscode/package-lock.json workspace:${vscode_lock_workspace_version}"; do
112 label="${pair%%:*}"
113 actual="${pair#*:}"
114 if [[ "${actual}" != "${workspace_version}" ]]; then
115 echo "::error::${label} version (${actual:-<missing>}) does not match workspace Cargo.toml (${workspace_version})." >&2
116 fail=1
117 fi
118 done
119 if [[ -f npm/deepseek-tui/package.json ]]; then
120 legacy_private="$(node -p "Boolean(require('./npm/deepseek-tui/package.json').private)")"
121 legacy_publish_config="$(node -p "Boolean(require('./npm/deepseek-tui/package.json').publishConfig)")"
122 if [[ "${legacy_private}" != "true" ]]; then
123 echo "::error::npm/deepseek-tui/package.json must stay private so the legacy package is not republished." >&2
124 fail=1
125 fi
126 if [[ "${legacy_publish_config}" == "true" ]]; then
127 echo "::error::npm/deepseek-tui/package.json must not define publishConfig; the legacy package is deprecated." >&2
128 fail=1
129 fi
130 fi
131
132 # 4) Internal path dependency pins.
133 internal_dep_drift="$(
134 grep -nE 'codewhale-[a-z-]+[[:space:]]*=[[:space:]]*\{[^}]*version[[:space:]]*=[[:space:]]*"' crates/*/Cargo.toml vendor/codewhale-ratatui/Cargo.toml \
135 | grep -vF 'codewhale-ratatui = { path = "../../vendor/codewhale-ratatui", version = "0.2.2" }' \
136 | grep -v "version[[:space:]]*=[[:space:]]*\"${workspace_version}\"" || true
137 )"
138 if [[ -n "${internal_dep_drift}" ]]; then
139 echo "::error::Internal codewhale-* path dependency versions must match workspace version ${workspace_version}:" >&2
140 echo "${internal_dep_drift}" >&2
141 fail=1
142 fi
143
144 # 5) Packaged TUI changelog slice (recent releases embedded in the binary).
145 if ! ./scripts/sync-changelog.sh --check >/dev/null 2>&1; then
146 echo "::error::crates/tui/CHANGELOG.md is out of date with the root CHANGELOG.md slice." >&2
147 echo "Run: ./scripts/sync-changelog.sh" >&2
148 fail=1
149 fi
150
151 # 6) Current candidate/release-note shape. Normal branch CI must accept an
152 # honest source candidate. The release candidate, tag creation and public
153 # release workflows pass --require-dated-release so publication cannot proceed
154 # until the same entry has a real release date and tag-based compare link (an
155 # RC receipt only counts for the exact tag SHA, so it must see the dated entry).
156 current_section="$(
157 awk -v version="${workspace_version}" '
158 index($0, "## [" version "] - ") == 1 { in_section = 1; print; next }
159 in_section && /^## \[/ { exit }
160 in_section { print }
161 ' CHANGELOG.md
162 )"
163 if [[ -z "${current_section}" ]]; then
164 echo "::error::CHANGELOG.md must contain a section for ${workspace_version}." >&2
165 fail=1
166 else
167 dated_heading="## [${workspace_version}] - YYYY-MM-DD"
168 candidate_heading="## [${workspace_version}] - Unreleased candidate"
169 if [[ "${require_dated_release}" == "1" ]]; then
170 if ! grep -qE "^## \\[${workspace_version}\\] - [0-9]{4}-[0-9]{2}-[0-9]{2}$" <<<"${current_section}"; then
171 echo "::error::Publication requires CHANGELOG.md section ${workspace_version} to use '${dated_heading}'." >&2
172 fail=1
173 fi
174 current_summary="$(
175 awk '
176 NR == 1 { next }
177 /^### / { exit }
178 { print }
179 ' <<<"${current_section}"
180 )"
181 if grep -qiE 'source candidate' <<<"${current_summary}" ||
182 grep -qiE 'not a published release|not the final [^[:space:]]+ tag|^### Work in progress' <<<"${current_section}"; then
183 echo "::error::Publication requires CHANGELOG.md section ${workspace_version} to replace source-candidate and work-in-progress text." >&2
184 fail=1
185 fi
186 elif ! grep -qE "^## \\[${workspace_version}\\] - ([0-9]{4}-[0-9]{2}-[0-9]{2}|Unreleased candidate)$" <<<"${current_section}"; then
187 echo "::error::CHANGELOG.md section ${workspace_version} must use '${candidate_heading}' or '${dated_heading}'." >&2
188 fail=1
189 fi
190 if ! grep -qE "^### (Added|Changed|Deprecated|Removed|Fixed|Security)$" <<<"${current_section}"; then
191 echo "::error::CHANGELOG.md section ${workspace_version} must contain at least one Keep a Changelog subsection." >&2
192 fail=1
193 fi
194 fi
195
196 compare_line="$(grep -E "^\\[${workspace_version}\\]: " CHANGELOG.md || true)"
197 if [[ -z "${compare_line}" ]]; then
198 echo "::error::CHANGELOG.md must include a compare link for ${workspace_version}." >&2
199 fail=1
200 elif [[ "${require_dated_release}" == "1" ]] &&
201 ! grep -qE "^\\[${workspace_version}\\]: https://github.com/codewhale-hq/CodeWhale/compare/v[0-9]+\\.[0-9]+\\.[0-9]+\\.\\.\\.v${workspace_version}$" <<<"${compare_line}"; then
202 echo "::error::Publication requires the ${workspace_version} compare link to end at v${workspace_version}." >&2
203 fail=1
204 fi
205
206 unreleased_section="$(
207 awk '
208 index($0, "## [Unreleased]") == 1 { in_section = 1; print; next }
209 in_section && /^## \[/ { exit }
210 in_section { print }
211 ' CHANGELOG.md
212 )"
213 if [[ "${require_dated_release}" == "1" ]]; then
214 unreleased_body="$(
215 awk '
216 index($0, "## [Unreleased]") == 1 { in_section = 1; next }
217 in_section && /^## \[/ { exit }
218 in_section && /[^[:space:]]/ { print }
219 ' CHANGELOG.md
220 )"
221 if [[ -n "${unreleased_body}" ]]; then
222 echo "::error::Publication requires CHANGELOG.md [Unreleased] to be folded into ${workspace_version} before tagging." >&2
223 fail=1
224 fi
225 if [[ "${workspace_version}" != *-* ]]; then
226 if [[ -f docs/CONTRIBUTORS.md ]] && (
227 grep -qF '<summary><strong>Unreleased' docs/CONTRIBUTORS.md ||
228 grep -qF "<summary><strong>v${workspace_version} — unreleased candidate" docs/CONTRIBUTORS.md
229 ); then
230 echo "::error::Publication requires docs/CONTRIBUTORS.md to fold the Unreleased band into a titled v${workspace_version} release band." >&2
231 fail=1
232 fi
233 if [[ -f web/lib/release-credits.ts ]] &&
234 node -e 'const s = require("fs").readFileSync("web/lib/release-credits.ts", "utf8"); const m = s.match(/UNRELEASED_CONTRIBUTORS:\s*string\[\]\s*=\s*\[([\s\S]*?)\]/); process.exit(m && /@[A-Za-z0-9_-]+/.test(m[1]) ? 0 : 1);'; then
235 echo "::error::Publication requires web/lib/release-credits.ts UNRELEASED_CONTRIBUTORS to be moved into RELEASE_CONTRIBUTORS." >&2
236 fail=1
237 fi
238 fi
239 fi
240 credit_sections="${current_section}
241 ${unreleased_section}"
242
243 # 7) Contributor-credit cross-check for README additions on the release branch.
244 # This cannot prove every external PR author has been credited, but it does
245 # catch the common release-polish failure mode: adding a README contributor row
246 # without mentioning that credit/correction in the current release entry. While
247 # a release branch is still unbumped, `[Unreleased]` is also a valid credit
248 # surface.
249 previous_tag=""
250 current_tag="v${workspace_version}"
251 if [[ "${compare_line}" =~ compare/(v[0-9]+\.[0-9]+\.[0-9]+)\.\.\.${current_tag} ]]; then
252 previous_tag="${BASH_REMATCH[1]}"
253 fi
254 if [[ -n "${previous_tag}" ]]; then
255 if [[ "$(git rev-parse --is-shallow-repository 2>/dev/null || echo false)" == "true" ]]; then
256 git fetch --quiet --unshallow origin || true
257 fi
258 if ! git rev-parse -q --verify "refs/tags/${previous_tag}" >/dev/null; then
259 git fetch --quiet origin "refs/tags/${previous_tag}:refs/tags/${previous_tag}" || true
260 fi
261 if git rev-parse -q --verify "refs/tags/${previous_tag}" >/dev/null; then
262 if ! ./scripts/release/check-feature-release-notes.sh "${previous_tag}" HEAD; then
263 if [[ "${range_audit_advisory}" == "1" ]]; then
264 echo "::warning::Missing feature release-note receipt(s) above. Advisory here because this audits already-merged commits in ${previous_tag}..HEAD, not this change. It blocks every release path; fix it before the next release." >&2
265 else
266 fail=1
267 fi
268 fi
269 while IFS= read -r line; do
270 [[ -z "${line}" ]] && continue
271 handle="$(sed -E 's#.*github.com/([^)/]+).*#\1#' <<<"${line}")"
272 if [[ -n "${handle}" && "${handle}" != "${line}" ]]; then
273 if ! grep -Fq "github.com/${handle}" <<<"${credit_sections}" && ! grep -Fq "@${handle}" <<<"${credit_sections}"; then
274 if [[ "${range_audit_advisory}" == "1" ]]; then
275 echo "::warning::README.md adds contributor @${handle}, but CHANGELOG.md ${workspace_version} or [Unreleased] does not mention that credit. Advisory here; blocking on every release path." >&2
276 else
277 echo "::error::README.md adds contributor @${handle}, but CHANGELOG.md ${workspace_version} or [Unreleased] does not mention that credit." >&2
278 fail=1
279 fi
280 fi
281 fi
282 done < <(
283 git diff "${previous_tag}..HEAD" -- README.md \
284 | grep -E '^\+[-*] \*\*\[[^]]+\]\(https://github.com/[^)]+\)\*\*' || true
285 )
286 else
287 # A gate that silently no-ops is worse than no gate: it reports success and
288 # is read as evidence. If the tag cannot be resolved -- the fetch above is
289 # `|| true` and a network blip is enough -- then the feature release-note
290 # receipt check and the contributor-credit check did not run at all, and
291 # this script must not imply that they passed.
292 echo "::error::Cannot resolve refs/tags/${previous_tag}, so the feature release-note receipt and contributor-credit checks did not run. Fetch the tag and re-run; do not treat this as a pass." >&2
293 if [[ "${CWC_ALLOW_MISSING_PREVIOUS_TAG:-}" == "1" ]]; then
294 echo "::warning::CWC_ALLOW_MISSING_PREVIOUS_TAG=1 set, continuing with those two checks UNRUN." >&2
295 else
296 fail=1
297 fi
298 fi
299 fi
300
301 # 8) Security contact guard.
302 security_email="hunter@shannonlabs.dev"
303 if ! grep -qF "${security_email}" .github/SECURITY.md; then
304 echo "::error::.github/SECURITY.md must list ${security_email} as the security contact." >&2
305 fail=1
306 fi
307 if grep -qiF "@gmail.com" .github/SECURITY.md; then
308 echo "::error::.github/SECURITY.md must not list a personal @gmail.com address; use ${security_email}." >&2
309 fail=1
310 fi
311
312 # 9) Generated web facts carry the workspace version. The file is ignored and
313 # generated during web builds, so a clean CI checkout must derive it before this
314 # release guard can inspect it.
315 if [[ ! -f web/lib/facts.generated.ts ]]; then
316 node web/scripts/derive-facts.mjs
317 fi
318 facts_version="$(grep -oE '"version": "[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?"' web/lib/facts.generated.ts | head -n1 | sed -E 's/.*"([^"]+)".*/\1/')"
319 if [[ "${facts_version}" != "${workspace_version}" ]]; then
320 node web/scripts/derive-facts.mjs
321 facts_version="$(grep -oE '"version": "[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?"' web/lib/facts.generated.ts | head -n1 | sed -E 's/.*"([^"]+)".*/\1/')"
322 if [[ "${facts_version}" != "${workspace_version}" ]]; then
323 echo "::error::web/lib/facts.generated.ts version (${facts_version}) does not match workspace (${workspace_version}). Run: node web/scripts/derive-facts.mjs" >&2
324 fail=1
325 fi
326 fi
327
328 # 10) README install-tag examples point at the current release.
329 readmes=(README.md docs/i18n/README.*.md)
330 for readme in "${readmes[@]}"; do
331 if [[ ! -f "${readme}" ]]; then
332 echo "::error::Missing release README: ${readme}" >&2
333 fail=1
334 continue
335 fi
336 stale_tags="$(grep -nE -- "--tag v[0-9]+\.[0-9]+\.[0-9]+" "${readme}" | grep -v -- "--tag v${workspace_version}" || true)"
337 if [[ -n "${stale_tags}" ]]; then
338 echo "::error::${readme} has install examples pinned to an old tag (want v${workspace_version}):" >&2
339 echo "${stale_tags}" >&2
340 fail=1
341 fi
342 done
343
344 # 10b) Public install/version snippets stay on the current release (#3767).
345 # `codewhale --version # X.Y.Z` verify-your-install lines across README
346 # locales and docs/INSTALL.md, plus the docs/INSTALL.md npm-wrapper publish
347 # pointer ("published at vX.Y.Z"). These drifted while this gate still passed
348 # on a prior lane, so guard them explicitly. Narrowly scoped to those two
349 # snippet shapes to avoid flagging unrelated prose.
350 for doc in "${readmes[@]}" docs/INSTALL.md; do
351 [[ -f "${doc}" ]] || continue
352 stale_version_comments="$(grep -nE -- "codewhale --version[[:space:]]+#[[:space:]]*[0-9]+\.[0-9]+\.[0-9]+" "${doc}" | grep -vE -- "#[[:space:]]*${workspace_version}([^0-9]|$)" || true)"
353 if [[ -n "${stale_version_comments}" ]]; then
354 echo "::error::${doc} has 'codewhale --version # X' snippet(s) not on ${workspace_version}:" >&2
355 echo "${stale_version_comments}" >&2
356 fail=1
357 fi
358 done
359
360 # The publish pointer can wrap onto the next line; also scan the line after the lead-in.
361 wrapper_pointer_version="$(grep -A1 -E -- "wrapper is published at" docs/INSTALL.md | grep -oE -- "v[0-9]+\.[0-9]+\.[0-9]+" | head -n1 || true)"
362 if [[ -n "${wrapper_pointer_version}" && "${wrapper_pointer_version}" != "v${workspace_version}" ]]; then
363 echo "::error::docs/INSTALL.md npm-wrapper publish pointer is ${wrapper_pointer_version}, want v${workspace_version}." >&2
364 fail=1
365 fi
366
367 if [[ -f scripts/check-docs-drift.py ]]; then
368 if ! python3 scripts/check-docs-drift.py --version-drift-only; then
369 fail=1
370 fi
371 fi
372
373 # 11) App-server is not a standalone binary.
374 app_server_bins="$(
375 cargo metadata --locked --format-version 1 --no-deps \
376 | node -e '
377 const fs = require("fs");
378 const metadata = JSON.parse(fs.readFileSync(0, "utf8"));
379 const pkg = metadata.packages.find((p) => p.name === "codewhale-app-server");
380 if (!pkg) {
381 process.exit(2);
382 }
383 const bins = pkg.targets
384 .filter((target) => target.kind.includes("bin"))
385 .map((target) => target.name);
386 process.stdout.write(bins.join("\n"));
387 '
388 )"
389 if [[ -n "${app_server_bins}" ]]; then
390 echo "::error::codewhale-app-server must stay library-only; use the codewhale-cli-owned 'codewhale app-server' entrypoint instead. Unexpected binary target(s):" >&2
391 echo "${app_server_bins}" >&2
392 fail=1
393 fi
394
395 # 13) Cargo.lock in sync.
396 if ! cargo metadata --locked --format-version 1 --no-deps >/dev/null 2>&1; then
397 echo "::error::Cargo.lock is out of sync with the manifests. Run 'cargo update -p codewhale-tui' or 'cargo build' and commit the result." >&2
398 fail=1
399 fi
400
401 # 14) Version-stamped contract fixtures match the workspace version. The
402 # 0.10.2 bump left providers-export.golden.json and the config-policy status
403 # baseline stamped 0.10.1; the test job caught both in CI while this gate said
404 # OK, at the cost of a full CI round. Two reads and a compare instead.
405 golden_fixture="crates/config/src/route/providers-export.golden.json"
406 if [[ -f "${golden_fixture}" ]]; then
407 golden_version="$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1])).get("runtimeVersion",""))' "${golden_fixture}" 2>/dev/null || true)"
408 if [[ "${golden_version}" != "${workspace_version}" ]]; then
409 echo "::error::${golden_fixture} is stamped '${golden_version:-<missing>}', want '${workspace_version}'. Regenerate with: WRITE_GOLDEN=1 cargo test -p codewhale-config --lib -- --ignored write_golden_providers_export_when_requested" >&2
410 fail=1
411 fi
412 else
413 echo "::error::${golden_fixture} is missing, so its version stamp cannot be checked against '${workspace_version}'." >&2
414 fail=1
415 fi
416 status_fixture="crates/tui/src/commands/contract/fixtures/config_policy/status.json"
417 if [[ -f "${status_fixture}" ]]; then
418 status_fixture_line="$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))["message"].splitlines()[0])' "${status_fixture}" 2>/dev/null || true)"
419 if [[ "${status_fixture_line}" != "codewhale ${workspace_version}" ]]; then
420 echo "::error::${status_fixture} first line is '${status_fixture_line:-<missing>}', want 'codewhale ${workspace_version}'." >&2
421 fail=1
422 fi
423 else
424 echo "::error::${status_fixture} is missing, so its version stamp cannot be checked against '${workspace_version}'." >&2
425 fail=1
426 fi
427
428 if [[ "${fail}" -eq 0 ]]; then
429 echo "Version state OK: workspace=${workspace_version}, npm=${npm_version}, npm-binary=${npm_binary_version}, lockfile in sync."
430 fi
431
432 exit "${fail}"
433
433 lines BASH