@@ -319,15 +319,16 @@ jobs:
319319 if : github.event.action != 'edited'
320320 name : Check CLI schema is up to date
321321 permissions :
322- contents : read
323- pull-requests : write
322+ contents : write
324323 runs-on : ubuntu-latest
325324 env :
326325 NODE_OPTIONS : --max-old-space-size=6144
327326 steps :
328327 - uses : actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
329328 with :
330- persist-credentials : false
329+ # PR head, not the merge ref, so a schema commit can fast-forward the branch.
330+ ref : ${{ github.event.pull_request.head.sha || github.sha }}
331+ persist-credentials : ${{ github.event.pull_request.head.repo.full_name == github.repository }}
331332 - uses : actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6
332333 with :
333334 node-version : 24.x
@@ -337,21 +338,25 @@ jobs:
337338 run : npm run build
338339 - name : Regenerate CLI schema
339340 run : npm run build:schema
340- - name : Check for uncommitted changes
341- run : |
342- if ! git diff --exit-code docs/cli/schema.json; then
343- echo ""
344- echo "docs/cli/schema.json is out of date. Run 'npm run build:schema' and commit the result."
345- exit 1
346- fi
347- - name : Comment on PR
348- if : failure() && github.event_name == 'pull_request'
341+ - name : Commit schema or fail
349342 env :
350- GH_TOKEN : ${{ github.token }}
351- PR_NUMBER : ${{ github.event.pull_request.number }}
343+ BRANCH : ${{ github.head_ref }}
344+ SHA : ${{ github.event.pull_request.head.sha }}
345+ SAME_REPO : ${{ github.event.pull_request.head.repo.full_name == github.repository }}
352346 run : |
353- gh pr comment "$PR_NUMBER" --body "<!-- schema-stale -->
354- \`docs/cli/schema.json\` is out of date. Comment \`/fix-schema\` on this PR and the bot will regenerate and commit it automatically."
347+ if git diff --quiet docs/cli/schema.json; then
348+ exit 0
349+ fi
350+ if [ "$SAME_REPO" = "true" ]; then
351+ git config user.name "github-actions[bot]"
352+ git config user.email "github-actions[bot]@users.noreply.github.com"
353+ git add docs/cli/schema.json
354+ git commit -m "chore: regenerate CLI schema"
355+ git push origin "HEAD:refs/heads/$BRANCH" --force-with-lease="refs/heads/$BRANCH:$SHA"
356+ exit 0
357+ fi
358+ echo "docs/cli/schema.json is out of date. Run 'npm run build:schema' and commit the result."
359+ exit 1
355360
356361 ci :
357362 name : CI Result
0 commit comments