ci: auto-repair invalid JSON in PRs and on direct pushes to main - #247
Open
Core447 wants to merge 4 commits into
Open
ci: auto-repair invalid JSON in PRs and on direct pushes to main#247Core447 wants to merge 4 commits into
Core447 wants to merge 4 commits into
Conversation
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>
…urrently, see PR)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
limitusus/json-syntax-checkcheck with a homegrownscripts/validate_json.py.json_repairand 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.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 — somainis 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 / checkneeds to be added as a required status check onmainin 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
scripts/validate_json.pyrepairs a trailing-comma break inIcons.jsonand leaves it valid.--restore-fallback.