Repository navigation
ci: gate file size, function complexity and import cycles #3765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
3a23bbd
76135aa
ec16ec2
d342943
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,9 @@ jobs: | |
| lint: | ||
| timeout-minutes: 8 | ||
| runs-on: ubuntu-24.04 | ||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v6 | ||
|
|
@@ -59,6 +62,7 @@ jobs: | |
| run: | ||
| node --test scripts/ci/__tests__/ratchet.test.mjs | ||
| scripts/ci/__tests__/oxlint-warnings.test.mjs | ||
| scripts/ci/__tests__/quality-report.test.mjs | ||
| # Also unconditional, and against the PR's own tree. claude-code-review.yml | ||
| # runs this file too, but from a base-branch checkout, so a PR that breaks | ||
| # what it pins (the AGENTS.md heading every review footer links to) passes | ||
|
|
@@ -69,6 +73,29 @@ jobs: | |
| .github/scripts/code-review/__tests__/review-comments.test.mjs | ||
| - name: Escape-hatch ratchet | ||
| run: node scripts/ci/ratchet.mjs | ||
| # Advisory: the gates are the ratchet above and each package's | ||
| # --max-warnings. This only makes the totals visible on the run page. | ||
| - name: Code quality report | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 P2 — Quality report runs type-aware oxlint on every package, but upstream The lint step uses Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in d342943: the report step builds common-utils first, and its timeout is 3 minutes. Left |
||
| id: quality | ||
| if: always() | ||
| continue-on-error: true | ||
| timeout-minutes: 3 | ||
| # `nx affected` above builds dist only for what the PR touches, and | ||
| # type-aware lint counts change when common-utils is unbuilt. | ||
| run: | | ||
| npx nx run @hyperdx/common-utils:ci:build | ||
| node scripts/ci/quality-report.mjs --comment "$RUNNER_TEMP/quality-comment.md" >> "$GITHUB_STEP_SUMMARY" | ||
| - name: Comment PR with code quality report | ||
| # Skip fork and Dependabot PRs: their GITHUB_TOKEN is read-only | ||
| if: | ||
| always() && steps.quality.outcome == 'success' && github.event_name == | ||
| 'pull_request' && github.event.pull_request.head.repo.fork != true && | ||
| github.actor != 'dependabot[bot]' | ||
| continue-on-error: true | ||
| uses: mshick/add-pr-comment@ec328af66588ab8f77cdeb2c264f14aba45bbf59 # v3.12.0 | ||
| with: | ||
| message-path: ${{ runner.temp }}/quality-comment.md | ||
| message-id: code-quality-report | ||
| # Also unconditional: the api's own `ci:lint` regenerates the spec but | ||
| # never asserts on it, and nx can skip or cache-replay that task. | ||
| - name: Check openapi.json is in sync with its sources | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import assert from 'node:assert/strict'; | ||
| import test from 'node:test'; | ||
|
|
||
| import { commentBody, lintSection, sizeSection } from '../quality-report.mjs'; | ||
|
|
||
| test('file size section lists the largest files first', () => { | ||
| const out = sizeSection({ 'a.ts': 400, 'b.ts': 900 }); | ||
| assert.match(out, /2 source files over 300 lines, 700 lines over/); | ||
| assert.ok(out.indexOf('b.ts') < out.indexOf('a.ts')); | ||
| }); | ||
|
|
||
| test('lint section totals each rule across packages, most common first', () => { | ||
| const out = lintSection({ | ||
| api: { limit: 5, rules: { complexity: 2, 'max-depth': 3 } }, | ||
| app: { limit: 9, rules: { complexity: 4 } }, | ||
| }); | ||
| assert.match(out, /\| `complexity` \| 2 \| 4 \| 6 \|/); | ||
| assert.match(out, /\| `max-depth` \| 3 \| 0 \| 3 \|/); | ||
| assert.ok(out.indexOf('complexity') < out.indexOf('max-depth')); | ||
| assert.match(out, /api 5\/5, app 4\/9 \(count\/limit\)/); | ||
| assert.match(out, /\| \*\*Total\*\* \| 5 \| 4 \|/); | ||
| assert.match(out, /\| \*\*Limit\*\* \| 5 \| 9 \|/); | ||
| }); | ||
|
|
||
| test('the PR comment is the totals and a link to the full report', () => { | ||
| const out = commentBody( | ||
| { 'a.ts': 400, 'b.ts': 900 }, | ||
| { api: { limit: 5, rules: { complexity: 2, 'max-depth': 3 } } }, | ||
| 'https://example.test/runs/1', | ||
| ); | ||
| assert.equal( | ||
| out, | ||
| [ | ||
| '## Code quality report', | ||
| '- 2 source files over 300 lines, 700 lines over the limit in total', | ||
| '- oxlint warnings (count/limit): api 5/5', | ||
| '', | ||
| '[Full report](https://example.test/runs/1)', | ||
| ].join('\n'), | ||
| ); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 P2 — The whole lint job now gets
pull-requests: write, though only the last comment step needs itEvery step in the job runs with a token that can write to PRs, including
yarn installlifecycle scripts, nx tasks and PR-authored scripts, and so do push runs, which never comment. Only the comment step needs that scope. Fix: droppull-requests: writefromlint, uploadquality-comment.mdas an artifact, and post it from a small follow-up job (needs: lint,if: github.event_name == 'pull_request') that alone haspull-requests: write.Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond