-
Notifications
You must be signed in to change notification settings - Fork 0
167 lines (146 loc) · 6.15 KB
/
Copy pathpr-checks.yml
File metadata and controls
167 lines (146 loc) · 6.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# Runs on every pull request:
# 1. biome – lint + format check (fails fast; annotates changed lines in the PR diff)
# 2. vitest – unit/integration tests with coverage (posts a summary comment on the PR)
# 3. playwright – e2e tests (uploads an HTML report as an artifact; posts a pass/fail comment)
#
# Required repository permissions (already granted to GITHUB_TOKEN by default for
# non-fork PRs; no extra secrets needed):
# • contents: read
# • pull-requests: write
name: PR Checks
on:
pull_request:
branches:
- main # adjust if your default branch is named differently
- master
# Cancel any in-progress run for the same PR branch so pushes don't queue up.
concurrency:
group: pr-checks-${{ github.head_ref }}
cancel-in-progress: true
jobs:
# ─────────────────────────────────────────────
# Job 1 · Biome – lint & format
# ─────────────────────────────────────────────
biome:
name: Biome (lint + format)
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
# biomejs/setup-biome installs the exact version declared in your
# package.json / biome.json. Pin to "latest" to always use the newest
# release, or pin to a semver string for reproducibility.
- name: Setup Biome
uses: biomejs/setup-biome@v2
with:
version: latest
# `biome ci` is the recommended command for CI:
# • exits non-zero on any lint/format error
# • emits GitHub annotations so errors appear inline in the PR diff
# • never auto-fixes (safe for CI)
- name: Run Biome CI
run: biome ci .
# ─────────────────────────────────────────────
# Job 2 · Vitest – unit & integration tests
# ─────────────────────────────────────────────
vitest:
name: Vitest (unit tests + coverage)
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write # needed to post the coverage comment
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: lts/*
cache: npm
- name: Install dependencies
run: npm ci
# Run Vitest with coverage enabled.
# Your vitest.config.ts should include at minimum:
#
# coverage: {
# provider: 'v8', // or 'istanbul'
# reporter: ['text', 'json-summary', 'json'],
# }
#
# The `json-summary` reporter is required by vitest-coverage-report-action.
# The `json` reporter enables per-file coverage detail in the PR comment.
- name: Run tests with coverage
run: npx vitest run --coverage
# Upload the coverage directory so the reporting step can consume it.
- name: Upload coverage artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: vitest-coverage
path: coverage/
retention-days: 7
# Post (or update) a coverage summary comment directly on the PR.
# Uses: https://github.com/davelosert/vitest-coverage-report-action
- name: Report coverage on PR
if: always()
uses: davelosert/vitest-coverage-report-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
json-summary-path: coverage/coverage-summary.json
json-final-path: coverage/coverage-final.json
# ─────────────────────────────────────────────
# Job 3 · Playwright – end-to-end tests
# ─────────────────────────────────────────────
playwright:
name: Playwright (e2e)
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write # needed to post the test-result comment
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: lts/*
cache: npm
- name: Install dependencies
run: npm ci
# Install Playwright's browser binaries + OS-level dependencies.
# Remove browsers you don't need to speed up the job.
- name: Install Playwright browsers
run: npx playwright install --with-deps chromium firefox webkit
# Build the Next.js app before running e2e tests.
# Remove this step if your Playwright config handles the dev server itself
# via the `webServer` option (recommended for most setups).
- name: Build Next.js app
run: npm run build
# Run Playwright. The `json` reporter writes results.json which is
# consumed by the PR-comment action below.
# Your playwright.config.ts reporter array should include:
# reporter: [['html'], ['json', { outputFile: 'results.json' }]]
- name: Run Playwright tests
run: npx playwright test --reporter=html,json
env:
# Ensure Playwright writes the JSON report to the project root.
PLAYWRIGHT_JSON_OUTPUT_NAME: results.json
# Always upload the HTML report so you can inspect failures even when
# the job is marked red.
- name: Upload Playwright HTML report
if: always()
uses: actions/upload-artifact@v4
with:
name: playwright-report
path: playwright-report/
retention-days: 14
# Post (or update) a pass/fail summary comment on the PR.
# Uses: https://github.com/daun/playwright-report-summary
- name: Post Playwright results to PR
if: always()
uses: daun/playwright-report-summary@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
report-file: results.json