-
Notifications
You must be signed in to change notification settings - Fork 1.5k
200 lines (173 loc) · 8.33 KB
/
ci-frontend.yml
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
name: Frontend CI
on:
pull_request:
push:
branches:
- master
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
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-24.04
timeout-minutes: 5
name: Determine need to run frontend checks
outputs:
frontend: ${{ steps.filter.outputs.frontend }}
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@v3
- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
frontend:
# Avoid running frontend tests for irrelevant changes
# NOTE: we are at risk of missing a dependency here.
- 'bin/**'
- 'frontend/**'
- 'ee/frontend/**'
# Make sure we run if someone is explicitly change the workflow
- .github/workflows/ci-frontend.yml
# various JS config files
- .eslintrc.js
- .prettier*
- babel.config.js
- package.json
- pnpm-lock.yaml
- jest.*.ts
- tsconfig.json
- tsconfig.*.json
- webpack.config.js
- stylelint*
frontend-code-quality:
name: Code quality checks
needs: changes
# kea typegen and typescript:check need some more oomph
runs-on: ubuntu-24.04
steps:
# we need at least one thing to run to make sure we include everything for required jobs
- uses: actions/checkout@v3
- name: Install pnpm
if: needs.changes.outputs.frontend == 'true'
uses: pnpm/action-setup@v4
- name: Set up Node.js
if: needs.changes.outputs.frontend == 'true'
uses: actions/setup-node@v4
with:
node-version: 18.12.1
- name: Get pnpm cache directory path
if: needs.changes.outputs.frontend == 'true'
id: pnpm-cache-dir
run: echo "PNPM_STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
if: needs.changes.outputs.frontend == 'true'
id: pnpm-cache
with:
path: ${{ steps.pnpm-cache-dir.outputs.PNPM_STORE_PATH }}
key: ${{ runner.os }}-pnpm-cypress-${{ hashFiles('pnpm-lock.yaml') }}
restore-keys: ${{ runner.os }}-pnpm-cypress-
- name: Install package.json dependencies with pnpm
if: needs.changes.outputs.frontend == 'true'
run: pnpm --filter=@posthog/frontend install --frozen-lockfile
- name: Check formatting with prettier
if: needs.changes.outputs.frontend == 'true'
run: pnpm prettier:check
- name: Lint with Stylelint
if: needs.changes.outputs.frontend == 'true'
run: pnpm lint:css
- name: Generate logic types and run typescript with strict
if: needs.changes.outputs.frontend == 'true'
run: pnpm typegen:write && pnpm typescript:check
- name: Lint with ESLint
if: needs.changes.outputs.frontend == 'true'
run: pnpm lint:js
- name: Check if "schema.json" is up to date
if: needs.changes.outputs.frontend == 'true'
run: pnpm schema:build:json && git diff --exit-code
- name: Check if mobile replay "schema.json" is up to date
if: needs.changes.outputs.frontend == 'true'
run: pnpm mobile-replay:schema:build:json && git diff --exit-code
- name: Check toolbar bundle size
if: needs.changes.outputs.frontend == 'true'
uses: preactjs/compressed-size-action@v2
with:
build-script: 'build'
compression: 'none'
pattern: 'frontend/dist/toolbar.js'
# we only care if the toolbar will increase a lot
minimum-change-threshold: 1000
jest:
runs-on: ubuntu-24.04
needs: changes
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, 3]
steps:
# we need at least one thing to run to make sure we include everything for required jobs
- uses: actions/checkout@v3
- name: Remove ee
if: needs.changes.outputs.frontend == 'true' && matrix.segment == 'FOSS'
run: rm -rf ee
- name: Install pnpm
if: needs.changes.outputs.frontend == 'true'
uses: pnpm/action-setup@v4
- name: Set up Node.js
if: needs.changes.outputs.frontend == 'true'
uses: actions/setup-node@v4
with:
node-version: 18.12.1
cache: pnpm
- name: Install package.json dependencies with pnpm
if: needs.changes.outputs.frontend == 'true'
run: pnpm --filter=@posthog/frontend install --frozen-lockfile
- name: Test with Jest
# set maxWorkers or Jest only uses 1 CPU in GitHub Actions
run: pnpm test:unit --maxWorkers=2 --shard=${{ matrix.chunk }}/3
if: needs.changes.outputs.frontend == 'true'
env:
NODE_OPTIONS: --max-old-space-size=6144
calculate-running-time:
name: Calculate running time
needs: [jest, frontend-code-quality, changes]
runs-on: ubuntu-24.04
if: needs.changes.outputs.frontend == 'true'
steps:
- name: Calculate running time
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token
run_id=${GITHUB_RUN_ID}
repo=${GITHUB_REPOSITORY}
run_info=$(gh api repos/${repo}/actions/runs/${run_id})
echo run_info: ${run_info}
# name is the name of the workflow file
# run_started_at is the start time of the workflow
# we want to get the number of seconds between the start time and now
name=$(echo ${run_info} | jq -r '.name')
run_url=$(echo ${run_info} | jq -r '.url')
run_started_at=$(echo ${run_info} | jq -r '.run_started_at')
run_attempt=$(echo ${run_info} | jq -r '.run_attempt')
start_seconds=$(date -d "${run_started_at}" +%s)
now_seconds=$(date +%s)
duration=$((now_seconds-start_seconds))
echo running_time_duration_seconds=${duration} >> $GITHUB_ENV
echo running_time_run_url=${run_url} >> $GITHUB_ENV
echo running_time_run_attempt=${run_attempt} >> $GITHUB_ENV
echo running_time_run_id=${run_id} >> $GITHUB_ENV
echo running_time_run_started_at=${run_started_at} >> $GITHUB_ENV
- name: Capture running time to PostHog
if: needs.changes.outputs.frontend == 'true'
uses: PostHog/[email protected]
with:
posthog-token: ${{secrets.POSTHOG_API_TOKEN}}
event: 'posthog-ci-running-time'
properties: '{"duration_seconds": ${{ env.running_time_duration_seconds }}, "run_url": "${{ env.running_time_run_url }}", "run_attempt": "${{ env.running_time_run_attempt }}", "run_id": "${{ env.running_time_run_id }}", "run_started_at": "${{ env.running_time_run_started_at }}"}'