Skip to content

Commit 2e16c71

Browse files
committed
chore(ci): enhance CI workflows with unit tests, improved fetch depth, and new script for PR diff reporting
1 parent f85af4a commit 2e16c71

9 files changed

Lines changed: 430 additions & 219 deletions

File tree

‎.github/workflows/README.md‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,14 @@ Workflows are split by responsibility. **Node.js 24** is used in CI to match [`S
1111
| Job | Purpose |
1212
|-----|---------|
1313
| **Format and lint** | Prettier (`pnpm run format:check`) then ESLint (one setup; runs **in parallel** with **Build**). |
14-
| **Build** | Single `pnpm run build`; uploads `SortVision/.next` as artifact `next-build` (no duplicate builds downstream). |
14+
| **Build** | `pnpm run build`, **bundle size** notes (warn if build exceeds 50MB), **generate + validate** `public/sitemap.xml`; uploads `SortVision/.next` as artifact `next-build` (no duplicate builds downstream). |
1515
| **Test** | After **Build**: `pnpm install` + restore `next-build` tarball, **`next start`**, `pnpm test`, PR QA comment + `qa-pr-comment` artifact. Runs **in parallel** with **Lighthouse**. |
1616
| **Lighthouse** | After **Build**: install + download `next-build`, **`next start`**, mobile + desktop Lighthouse ([`lighthouserc.json`](../../SortVision/lighthouserc.json), [`lighthouserc.desktop.json`](../../SortVision/lighthouserc.desktop.json)); uploads `lighthouse-manifest-{mobile,desktop}` (manifest after the treosh action) for the summary job. |
1717
| **Lighthouse summary** | Merges mobile/desktop manifests, **job summary** + **PR comment** (same pattern as QA), gates Lighthouse. |
1818
| **Production validation** | On `main` / `master` only, after **Test** and **Lighthouse** (+ summary): production smoke tests and HTTP checks |
1919

2020
Shared setup: [`setup-sortvision`](../actions/setup-sortvision/action.yml) (pnpm, Node, `pnpm install`). Consumer jobs use [`restore-next-build`](../actions/restore-next-build/action.yml) after **Build** to unpack `next-build.tar.gz` into `SortVision/.next`.
2121

22-
### `extended-quality-assurance.yml`
23-
24-
**Triggers:** nightly (`0 2 * * *` UTC), `workflow_dispatch`.
25-
26-
Longer validation: format, lint, build, `pnpm run test:extended`, sitemap, **pnpm audit** (fails on high/critical for production deps), bundle notes, artifacts.
27-
2822
### `security-scan.yml`
2923

3024
**Triggers:** push/PR, **merge queue** (`merge_group`), weekly schedule.
@@ -61,8 +55,6 @@ Merge queue uses a **temporary branch** (ref like `refs/heads/gh-readonly-queue/
6155
- [`typos.yml`](typos.yml)
6256
- [`security-scan.yml`](security-scan.yml) — audit + TruffleHog run; **Dependency Review** stays `pull_request`-only by design.
6357

64-
**Not** run on merge queue: [`extended-quality-assurance.yml`](extended-quality-assurance.yml) (scheduled/manual only) — too heavy for every queue entry.
65-
6658
**How “PR tests” vs “merge queue tests” relate:** Each PR still gets normal `pull_request` runs. When you click **Merge when ready**, GitHub runs required checks again on the **merge group** commit (integration of `main` + your change, and possibly other queued PRs depending on queue mode). One green merge-group run can clear the next merge for batched queues; if something fails, the queue is blocked or that PR is dropped per GitHub’s rules.
6759

6860
**Enable in GitHub:** **Settings → Rules** (ruleset on `main`) → enable **Merge queue** → choose **Merge method** → list the **same** required status checks as for pull requests. After the first merge-group run, confirm check names match **Settings → Rules** (search for checks).
@@ -74,7 +66,6 @@ Required status check names must match each job’s `name:` field exactly (for e
7466
## Adding more checks
7567

7668
- **Default PR path:** extend [`continuous-integration.yml`](continuous-integration.yml) or add a job with `needs:` as appropriate.
77-
- **Nightly / manual only:** use [`extended-quality-assurance.yml`](extended-quality-assurance.yml) or a new workflow file.
7869
- **Security:** prefer [`security-scan.yml`](security-scan.yml); CodeQL is managed in **Settings → Code scanning** (default setup).
7970

8071
**Not configured here (optional later):** Knip/depcheck for unused exports, Playwright E2E — useful once you want the extra maintenance cost.

‎.github/workflows/continuous-integration.yml‎

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ jobs:
4545
steps:
4646
- name: Checkout repository
4747
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 (node24 runtime; fewer forced-runtime warnings)
48+
with:
49+
fetch-depth: 1
4850

4951
- name: Setup SortVision
5052
uses: ./.github/actions/setup-sortvision
@@ -57,6 +59,9 @@ jobs:
5759
- name: ESLint
5860
run: pnpm run lint
5961

62+
- name: Unit tests (node:test)
63+
run: pnpm run test:unit
64+
6065
# Runs in parallel with format-lint so wall time is max(static, build), not sum (update branch rules if you required separate "Formatting" / "Lint" checks).
6166
build:
6267
name: Build
@@ -65,6 +70,8 @@ jobs:
6570
steps:
6671
- name: Checkout repository
6772
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 (node24 runtime; fewer forced-runtime warnings)
73+
with:
74+
fetch-depth: 1
6875

6976
- name: Cache Next.js build
7077
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
@@ -83,6 +90,26 @@ jobs:
8390
env:
8491
NODE_ENV: production
8592

93+
- name: Analyze bundle size
94+
run: |
95+
echo "=== Bundle Size Analysis ==="
96+
du -sh .next/static/chunks/* 2>/dev/null | sort -h | tail -10 || echo "No chunks found"
97+
TOTAL_SIZE=$(du -sb .next 2>/dev/null | awk '{print $1}')
98+
TOTAL_SIZE_MB=$((TOTAL_SIZE / 1024 / 1024))
99+
echo "Total build size: ${TOTAL_SIZE_MB}MB"
100+
if [ "$TOTAL_SIZE_MB" -gt 50 ]; then
101+
echo "WARNING: Build size exceeds 50MB"
102+
fi
103+
104+
- name: Generate and validate sitemap
105+
run: |
106+
pnpm run generate-sitemap
107+
if [ ! -f public/sitemap.xml ]; then
108+
echo "ERROR: Sitemap generation failed"
109+
exit 1
110+
fi
111+
echo "Sitemap generated: $(wc -l < public/sitemap.xml) lines"
112+
86113
# Tarball avoids upload-artifact v4 directory flattening (files must land under SortVision/.next for `next start`).
87114
- name: Pack Next.js build for CI artifact
88115
working-directory: ${{ github.workspace }}
@@ -107,6 +134,9 @@ jobs:
107134
steps:
108135
- name: Checkout repository
109136
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 (node24 runtime; fewer forced-runtime warnings)
137+
with:
138+
# Full history on PRs so git diff base...head works for the "vs main" table (push stays shallow).
139+
fetch-depth: ${{ github.event_name == 'pull_request' && '0' || '1' }}
110140

111141
- name: Setup SortVision
112142
uses: ./.github/actions/setup-sortvision
@@ -120,12 +150,12 @@ jobs:
120150
run: |
121151
pnpm run start &
122152
echo $! > .server-pid
123-
npx wait-on http://localhost:3000 --timeout 120000
153+
pnpm exec wait-on http://localhost:3000 --timeout 120000
124154
sleep 2
125155
126-
- name: Run complete test suite (600+ tests)
156+
- name: Run complete test suite (core + extended sitemap, links, security)
127157
id: qa_tests
128-
run: pnpm test
158+
run: pnpm run test:ci
129159
env:
130160
CI: 'true'
131161
GITHUB_ACTIONS: 'true'
@@ -152,6 +182,16 @@ jobs:
152182
echo '${{ github.event.pull_request.number }}' > "$DIR/pr_number.txt"
153183
fi
154184
185+
- name: Append main vs PR diff (tests + scripts)
186+
if: github.event_name == 'pull_request' && always()
187+
working-directory: ${{ github.workspace }}
188+
env:
189+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
190+
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
191+
BASE_REF: ${{ github.event.pull_request.base.ref }}
192+
QA_COMMENT_FILE: ${{ github.workspace }}/SortVision/.qa-pr-comment/comment.md
193+
run: node SortVision/scripts/ci-append-pr-vs-base.cjs
194+
155195
- name: Find previous QA comment
156196
id: find_qa_comment
157197
if: github.event_name == 'pull_request' && always()
@@ -196,6 +236,8 @@ jobs:
196236
steps:
197237
- name: Checkout repository
198238
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 (node24 runtime; fewer forced-runtime warnings)
239+
with:
240+
fetch-depth: 1
199241

200242
- name: Setup SortVision
201243
uses: ./.github/actions/setup-sortvision
@@ -209,7 +251,7 @@ jobs:
209251
run: |
210252
pnpm run start &
211253
echo $! > .server-pid
212-
npx wait-on http://localhost:3000 --timeout 120000
254+
pnpm exec wait-on http://localhost:3000 --timeout 120000
213255
sleep 2
214256
215257
- name: Lighthouse (${{ matrix.variant }})
@@ -244,8 +286,13 @@ jobs:
244286
runs-on: ubuntu-latest
245287
timeout-minutes: 5
246288
steps:
247-
- name: Checkout repository
289+
- name: Checkout repository (summary script only)
248290
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 (node24 runtime; fewer forced-runtime warnings)
291+
with:
292+
fetch-depth: 1
293+
sparse-checkout: |
294+
SortVision/scripts/lighthouse-ci-summary.cjs
295+
sparse-checkout-cone-mode: false
249296

250297
- name: Download Lighthouse manifests (mobile)
251298
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
@@ -323,6 +370,8 @@ jobs:
323370
steps:
324371
- name: Checkout repository
325372
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 (node24 runtime; fewer forced-runtime warnings)
373+
with:
374+
fetch-depth: 1
326375

327376
- name: Setup Node.js
328377
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0

‎.github/workflows/extended-quality-assurance.yml‎

Lines changed: 0 additions & 134 deletions
This file was deleted.

‎SortVision/package.json‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
"version": "2.0.0",
55
"scripts": {
66
"test": "node tests/quality-assurance.mjs",
7+
"test:ci": "node tests/quality-assurance.mjs --extended",
8+
"test:unit": "node --test \"tests/unit/*.test.mjs\"",
79
"test:quick": "node tests/quality-assurance.mjs --quick",
810
"test:prod": "node tests/quality-assurance.mjs --production",
911
"test:extended": "node tests/quality-assurance.mjs --extended",
@@ -88,7 +90,8 @@
8890
"globals": "^17.4.0",
8991
"husky": "^9.1.7",
9092
"lint-staged": "^16.4.0",
91-
"prettier": "^3.8.1"
93+
"prettier": "^3.8.1",
94+
"wait-on": "9.0.4"
9295
},
9396
"engines": {
9497
"node": ">=24.0.0"

0 commit comments

Comments
 (0)