-
-
Notifications
You must be signed in to change notification settings - Fork 637
72 lines (61 loc) · 2.27 KB
/
Copy pathsnapshot-version-check.yaml
File metadata and controls
72 lines (61 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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}."