Skip to content

ci: auto-repair invalid JSON in PRs and on direct pushes to main - #247

Open
Core447 wants to merge 4 commits into
mainfrom
ci/json-autofix-guard
Open

ci: auto-repair invalid JSON in PRs and on direct pushes to main#247
Core447 wants to merge 4 commits into
mainfrom
ci/json-autofix-guard

Conversation

@Core447

@Core447 Core447 commented Aug 6, 2026

Copy link
Copy Markdown
Member

Summary

  • Replaces the syntax-only limitusus/json-syntax-check check with a homegrown scripts/validate_json.py.
  • On a PR from a branch in this repo, invalid JSON is auto-repaired (trailing commas, minor syntax slips) via json_repair and pushed back to the PR as a fix commit. If it can't be safely repaired, the check fails — this can then be set as a required status check so bad JSON can't be merged.
  • On a PR from a fork, we can't push to it, so it just checks and reports (GitHub Actions can't write to fork branches).
  • On a direct push to main, it tries the same repair, and if that isn't safe (e.g. it would drop most entries), it restores the file to the last version in git history that parsed as valid JSON — so main is never left pointing at broken JSON that the app would choke on.

Follow-up (not done in this PR)

To actually block merges on this check, JSON check / check needs to be added as a required status check on main in branch protection (currently branch protection has no required checks at all). Happy to do that once this is merged and the check has run — just say the word.

Note

While testing this I noticed GitHub Actions doesn't appear to be executing new/re-run jobs on this repo right now (queued runs aren't picking up a runner) — likely an org-level Actions capacity/spend issue, unrelated to this PR. Logic was verified locally instead (see commit history / description below).

Test plan

  • Locally verified scripts/validate_json.py repairs a trailing-comma break in Icons.json and leaves it valid.
  • Locally verified it fails safely (won't repair) on severely truncated JSON, and correctly restores from git history with --restore-fallback.
  • Once Actions capacity is back, confirm the workflow succeeds end-to-end in CI on this PR.

Core447 and others added 4 commits August 6, 2026 20:20
The JSON check previously only reported syntax errors; it didn't block
merges and couldn't fix anything. This adds:

- scripts/validate_json.py: validates the top-level *.json files, with
  a --fix mode that repairs minor syntax issues (trailing commas, etc.)
  via json_repair, and a --restore-fallback mode that reverts a file to
  its last known-good version from git history if a repair isn't safe
  (e.g. it would drop most of the entries).
- On pull_request (same-repo branches): auto-repairs and pushes the fix
  back to the PR branch; still fails the check if something can't be
  fixed, so it can be made a required status check to block merging.
- On push to main (direct commits): auto-repairs, falling back to
  restoring the last known-good version, so main is never left pointing
  at broken JSON that the app would choke on.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant