Skip to content

feat(core): add runtimeValidation both strategy for Zod-backed clients #763

feat(core): add runtimeValidation both strategy for Zod-backed clients

feat(core): add runtimeValidation both strategy for Zod-backed clients #763

name: Snapshot version check
on:
pull_request:
branches:
- master
paths:
- '**/__snapshots__/**'
permissions:
contents: read
pull-requests: read
jobs:
check-snapshot-versions:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Get version from master branch
id: base-version
run: |
git fetch origin master
VERSION=$(git show "origin/master:package.json" | jq -r '.version')
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Master branch version: $VERSION"
- name: Check snapshot file headers
env:
EXPECTED_VERSION: ${{ steps.base-version.outputs.version }}
run: |
CHANGED_SNAPSHOTS=$(git diff --name-only --diff-filter=ACMR "origin/master...HEAD" -- '**/__snapshots__/**')
if [ -z "$CHANGED_SNAPSHOTS" ]; then
echo "No snapshot files changed in this PR."
exit 0
fi
echo "Checking snapshot files for version v${EXPECTED_VERSION}..."
echo "Changed snapshot files:"
echo "$CHANGED_SNAPSHOTS"
echo ""
FAILED=0
while IFS= read -r file; do
if [ ! -f "$file" ]; then
continue
fi
HEADER=$(head -n 6 "$file")
if echo "$HEADER" | grep -q "Generated by orval"; then
if ! echo "$HEADER" | grep -qF "Generated by orval v${EXPECTED_VERSION} "; then
ACTUAL=$(echo "$HEADER" | grep -oP 'Generated by orval v\K[0-9.]+' || echo "unknown")
echo "::error file=${file}::Version mismatch: expected v${EXPECTED_VERSION}, found v${ACTUAL}"
FAILED=1
else
echo "✓ ${file}"
fi
fi
done <<< "$CHANGED_SNAPSHOTS"
if [ "$FAILED" -eq 1 ]; then
echo ""
echo "::error::Snapshot version mismatch. Snapshots must be generated with orval v${EXPECTED_VERSION} (the version on master)."
echo "Run 'vp run -w test:snapshots:update' after updating the orval version to regenerate snapshots."
exit 1
fi
echo ""
echo "All snapshot versions match v${EXPECTED_VERSION}."