Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
181 changes: 51 additions & 130 deletions .github/workflows/ci-freshness.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
name: Artifact freshness

# Nightly check that each committed native artifact's provenance still
# describes the tree. Each lane's sidecar records sourceRevision and
# recipeRevision, each computed by the producer as `git log -1 --format=%H`
# over a path set that excludes the artifact output directories — so a
# refresh writeback can never report itself stale. This job recomputes both
# at HEAD over the same sets and compares by equality:
# missing / "unknown" field → ::warning::, the lane is unverified, run green
# unequal → ::error:: + summary, the run fails
# headSha / appliedAtHead / producerCheckout are run identity and are never
# compared. No issue is opened: contents: read is the whole permission set,
# so the red run and the step summary are the only alert channel.
# Nightly check that each committed native artifact's recorded build inputs
# still describe the tree. Each lane compares the revisions recorded in its
# committed provenance sidecar — sourceRevision and recipeRevision per
# carrier — to HEAD over that carrier's compiled-source and recipe path sets.
# An unrelated commit, a test-only change or another platform's refresh never
# reports the lane stale; a real build-input change after a recorded revision
# does.
# recorded revision stale → ::error:: + summary, red
# missing/malformed/unresolvable record → ::error:: + summary, red
# check could not run (checker exit 2) → ::error::, red
# No issue is opened: contents: read is the whole permission set, so the red
# run and the step summary are the only alert channel.
on:
schedule:
- cron: '17 3 * * *'
Expand All @@ -31,133 +32,53 @@ jobs:
# Full history: the recorded revisions must resolve in this clone.
fetch-depth: 0
Comment thread
auto-wood marked this conversation as resolved.
Resolved

- name: Setup Node.js
# actions/setup-node@v4.4.0 — Node 24
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020
with:
node-version: 24

- name: Compare provenance baselines
run: |
set -u
stale=0

# git pathspec exclusions for the artifact writeback directories and
# every provenance sidecar: a refresh commit moves neither baseline.
EXCLUDES=(
':(exclude)crates/spoke-connect/bindings/swift/xcframework/**'
':(exclude)crates/spoke-connect/bindings/swift/generated/**'
':(exclude)crates/spoke-connect/bindings/cpp/native/**'
':(exclude)**/provenance.json'
)
set -uo pipefail

last_revision() {
git log -1 --format=%H -- "$@" "${EXCLUDES[@]}"
}
echo "## Artifact freshness" >> "$GITHUB_STEP_SUMMARY"

# compare <lane> <field> <recorded> <current> <pathspec...>
compare() {
local lane="$1" field="$2" recorded="$3" current="$4"
shift 4
if [ -z "$recorded" ] || [ "$recorded" = "null" ] || [ "$recorded" = "unknown" ]; then
echo "::warning::${lane}: ${field} not recorded in committed provenance; freshness unverified"
echo "- :warning: **${lane}** \`${field}\` is not recorded; the lane's freshness is unverified until the next refresh writes it." >> "$GITHUB_STEP_SUMMARY"
return 0
fi
if [ -z "$current" ]; then
echo "::warning::${lane}: no HEAD history resolves ${field}; baseline cannot be recomputed"
echo "- :warning: **${lane}** \`${field}\` has no history at HEAD; the baseline cannot be recomputed." >> "$GITHUB_STEP_SUMMARY"
return 0
fi
if [ "$recorded" != "$current" ]; then
local first
first=$(git rev-list --reverse "${recorded}..HEAD" -- "$@" "${EXCLUDES[@]}" 2>/dev/null | head -1 || true)
echo "::error::${lane}: ${field} stale: recorded ${recorded}, HEAD ${current}"
{
echo "- :x: **${lane}** \`${field}\` stale"
echo " - recorded: \`${recorded}\`"
echo " - HEAD: \`${current}\`"
[ -n "$first" ] && echo " - first offending commit: \`${first}\`"
} >> "$GITHUB_STEP_SUMMARY"
return 1
fi
echo "- :white_check_mark: **${lane}** \`${field}\` fresh at \`${current}\`" >> "$GITHUB_STEP_SUMMARY"
return 0
}
report="$(mktemp)"
status=0
node tooling/release/check-artifact-freshness.mjs --repo . > "$report" || status=$?
Comment thread
auto-wood marked this conversation as resolved.
Resolved

echo "## Artifact freshness" >> "$GITHUB_STEP_SUMMARY"
failed=0
if [ "$status" -ne 0 ] && [ "$status" -ne 1 ]; then failed=1; fi
if ! jq -e '.lanes' "$report" > /dev/null 2>&1; then failed=1; fi

# --- C++ carrier (crates/spoke-connect/bindings/cpp/native) ---
# Path sets mirror cpp-build.mjs: BUILD_SOURCE_PATHS and
# BUILD_RECIPE_PATHS.
CPP_SOURCE=(
Cargo.toml Cargo.lock
crates/spoke-connect-capi crates/spoke-connect/src crates/spoke-connect/Cargo.toml
crates/spoke-operations crates/spoke-schemas
)
CPP_RECIPE=(
tooling/connect/cpp-build.mjs
.github/workflows/cpp-connect.yml
)
CPP_PROVENANCE=crates/spoke-connect/bindings/cpp/native/provenance.json
cpp_src_rev=$(last_revision "${CPP_SOURCE[@]}")
cpp_rec_rev=$(last_revision "${CPP_RECIPE[@]}")
# Missing, malformed, empty or non-object sidecar is a broken
# record, not an unknown baseline: fail the lane rather than
# warning green. `jq -e` also catches the zero-byte file that a
# bare parse accepts.
if [ ! -f "$CPP_PROVENANCE" ]; then
echo "::error::cpp-carrier: $CPP_PROVENANCE is missing"
echo "- :x: **cpp-carrier** committed provenance is missing." >> "$GITHUB_STEP_SUMMARY"
stale=1
elif ! jq -e 'type == "object"' "$CPP_PROVENANCE" > /dev/null; then
echo "::error::cpp-carrier: $CPP_PROVENANCE is not a JSON object"
echo "- :x: **cpp-carrier** committed provenance is not a JSON object." >> "$GITHUB_STEP_SUMMARY"
stale=1
elif [ "$(jq -r '.nativeArtifacts | type' "$CPP_PROVENANCE")" != "object" ]; then
echo "::error::cpp-carrier: $CPP_PROVENANCE has no nativeArtifacts object"
echo "- :x: **cpp-carrier** committed provenance has no \`nativeArtifacts\` object." >> "$GITHUB_STEP_SUMMARY"
stale=1
elif cpp_rows=$(jq -r '.nativeArtifacts | keys[]' "$CPP_PROVENANCE"); [ -z "$cpp_rows" ]; then
echo "::warning::cpp-carrier: committed provenance has no nativeArtifacts entries"
echo "- :warning: **cpp-carrier** committed provenance records no carriers." >> "$GITHUB_STEP_SUMMARY"
else
while IFS= read -r rid; do
[ -z "$rid" ] && continue
rec_src=$(jq -r --arg rid "$rid" '.nativeArtifacts[$rid].sourceRevision // empty' "$CPP_PROVENANCE")
rec_rec=$(jq -r --arg rid "$rid" '.nativeArtifacts[$rid].recipeRevision // empty' "$CPP_PROVENANCE")
compare "cpp-carrier/${rid}" sourceRevision "$rec_src" "$cpp_src_rev" "${CPP_SOURCE[@]}" || stale=1
compare "cpp-carrier/${rid}" recipeRevision "$rec_rec" "$cpp_rec_rev" "${CPP_RECIPE[@]}" || stale=1
done <<< "$cpp_rows"
if [ "$failed" -eq 1 ]; then
# The checker prints its own error JSON; a crash may leave raw text.
detail="$(jq -r '.error // empty' "$report" 2>/dev/null || true)"
if [ -z "$detail" ]; then
detail="$(head -c 500 "$report" 2>/dev/null | tr '\n' ' ' || true)"
fi
echo "::error::artifact freshness check failed to run: ${detail}"
echo "- :x: **artifact freshness** check failed to run: ${detail}" >> "$GITHUB_STEP_SUMMARY"
exit 1
fi

# --- Swift xcframework (crates/spoke-connect/bindings/swift/xcframework) ---
# Source set = the xcframework rebuild pattern minus the four recipe
# files; recipe set = the files that define how the bundle is built.
XC_PROVENANCE=crates/spoke-connect/bindings/swift/xcframework/provenance.json
XC_SOURCE=(
Cargo.toml Cargo.lock .cargo rust-toolchain rust-toolchain.toml
crates/spoke-connect crates/spoke-schemas crates/spoke-operations
)
XC_RECIPE=(
tooling/connect/build-swift-xcframework.sh
tooling/connect/xcframework-manifest.sh
tooling/connect/normalize-cargo-version.mjs
tooling/release/lockstep-surfaces.mjs
.github/workflows/xcframework.yml
)
xc_src_rev=$(last_revision "${XC_SOURCE[@]}")
xc_rec_rev=$(last_revision "${XC_RECIPE[@]}")
if [ ! -f "$XC_PROVENANCE" ]; then
echo "::error::swift-xcframework: $XC_PROVENANCE is missing"
echo "- :x: **swift-xcframework** committed provenance is missing." >> "$GITHUB_STEP_SUMMARY"
stale=1
elif ! jq -e 'type == "object"' "$XC_PROVENANCE" > /dev/null; then
echo "::error::swift-xcframework: $XC_PROVENANCE is not a JSON object"
echo "- :x: **swift-xcframework** committed provenance is not a JSON object." >> "$GITHUB_STEP_SUMMARY"
stale=1
else
xc_rec_src=$(jq -r '.xcframework.sourceRevision // empty' "$XC_PROVENANCE")
xc_rec_rec=$(jq -r '.xcframework.recipeRevision // empty' "$XC_PROVENANCE")
compare "swift-xcframework" sourceRevision "$xc_rec_src" "$xc_src_rev" "${XC_SOURCE[@]}" || stale=1
compare "swift-xcframework" recipeRevision "$xc_rec_rec" "$xc_rec_rev" "${XC_RECIPE[@]}" || stale=1
fi
jq -r '.lanes[] as $lane
| if $lane.status == "fresh" then
"- :white_check_mark: **\($lane.lane)** fresh"
elif $lane.status == "stale" then
"- :x: **\($lane.lane)** stale\n" +
($lane.stale | map(" - base `\(.base)` (`\(.label)`) changed by `\(.commit)`") | join("\n"))
else
"- :x: **\($lane.lane)** invalid provenance\n" +
($lane.errors | map(" - \(.)") | join("\n"))
end' "$report" >> "$GITHUB_STEP_SUMMARY"

jq -r '.lanes[] as $lane
| ($lane.errors[] | "::error::\($lane.lane): invalid provenance: \(.)"),
($lane.stale[] | "::error::\($lane.lane): build inputs changed since \(.base) (\(.label)) (commit \(.commit))")' "$report"

if [ "$stale" -ne 0 ]; then
echo "::error::stale committed artifact baselines; refresh via the lane's apply tooling"
if [ "$status" -eq 1 ]; then
echo "::error::artifact freshness check reported stale or invalid provenance"
exit 1
fi
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"test:operations": "pnpm -F @42ch/spoke-operations test",
"test:connect-ts": "pnpm -F @42ch/spoke-connect test",
"test:demo": "pnpm -F @42ch/spoke-demo-server test && pnpm -F @42ch/spoke-demo-client test",
"test:release": "node --test tooling/release/assert-lockstep-version.test.mjs tooling/release/assert-breaking-section.test.mjs tooling/release/bump-version.test.mjs tooling/release/check-pypi-published.test.mjs tooling/release/check-maven-published.test.mjs tooling/connect/cpp-build.test.mjs tooling/connect/apply-xcframework-artifact.test.mjs tooling/connect/cpp-symbol-check.test.mjs",
"test:release": "node --test tooling/release/assert-lockstep-version.test.mjs tooling/release/assert-breaking-section.test.mjs tooling/release/bump-version.test.mjs tooling/release/check-pypi-published.test.mjs tooling/release/check-maven-published.test.mjs tooling/release/check-artifact-freshness.test.mjs tooling/connect/cpp-build.test.mjs tooling/connect/apply-xcframework-artifact.test.mjs tooling/connect/cpp-symbol-check.test.mjs",
"ci:typescript": "pnpm -F @42ch/spoke-schemas typecheck && pnpm run build:schema && pnpm -F @42ch/spoke-operations typecheck && pnpm run test && pnpm run build:operations && pnpm run test:release && pnpm run test:fixtures && pnpm -F @42ch/spoke-connect typecheck && pnpm run test:connect-ts && pnpm -F @42ch/spoke-connect build && pnpm -F @42ch/spoke-connect test:dist && pnpm -F @42ch/spoke-demo-server typecheck && pnpm -F @42ch/spoke-demo-client typecheck && pnpm run test:demo",
"docs:dev": "pnpm run docs:diagrams && pnpm run docs:llms && vitepress dev docs",
"docs:build": "pnpm run docs:diagrams && pnpm run docs:llms && vitepress build docs",
Expand Down
Loading
Loading