55#
66# Jobs:
77# 1. validate: Runs the full generation pipeline in dry-run mode
8- # 2. zero-diff: Compares the dry-run artifacts against the committed code to detect drift .
8+ # 2. zero-diff: Checks for drift using the validate job's outputs (in-place git status) .
99# If drift is detected, the check fails and posts a comment telling the author to run /generate.
1010#
1111# This workflow calls the main generation workflow with dry_run=true to ensure
2525permissions :
2626 contents : write
2727 pull-requests : write
28- actions : read
2928
3029jobs :
3130 check-paths :
@@ -64,87 +63,27 @@ jobs:
6463 contents : read
6564 pull-requests : write
6665 steps :
67- - name : Checkout PR branch
68- uses : actions/checkout@v4
69-
70- - name : Download generated SDK artifact
71- uses : actions/download-artifact@v8
72- with :
73- name : generated_sdk_code
74- path : /tmp/generated/
75-
76- - name : Compare generated code against committed code
77- id : diff-check
66+ - name : Check for generation drift
67+ id : drift-check
7868 run : |
79- DIFF_SUMMARY=""
80-
81- echo "=== Comparing generated SDK code ==="
82- # Compare src/ directory
83- if [ -d "src/" ] && [ -d "/tmp/generated/src/" ]; then
84- while IFS= read -r line; do
85- # Extract relative path from diff output
86- FILE=$(echo "$line" | sed 's|^Files ||; s| and /tmp/generated/.*||')
87- ADDED=$(diff -u "$FILE" "/tmp/generated/$FILE" 2>/dev/null | tail -n +3 | grep -c '^+' || echo "0")
88- REMOVED=$(diff -u "$FILE" "/tmp/generated/$FILE" 2>/dev/null | tail -n +3 | grep -c '^-' || echo "0")
89- DIFF_SUMMARY="${DIFF_SUMMARY}${FILE} (+${ADDED}/-${REMOVED})"$'\n'
90- done < <(diff -rq src/ /tmp/generated/src/ 2>&1 | grep "^Files" || true)
91-
92- # Check for files only in one side
93- ONLY_LINES=$(diff -rq src/ /tmp/generated/src/ 2>&1 | grep "^Only" || true)
94- if [ -n "$ONLY_LINES" ]; then
95- while IFS= read -r line; do
96- DIR=$(echo "$line" | sed 's|^Only in /tmp/generated/||; s|^Only in ||; s|: |/|')
97- if echo "$line" | grep -q "^Only in /tmp/generated/"; then
98- DIFF_SUMMARY="${DIFF_SUMMARY}${DIR} (new file)"$'\n'
99- else
100- DIFF_SUMMARY="${DIFF_SUMMARY}${DIR} (deleted)"$'\n'
101- fi
102- done <<< "$ONLY_LINES"
103- fi
104- elif [ -d "/tmp/generated/src/" ]; then
105- DIFF_SUMMARY="src/ directory missing in committed code but present in generated output"$'\n'
106- fi
107-
108- # Compare pyproject.toml
109- if [ -f "/tmp/generated/pyproject.toml" ]; then
110- TOML_DIFF=$(diff -q pyproject.toml /tmp/generated/pyproject.toml 2>&1 || true)
111- if [ -n "$TOML_DIFF" ]; then
112- ADDED=$(diff -u pyproject.toml /tmp/generated/pyproject.toml 2>/dev/null | tail -n +3 | grep -c '^+' || echo "0")
113- REMOVED=$(diff -u pyproject.toml /tmp/generated/pyproject.toml 2>/dev/null | tail -n +3 | grep -c '^-' || echo "0")
114- DIFF_SUMMARY="${DIFF_SUMMARY}pyproject.toml (+${ADDED}/-${REMOVED})"$'\n'
115- fi
116- fi
117-
118- if [ -n "$DIFF_SUMMARY" ]; then
69+ if [ "${{ needs.validate.outputs.has_changes }}" = "true" ]; then
11970 echo "has_diff=true" >> $GITHUB_OUTPUT
12071 echo "::warning::Generated code drift detected. The committed code does not match what the generation pipeline produces."
121- echo "$DIFF_SUMMARY"
122- echo "$DIFF_SUMMARY" > /tmp/diff_summary.txt
12372 else
12473 echo "has_diff=false" >> $GITHUB_OUTPUT
12574 echo "Zero-diff check passed. Committed code matches generation output."
12675 fi
12776
128- - name : Prepare diff summary
129- if : steps.diff-check.outputs.has_diff == 'true'
130- id : diff-summary
131- run : |
132- SUMMARY=$(cat /tmp/diff_summary.txt 2>/dev/null || echo "(see job logs for full details)")
133- EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
134- echo "content<<$EOF" >> $GITHUB_OUTPUT
135- echo "$SUMMARY" >> $GITHUB_OUTPUT
136- echo "$EOF" >> $GITHUB_OUTPUT
137-
13877 - name : Find existing drift comment
139- if : steps.diff -check.outputs.has_diff == 'true'
78+ if : steps.drift -check.outputs.has_diff == 'true'
14079 uses : peter-evans/find-comment@v3
14180 id : find-drift-comment
14281 with :
14382 issue-number : ${{ github.event.pull_request.number }}
14483 body-includes : ' <!-- zero-diff-check -->'
14584
14685 - name : Post drift comment on PR
147- if : steps.diff -check.outputs.has_diff == 'true'
86+ if : steps.drift -check.outputs.has_diff == 'true'
14887 uses : peter-evans/create-or-update-comment@v5
14988 with :
15089 issue-number : ${{ github.event.pull_request.number }}
@@ -159,11 +98,11 @@ jobs:
15998 **To fix:** Comment `/generate` on this PR to regenerate.
16099
161100 ```
162- ${{ steps.diff-summary .outputs.content }}
101+ ${{ needs.validate .outputs.drift_summary }}
163102 ```
164103
165104 - name : Fail if drift detected
166- if : steps.diff -check.outputs.has_diff == 'true'
105+ if : steps.drift -check.outputs.has_diff == 'true'
167106 run : |
168107 echo "::error::Generated code drift detected. Run /generate on this PR to fix."
169108 exit 1
0 commit comments