Skip to content

Commit c281018

Browse files
refactor: expose drift as workflow outputs, restore dedicated zero-diff CI job
Co-Authored-By: AJ Steers <aj@airbyte.io>
1 parent 71e1e51 commit c281018

2 files changed

Lines changed: 76 additions & 36 deletions

File tree

.github/workflows/generate-command.yml

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ name: Generate SDK
5454
description: Validate generation without creating a PR
5555
type: boolean
5656
default: false
57+
outputs:
58+
has_changes:
59+
description: Whether the generation produced changes vs committed code
60+
value: ${{ jobs.generate.outputs.has_changes }}
61+
drift_summary:
62+
description: Git diff stat summary when drift is detected
63+
value: ${{ jobs.generate.outputs.drift_summary }}
5764

5865
concurrency:
5966
group: ${{ (github.event_name == 'push' || github.event_name == 'schedule') && 'generate-new-pr' || format('generate-{0}', github.run_id) }}
@@ -64,6 +71,9 @@ jobs:
6471
name: Generate SDK
6572
runs-on: ubuntu-latest
6673
timeout-minutes: 30
74+
outputs:
75+
has_changes: ${{ steps.changes.outputs.has_changes }}
76+
drift_summary: ${{ steps.changes.outputs.drift_summary }}
6777
permissions:
6878
contents: write
6979
pull-requests: write
@@ -191,43 +201,16 @@ jobs:
191201
git status --porcelain
192202
echo
193203
echo "=== Diff stat ==="
194-
git diff --stat
204+
SUMMARY=$(git diff --stat)
205+
echo "$SUMMARY"
206+
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
207+
echo "drift_summary<<$EOF" >> $GITHUB_OUTPUT
208+
echo "$SUMMARY" >> $GITHUB_OUTPUT
209+
echo "$EOF" >> $GITHUB_OUTPUT
195210
else
196211
echo "has_changes=false" >> $GITHUB_OUTPUT
197212
fi
198213
199-
- name: Detect generation drift (dry run)
200-
if: ${{ inputs.dry_run && steps.changes.outputs.has_changes == 'true' }}
201-
id: drift
202-
run: |
203-
echo "::error::Generated code drift detected. The committed code does not match what the generation pipeline produces."
204-
SUMMARY=$(git diff --stat)
205-
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
206-
echo "summary<<$EOF" >> $GITHUB_OUTPUT
207-
echo "$SUMMARY" >> $GITHUB_OUTPUT
208-
echo "$EOF" >> $GITHUB_OUTPUT
209-
210-
- name: Post drift comment on PR
211-
if: ${{ inputs.dry_run && steps.changes.outputs.has_changes == 'true' && github.event_name == 'pull_request' }}
212-
uses: peter-evans/create-or-update-comment@v5
213-
with:
214-
issue-number: ${{ github.event.pull_request.number }}
215-
body: |
216-
<!-- zero-diff-check -->
217-
**Generated Code Drift Detected**
218-
219-
The committed code does not match what the generation pipeline produces.
220-
221-
**To fix:** Comment `/generate` on this PR to regenerate.
222-
223-
```
224-
${{ steps.drift.outputs.summary }}
225-
```
226-
227-
- name: Fail on drift (dry run)
228-
if: ${{ inputs.dry_run && steps.changes.outputs.has_changes == 'true' }}
229-
run: exit 1
230-
231214
# --- PR branch mode: commit and push to the existing PR branch ---
232215
- name: Push regenerated code to PR branch
233216
if: ${{ !inputs.dry_run && github.event.inputs.pr != '' && steps.changes.outputs.has_changes == 'true' }}

.github/workflows/test-full.yml

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
# This workflow validates that Speakeasy generation can complete successfully
44
# and that the committed generated code matches what the generation pipeline produces.
55
#
6-
# It calls the main generation workflow with dry_run=true. After generation,
7-
# the workflow checks `git status` in-place — if any tracked files changed,
8-
# drift is detected and the check fails with a PR comment.
6+
# Jobs:
7+
# 1. validate: Runs the full generation pipeline in dry-run mode
8+
# 2. zero-diff: Checks for drift using the validate job's outputs (in-place git status).
9+
# If drift is detected, the check fails and posts a comment telling the author to run /generate.
10+
#
11+
# This workflow calls the main generation workflow with dry_run=true to ensure
12+
# both workflows use the same generation logic.
913
#
1014
# Note: paths-ignore is NOT used at the workflow level because GitHub treats a
1115
# workflow that never runs as "expected" (pending), which blocks required checks.
@@ -49,3 +53,56 @@ jobs:
4953
with:
5054
dry_run: true
5155
secrets: inherit
56+
57+
zero-diff:
58+
name: Zero-Diff Check (Generated Code)
59+
needs: [check-paths, validate]
60+
if: needs.check-paths.outputs.should_run == 'true' && github.event_name == 'pull_request'
61+
runs-on: ubuntu-latest
62+
permissions:
63+
contents: read
64+
pull-requests: write
65+
steps:
66+
- name: Check for generation drift
67+
id: drift-check
68+
run: |
69+
if [ "${{ needs.validate.outputs.has_changes }}" = "true" ]; then
70+
echo "has_diff=true" >> $GITHUB_OUTPUT
71+
echo "::warning::Generated code drift detected. The committed code does not match what the generation pipeline produces."
72+
else
73+
echo "has_diff=false" >> $GITHUB_OUTPUT
74+
echo "Zero-diff check passed. Committed code matches generation output."
75+
fi
76+
77+
- name: Find existing drift comment
78+
if: steps.drift-check.outputs.has_diff == 'true'
79+
uses: peter-evans/find-comment@v3
80+
id: find-drift-comment
81+
with:
82+
issue-number: ${{ github.event.pull_request.number }}
83+
body-includes: '<!-- zero-diff-check -->'
84+
85+
- name: Post drift comment on PR
86+
if: steps.drift-check.outputs.has_diff == 'true'
87+
uses: peter-evans/create-or-update-comment@v5
88+
with:
89+
issue-number: ${{ github.event.pull_request.number }}
90+
comment-id: ${{ steps.find-drift-comment.outputs.comment-id || '' }}
91+
edit-mode: replace
92+
body: |
93+
<!-- zero-diff-check -->
94+
**Generated Code Drift Detected**
95+
96+
The committed code does not match what the generation pipeline produces.
97+
98+
**To fix:** Comment `/generate` on this PR to regenerate.
99+
100+
```
101+
${{ needs.validate.outputs.drift_summary }}
102+
```
103+
104+
- name: Fail if drift detected
105+
if: steps.drift-check.outputs.has_diff == 'true'
106+
run: |
107+
echo "::error::Generated code drift detected. Run /generate on this PR to fix."
108+
exit 1

0 commit comments

Comments
 (0)