Add CI guard for validator file size limit (768 lines)#21077
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds automated visibility/enforcement for the 300-line hard limit on Go validator files (*_validation.go) documented in AGENTS.md, via a new make target and a non-blocking CI job.
Changes:
- Added
scripts/check-validator-sizes.shto scanpkg/**/_validation.gofiles (excluding tests) and fail when any exceed 300 lines (or report-only withWARN_ONLY=1). - Added
make check-validator-sizestarget and documented it inmake help. - Wired a new non-blocking
check-validator-sizesjob into CI with a formatted step summary.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| scripts/check-validator-sizes.sh | New validator line-count checker with hard limit + warn-only mode. |
| Makefile | New check-validator-sizes target and help text entry. |
| .github/workflows/ci.yml | New CI job to run the checker and publish output to the step summary (non-blocking). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
scripts/check-validator-sizes.sh
Outdated
| line_count=$(wc -l < "$file") | ||
| # Note: wc -l counts newlines, so files without a trailing newline are | ||
| # counted as one line fewer. Go source files almost always have a trailing | ||
| # newline, so this off-by-one is acceptable for this advisory check. |
scripts/check-validator-sizes.sh
Outdated
| # Colors for output | ||
| RED='\033[0;31m' | ||
| YELLOW='\033[1;33m' | ||
| GREEN='\033[0;32m' | ||
| NC='\033[0m' # No Color |
.github/workflows/ci.yml
Outdated
| echo "exit_code=$EXIT_CODE" >> $GITHUB_OUTPUT | ||
| echo "## Validator File Size Check" >> $GITHUB_STEP_SUMMARY | ||
| echo "" >> $GITHUB_STEP_SUMMARY | ||
| echo "Checking \`*_validation.go\` files against the 300-line hard limit (AGENTS.md)." >> $GITHUB_STEP_SUMMARY | ||
| echo "" >> $GITHUB_STEP_SUMMARY | ||
| echo "\`\`\`" >> $GITHUB_STEP_SUMMARY | ||
| echo "$OUTPUT" >> $GITHUB_STEP_SUMMARY |
.github/workflows/ci.yml
Outdated
| echo "exit_code=$EXIT_CODE" >> $GITHUB_OUTPUT | ||
| echo "## Validator File Size Check" >> $GITHUB_STEP_SUMMARY | ||
| echo "" >> $GITHUB_STEP_SUMMARY | ||
| echo "Checking \`*_validation.go\` files against the 300-line hard limit (AGENTS.md)." >> $GITHUB_STEP_SUMMARY | ||
| echo "" >> $GITHUB_STEP_SUMMARY | ||
| echo "\`\`\`" >> $GITHUB_STEP_SUMMARY | ||
| echo "$OUTPUT" >> $GITHUB_STEP_SUMMARY | ||
| echo "\`\`\`" >> $GITHUB_STEP_SUMMARY | ||
| if [ $EXIT_CODE -ne 0 ]; then | ||
| echo "" >> $GITHUB_STEP_SUMMARY | ||
| echo "⚠️ This check is currently non-blocking. Fix violations to keep the codebase healthy." >> $GITHUB_STEP_SUMMARY | ||
| fi | ||
| exit $EXIT_CODE |
|
@copilot set limit at 512 |
…ting Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Done in 73b34bc — limit raised to 512. Also took the opportunity to fix the ANSI color/CI summary issues raised in the review: colors are now suppressed when not connected to a TTY or when |
|
@copilot raise limit to 768 |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Validator files have been repeatedly growing past the hard limit documented in AGENTS.md with no automated enforcement. This adds a
make check-validator-sizestarget and wires it into CI as a non-blocking job so regressions are visible immediately.Changes
scripts/check-validator-sizes.sh— scans all*_validation.gofiles (excluding tests) and reports any exceeding 768 lines; exits 1 on violations, or 0 whenWARN_ONLY=1; honorsNO_COLOR,TERM=dumb, and non-TTY environments to emit plain text (no ANSI escape codes)Makefile— newcheck-validator-sizestarget + help text.github/workflows/ci.yml— newcheck-validator-sizesjob withcontinue-on-error: true(non-blocking); invokes the script withNO_COLOR=1so the step summary output is readable plain text; shell variables are properly quotedCurrent state
All existing validator files are within the 768-line limit. The CI job is intentionally non-blocking; once the team is confident no regressions exist,
continue-on-errorcan be removed to make it blocking.📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.