-
Notifications
You must be signed in to change notification settings - Fork 0
383 lines (333 loc) · 16.2 KB
/
Copy pathci-frontend.yml
File metadata and controls
383 lines (333 loc) · 16.2 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
name: Frontend CI
on:
pull_request:
merge_group:
push:
branches:
- master
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
permissions:
contents: read
pull-requests: write
actions: read
jobs:
# Job to decide if we should run frontend ci
# See https://github.com/dorny/paths-filter#conditional-execution for more details
# we skip each step individually, so they are still reported as success
# because many of them are required for CI checks to be green
changes:
runs-on: ubuntu-latest
timeout-minutes: 5
name: Determine need to run frontend checks
outputs:
frontend: ${{ steps.filter.outputs.frontend || 'true' }}
frontend_code: ${{ steps.filter.outputs.frontend_code || 'true' }}
steps:
# For pull requests it's not necessary to check out the code, but we
# also want this to run on master, so we need to check out
- uses: actions/checkout@v6
- uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
id: filter
if: github.event_name != 'push' # Run all tests on master push
with:
filters: |
frontend:
# Avoid running frontend tests for irrelevant changes
# NOTE: we are at risk of missing a dependency here.
- 'bin/**'
- 'frontend/**'
- 'ee/frontend/**'
- 'common/esbuilder/**'
- 'products/**/*.ts'
- 'products/**/*.tsx'
- 'products/**/*.json'
- 'playwright/**'
# Make sure we run if someone is explicitly change the workflow
- .github/workflows/ci-frontend.yml
# various JS config files
- .oxlintrc.json
- .oxfmtrc*
- babel.config.js
- package.json
- pnpm-lock.yaml
- jest.*.ts
- tsconfig.json
- tsconfig.*.json
- webpack.config.js
- stylelint*
- '**/*.md'
- '**/*.mdx'
- '**/*.yaml'
- '**/*.yml'
- .config/.markdownlint-cli2.jsonc
# Like `frontend` but excludes doc/config-only files that don't affect
# compiled output — used to skip Jest, bundle-size, and TypeScript checks
# when only markdown or YAML files change.
frontend_code:
- 'bin/**'
- 'frontend/**'
- 'ee/frontend/**'
- 'common/esbuilder/**'
- 'products/**/*.ts'
- 'products/**/*.tsx'
- 'products/**/*.json'
- 'playwright/**'
- .github/workflows/ci-frontend.yml
- .oxlintrc.json
- .oxfmtrc*
- babel.config.js
- package.json
- pnpm-lock.yaml
- jest.*.ts
- tsconfig.json
- tsconfig.*.json
- webpack.config.js
- stylelint*
frontend-format:
name: Frontend formatting
needs: changes
if: needs.changes.outputs.frontend == 'true'
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v6
- name: Install pnpm
uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4.2.0
- name: Fix node-gyp permissions
run: chmod +x ~/setup-pnpm/node_modules/.pnpm/pnpm@*/node_modules/pnpm/dist/node_modules/node-gyp/gyp/gyp_main.py
- name: Set up Node.js
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
with:
node-version-file: .nvmrc
cache: pnpm
cache-dependency-path: |
pnpm-lock.yaml
.github/workflows/ci-frontend.yml
- name: Install package.json dependencies with pnpm
run: |
pnpm --filter=@posthog/playwright... install --frozen-lockfile
bin/turbo --filter=@posthog/frontend prepare
- name: Check formatting with oxfmt
run: pnpm run format:frontend:check
- name: Lint with Stylelint
run: pnpm run lint:css
- name: Lint with Oxlint
run: pnpm exec oxlint --quiet
- name: Check markdown formatting with oxfmt
run: pnpm exec oxfmt --check "**/*.{md,mdx}"
- name: Check YAML formatting with oxfmt
run: pnpm exec oxfmt --check "**/*.{yaml,yml}"
- name: Lint markdown files
run: pnpm exec markdownlint-cli2 --config .config/.markdownlint-cli2.jsonc "**/*.{md,mdx}"
frontend-bundle-size:
name: Frontend bundle size
needs: [changes]
if: needs.changes.outputs.frontend_code == 'true' && github.event_name != 'merge_group'
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v6
with:
filter: blob:none
- name: Install pnpm
uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4.2.0
- name: Fix node-gyp permissions
run: chmod +x ~/setup-pnpm/node_modules/.pnpm/pnpm@*/node_modules/pnpm/dist/node_modules/node-gyp/gyp/gyp_main.py
- name: Set up Node.js
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
with:
node-version-file: .nvmrc
cache: pnpm
cache-dependency-path: |
pnpm-lock.yaml
.github/workflows/ci-frontend.yml
- name: Install package.json dependencies with pnpm
run: |
pnpm --filter=@posthog/playwright... install --frozen-lockfile
bin/turbo --filter=@posthog/frontend prepare
- name: Build products
run: pnpm --filter=@posthog/frontend build:products
- name: Check frontend bundle size
uses: preactjs/compressed-size-action@946a292cd35bd1088e0d7eb92b69d1a8d5b5d76a # v2
with:
build-script: '--filter=@posthog/frontend build'
install-script: 'pnpm --filter=@posthog/frontend... install'
compression: 'none'
# Check all JS bundles in the dist folder
pattern: 'frontend/dist/**/*.js'
# Exclude source maps and chunk files (chunk hashes change every build)
exclude: '{**/*.js.map,**/chunk*.js}'
# Only show large changes
minimum-change-threshold: 1000
order-by: 'Size:desc'
strip-hash: "-[A-Za-z0-9]{8}\\.js$"
- name: Check toolbar for CSP eval violations
run: pnpm --filter=@posthog/frontend check-toolbar-csp-eval
- name: Calculate dist folder size
id: dist-size
run: |
size_bytes=$(du -sb frontend/dist | cut -f1)
echo "size_bytes=${size_bytes}" >> $GITHUB_OUTPUT
echo "Frontend dist folder size: ${size_bytes} bytes ($(numfmt --to=iec-i --suffix=B ${size_bytes}))"
- name: Capture bundle size to PostHog
if: |
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == 'PostHog/posthog') ||
(github.event_name != 'pull_request' && github.repository == 'PostHog/posthog')
uses: PostHog/posthog-github-action@8c42e50f2c52e002eabb9bee3f69b152ee8fc1dd # v1.0.1
with:
posthog-token: ${{secrets.POSTHOG_API_TOKEN}}
event: 'posthog-ci-frontend-bundle-size'
properties: |
{
"size_bytes": ${{ steps.dist-size.outputs.size_bytes }},
"branch": ${{ toJSON(github.head_ref || github.ref_name) }},
"sha": ${{ toJSON(github.sha) }},
"pr_number": ${{ github.event.pull_request.number || 'null' }},
"event_type": ${{ toJSON(github.event_name) }}
}
frontend-typescript-checks:
name: Frontend typechecking
needs: [changes]
if: needs.changes.outputs.frontend_code == 'true'
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v6
- name: Install pnpm
uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4.2.0
- name: Fix node-gyp permissions
run: chmod +x ~/setup-pnpm/node_modules/.pnpm/pnpm@*/node_modules/pnpm/dist/node_modules/node-gyp/gyp/gyp_main.py
- name: Set up Node.js
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
with:
node-version-file: .nvmrc
cache: pnpm
cache-dependency-path: |
pnpm-lock.yaml
.github/workflows/ci-frontend.yml
- name: Install package.json dependencies with pnpm
run: |
pnpm --filter=@posthog/playwright... install --no-frozen-lockfile
bin/turbo --filter=@posthog/frontend prepare
- name: Restore .typegen cache
uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5
with:
path: .typegen
key: ${{ runner.os }}-typegen-${{ hashFiles('pnpm-lock.yaml') }}
restore-keys: ${{ runner.os }}-typegen-
- name: Build products
run: pnpm --filter=@posthog/frontend build:products
- name: Check if products.tsx and products.json are up to date
run: pnpm --filter=@posthog/frontend build:products && git diff --exit-code
- name: Kea typegen
run: pnpm --filter=@posthog/frontend typegen:write
- name: Re-format files after typegen
run: pnpm exec oxfmt "./{products,frontend/src}/**/*.{ts,tsx}"
- name: Save .typegen cache
if: github.ref == 'refs/heads/master'
uses: actions/cache/save@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5
with:
path: .typegen
key: ${{ runner.os }}-typegen-${{ hashFiles('pnpm-lock.yaml') }}
- name: Run typescript with strict
run: pnpm --filter=@posthog/frontend typescript:check
env:
NODE_OPTIONS: --max-old-space-size=16384
- name: Check if schema.json and validators.js are up to date
run: pnpm --filter=@posthog/frontend schema:build:json && git diff --exit-code
- name: Check if mobile replay "schema.json" is up to date
run: pnpm --filter=@posthog/frontend mobile-replay:schema:build:json && git diff --exit-code
env:
NODE_OPTIONS: --max-old-space-size=8192
- name: Validate SetupTaskId completions
run: node bin/validate-setup-tasks.mjs
jest:
runs-on: ubuntu-latest
timeout-minutes: 15
needs: changes
if: needs.changes.outputs.frontend_code == 'true'
name: Jest test (${{ matrix.segment }} - ${{ matrix.chunk }})
strategy:
# If one test fails, still run the others
fail-fast: false
matrix:
segment: ['FOSS', 'EE']
chunk: [1, 2]
steps:
- uses: actions/checkout@v6
- name: Remove ee
if: matrix.segment == 'FOSS'
run: rm -rf ee
- name: Install pnpm
uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4.2.0
- name: Fix node-gyp permissions
run: chmod +x ~/setup-pnpm/node_modules/.pnpm/pnpm@*/node_modules/pnpm/dist/node_modules/node-gyp/gyp/gyp_main.py
- name: Set up Node.js
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
with:
node-version-file: .nvmrc
cache: pnpm
cache-dependency-path: |
pnpm-lock.yaml
.github/workflows/ci-frontend.yml
- name: Install package.json dependencies with pnpm
run: pnpm --filter=@posthog/frontend... install --frozen-lockfile
- name: Test with Jest
run: bin/turbo run test --filter=@posthog/frontend -- --maxWorkers=2
env:
NODE_OPTIONS: --max-old-space-size=16384
SHARD_INDEX: ${{ matrix.chunk }}
SHARD_COUNT: 2
calculate-running-time:
name: Calculate running time
needs: [jest, frontend-typescript-checks, frontend-format, frontend-bundle-size, changes]
runs-on: ubuntu-latest
timeout-minutes: 5
if: # Run on pull requests to PostHog/posthog + on PostHog/posthog outside of PRs - but never on forks or Dependabot (no secrets access)
always() && github.actor != 'dependabot[bot]' &&
needs.changes.outputs.frontend_code == 'true' && (
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == 'PostHog/posthog') ||
(github.event_name != 'pull_request' && github.repository == 'PostHog/posthog'))
steps:
- name: Capture running time to PostHog
uses: PostHog/posthog-github-action@eea1405eeb2d1d2259f0ee0b44d7b152869e6840 # v1.1.1
with:
posthog-token: ${{ secrets.POSTHOG_API_TOKEN }}
event: 'posthog-ci-running-time'
capture-run-duration: true
capture-job-durations: true
github-token: ${{ secrets.GITHUB_TOKEN }}
status-job: 'Frontend Tests Pass'
runner: 'github'
frontend_tests:
needs: [jest, frontend-format, frontend-bundle-size, frontend-typescript-checks]
name: Frontend Tests Pass
runs-on: ubuntu-latest
timeout-minutes: 5
if: always()
steps:
- run: exit 0
- name: Check outcomes
run: |
if [[ "${{ needs.jest.result }}" != "success" && "${{ needs.jest.result }}" != "skipped" ]]; then
echo "Frontend jest tests failed."
exit 1
fi
echo "Frontend jest tests passed."
if [[ "${{ needs.frontend-format.result }}" != "success" && "${{ needs.frontend-format.result }}" != "skipped" ]]; then
echo "Frontend linting failed."
exit 1
fi
echo "Frontend linting passed."
if [[ "${{ needs.frontend-bundle-size.result }}" != "success" && "${{ needs.frontend-bundle-size.result }}" != "skipped" ]]; then
echo "Frontend bundle size checks failed."
exit 1
fi
echo "Frontend bundle size checks passed."
if [[ "${{ needs.frontend-typescript-checks.result }}" != "success" && "${{ needs.frontend-typescript-checks.result }}" != "skipped" ]]; then
echo "Frontend TypeScript checks failed."
exit 1
fi
echo "Frontend TypeScript checks passed."