ci: add PR gate workflow, structure/rules checker, and algorithm tests - #29
Merged
Merged
Conversation
Adds a GitHub Actions workflow that runs on every pull request against main, so a review starts from a green or red signal instead of a manual read-through. .github/check_pr.py is the gate. It diffs the PR against the base branch and enforces the parts of CONTRIBUTING.md that can be checked mechanically: - structure: no new top-level entries, no moves, renames or deletions, no subdirectories or stray extensions inside scripts/, notebooks/, docs/ and tests/ - third-party imports must be declared in requirements.txt - scripts that move or delete files must offer --dry-run - notebooks must not carry saved output containing local paths Missing tests and oversized notebook output are warnings, not errors, so the existing files that break those two rules do not block contributors today. `--selftest` covers the helpers. tests/test_algorithms.py adds 12 unittest cases for the pure functions in the search and sort scripts. They are loaded by path because 01.TwoSum.py is not an importable module name. The remaining scripts call input() or sleep at import time and need a refactor before they can be tested. Also strips the NUL bytes from the qrcode[pil] line in requirements.txt, which was appended as UTF-16 into a UTF-8 file and made the whole file unreadable to pip. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
What this adds
A GitHub Actions workflow that runs on every PR against
main, so review starts from a green or red signal instead of a manual read-through..github/workflows/pr-check.yml— three steps: the gate,compileall scripts, thenunittest discover tests..github/check_pr.py— diffs the PR against its base branch and enforces the parts ofCONTRIBUTING.mdthat can be checked mechanically.Hard failures:
scripts/,notebooks/,docs/,tests/requirements.txt(with an alias map forcv2,PIL,bs4,yaml,sklearn,dotenv)--dry-runflag/Users/...Warnings only (non-blocking):
assertand no test naming itThe two warning rules are deliberately not errors: four scripts already on
mainbreak them, and blocking beginners on pre-existing debt is the wrong trade. Flip them to errors once that backlog is clear.Run it locally the same way CI does:
python .github/check_pr.py --base main python .github/check_pr.py --selftest # covers the parsing helperstests/test_algorithms.py— 12unittestcases for the pure functions in the search and sort scripts:binarySearch(found / missing / empty),linearSearch(found / first match / missing),mergeSort(in place, duplicates and negatives, 0–2 elements),twoSum(pair indices, unsorted input, no pair). They load scripts by path because01.TwoSum.pyisn't a valid module name, and suppress stdout because two of the scripts print at import.check.py,toh.py,multithreading.pyandqr_code_generator.pyare untested here — the first three callinput()or sleep at import time, so they need refactoring into functions first. Separate PR.Drive-by fix
requirements.txtwas corrupted onmain: theqrcode[pil]line had been appended as UTF-16LE into a UTF-8 file, putting a NUL byte after every character.pip install -r requirements.txtfails on it, and the gate can't read the file either. Stripped the NULs; the line now reads normally.Verification
The gate was also dry-run against every existing file in
scripts/andtests/: 0 errors, 4 warnings (the untested scripts named above).🤖 Generated with Claude Code