Files
mxaccessgw/scripts/check-codegen.ps1
T
Joseph Doherty 866d053ec2
ci / live-mxaccess (push) Waiting to run
ci / java (push) Failing after 1m57s
ci / portable (push) Failing after 3m36s
ci / windows (push) Failing after 8s
ci(tst-03): fix codegen-check null bug, refresh rust proto, gradle direct install
Surfaced by the first real CI run on the self-hosted runner:

- scripts/check-codegen.ps1: `git status --porcelain` returns $null on a clean
  tree, so `.Trim()` threw "cannot call a method on a null-valued expression" —
  i.e. Check 2 could never report success. Pipe through Out-String (null -> '').
- clients/rust/protos/mxaccess_worker.proto: genuinely stale — missing the
  canonical `max_frame_bytes` field. Refreshed from
  src/ZB.MOM.WW.MxGateway.Contracts/Protos (Check 3 drift guard, added in P1).
- ci.yml java job: act cannot resolve the gradle/actions monorepo action
  (`unsupported object type` on the v4 tag); install Gradle 9.5.1 directly instead
  (matches the local build) since the repo has no gradle wrapper.

Claude-Session: https://claude.ai/code/session_01DMXXvNuPekkkrTEyPNxEkW
2026-07-10 03:49:09 -04:00

99 lines
4.6 KiB
PowerShell

#!/usr/bin/env pwsh
# Codegen freshness guard for CI (IPC-01, IPC-19, IPC-20, CLI-02).
#
# Three checks, all Linux/macOS-runnable (no Server build, no x86 worker):
# 1. Published client descriptor set matches the current .proto sources (delegates to
# publish-client-proto-inputs.ps1 -Check, which normalizes source_code_info so it is
# protoc-version tolerant).
# 2. The committed C# under Contracts/Generated matches a fresh regeneration. Grpc.Tools is
# pinned in the contracts csproj, so a clean checkout regenerates byte-identical output; a
# non-empty git diff means a .proto was edited without regenerating and committing Generated/
# (which breaks the net48 worker build with CS0246 — see docs/Contracts.md).
# 3. The Rust crate's vendored protos (clients/rust/protos/*.proto — build inputs that make the
# crate buildable outside the repo, CLI-02) are byte-identical to the canonical Contracts
# protos. A drift means a .proto was edited without refreshing the vendored copies, which would
# publish a stale wire contract to crate consumers while the in-repo build stays correct.
#
# The x86 Worker + Worker.Tests are Windows-only and are guarded by the Windows CI job, not here.
[CmdletBinding()]
param()
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$repoRoot = Resolve-Path (Join-Path $PSScriptRoot '..')
$generatedDir = Join-Path $repoRoot 'src/ZB.MOM.WW.MxGateway.Contracts/Generated'
$contractsProject = Join-Path $repoRoot 'src/ZB.MOM.WW.MxGateway.Contracts/ZB.MOM.WW.MxGateway.Contracts.csproj'
$failures = New-Object System.Collections.Generic.List[string]
Write-Host '== Check 1/2: client descriptor set freshness =='
try {
& (Join-Path $PSScriptRoot 'publish-client-proto-inputs.ps1') -Check
if ($LASTEXITCODE -ne 0) {
$failures.Add('Client descriptor set is stale (publish-client-proto-inputs.ps1 -Check failed).')
}
}
catch {
$failures.Add("Descriptor freshness check failed: $($_.Exception.Message)")
}
Write-Host ''
Write-Host '== Check 2/2: Contracts/Generated matches a fresh regeneration =='
try {
# Force a full regeneration: Grpc.Tools skips regen when the committed .cs look up to date, so
# remove them first (the documented "del Generated/*.cs to force regen" trick).
if (Test-Path $generatedDir) {
Get-ChildItem -Path $generatedDir -Filter '*.cs' -Recurse -File | Remove-Item -Force
}
& dotnet build $contractsProject -c Release --nologo | Out-Host
if ($LASTEXITCODE -ne 0) {
$failures.Add('Contracts project failed to build during codegen check.')
}
# Pipe through Out-String so a clean tree (git emits nothing -> $null) does not throw
# "cannot call a method on a null-valued expression"; Out-String yields '' for no output.
$diff = (& git -C $repoRoot status --porcelain -- 'src/ZB.MOM.WW.MxGateway.Contracts/Generated' | Out-String).Trim()
if (-not [string]::IsNullOrEmpty($diff)) {
Write-Host $diff
$failures.Add('Contracts/Generated differs from a fresh regeneration. Run `dotnet build` on the contracts project and commit Generated/ (required for the net48 worker build).')
}
}
catch {
$failures.Add("Generated codegen check failed: $($_.Exception.Message)")
}
Write-Host ''
Write-Host '== Check 3/3: Rust vendored protos match canonical Contracts protos =='
try {
$canonicalProtoDir = Join-Path $repoRoot 'src/ZB.MOM.WW.MxGateway.Contracts/Protos'
$vendoredProtoDir = Join-Path $repoRoot 'clients/rust/protos'
foreach ($vendored in Get-ChildItem -Path $vendoredProtoDir -Filter '*.proto' -File) {
$canonical = Join-Path $canonicalProtoDir $vendored.Name
if (-not (Test-Path $canonical)) {
$failures.Add("Vendored Rust proto has no canonical counterpart: $($vendored.Name).")
continue
}
$vendoredHash = (Get-FileHash -Algorithm SHA256 $vendored.FullName).Hash
$canonicalHash = (Get-FileHash -Algorithm SHA256 $canonical).Hash
if ($vendoredHash -ne $canonicalHash) {
$failures.Add("Rust vendored proto drifted from canonical: clients/rust/protos/$($vendored.Name). Refresh it from src/ZB.MOM.WW.MxGateway.Contracts/Protos/$($vendored.Name).")
}
}
}
catch {
$failures.Add("Rust vendored proto check failed: $($_.Exception.Message)")
}
Write-Host ''
if ($failures.Count -gt 0) {
Write-Host 'Codegen freshness check FAILED:' -ForegroundColor Red
foreach ($failure in $failures) {
Write-Host " - $failure" -ForegroundColor Red
}
exit 1
}
Write-Host 'Codegen freshness check passed.' -ForegroundColor Green