|
3 | 3 | # This workflow validates that Speakeasy generation can complete successfully |
4 | 4 | # and that the committed generated code matches what the generation pipeline produces. |
5 | 5 | # |
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. |
9 | 13 | # |
10 | 14 | # Note: paths-ignore is NOT used at the workflow level because GitHub treats a |
11 | 15 | # workflow that never runs as "expected" (pending), which blocks required checks. |
|
49 | 53 | with: |
50 | 54 | dry_run: true |
51 | 55 | 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