-
Notifications
You must be signed in to change notification settings - Fork 42
311 lines (291 loc) · 9.51 KB
/
Copy pathlint_and_test.yml
File metadata and controls
311 lines (291 loc) · 9.51 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
name: Lint and Test
on:
pull_request:
paths-ignore:
- 'components/**'
- 'docs/**'
- 'mkdocs.yml'
- 'README.md'
- 'CLAUDE.md'
- 'LICENSE'
- '.coderabbit.yaml'
- 'locust/**'
- 'cypress/**'
- 'cypress.config.ts'
- 'cypress.env.json'
- 'docker-compose-dev.yml'
- 'heroku.yml'
- 'app.json'
- 'scripts/**'
- 'media/**'
push:
branches:
- main
paths-ignore:
- 'components/**'
- 'docs/**'
- 'mkdocs.yml'
- 'README.md'
- 'CLAUDE.md'
- 'LICENSE'
- '.coderabbit.yaml'
- 'locust/**'
- 'cypress/**'
- 'cypress.config.ts'
- 'cypress.env.json'
- 'docker-compose-dev.yml'
- 'heroku.yml'
- 'app.json'
- 'scripts/**'
- 'media/**'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
PYTHON_VERSION: '3.13'
permissions:
contents: read
jobs:
build-image:
# Pre-build the prod container image (tagged by commit SHA) in parallel with
# the tests, so the Deploy workflow — which chains off this one — can skip the
# build and go straight to migrate + deploy. Only runs on main pushes, so
# PR/fork code never receives AWS credentials.
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v6
with:
persist-credentials: false
- name: Set variables
run: |
APP_NAME="${{ fromJSON(vars.DEPLOY_APP_NAME)['prod'] }}"
echo "ECR_REPOSITORY=$APP_NAME-prod-ecr-repo" >> "$GITHUB_ENV"
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v6.2.1
with:
role-to-assume: "arn:aws:iam::${{ fromJSON(vars.AWS_ACCOUNT)['prod'] }}:role/github_deploy"
role-session-name: GithubBuild
aws-region: ${{ fromJSON(vars.DEPLOY_AWS_REGION)['prod'] }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2.1.6
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Get image names
id: image-name
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
run: |
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> "$GITHUB_OUTPUT"
echo "image_latest=$ECR_REGISTRY/$ECR_REPOSITORY:latest" >> "$GITHUB_OUTPUT"
- name: Build and push
uses: docker/build-push-action@v7
with:
tags: |
${{ steps.image-name.outputs.image }}
${{ steps.image-name.outputs.image_latest }}
file: Dockerfile
cache-from: type=gha
cache-to: type=gha,mode=max
outputs: type=image,push=true,oci-mediatypes=true,compression=zstd,compression-level=3
build-frontend:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Use Node.js
uses: actions/setup-node@v6
with:
node-version: 24.x
- name: Install dependencies
run: npm ci
- name: Build front end
run: npm run build
- name: Check types
run: npm run type-check
code-style:
if: github.ref != 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: 24.x
- uses: astral-sh/setup-uv@v7
with:
enable-cache: true
- name: Install dependencies
run: |
npm ci
sudo apt-get install -y ripgrep
uv venv
uv sync --locked --dev
- id: file_changes
uses: trilom/file-changes-action@v1.2.4
- id: changed_files
name: Build space-separated file list
env:
CHANGED_FILES: ${{ steps.file_changes.outputs.files }}
run: |
files=$(printf '%s' "$CHANGED_FILES" | jq -r '.[]' | tr '\n' ' ')
echo "files=$files" >> "$GITHUB_OUTPUT"
- name: Run pre-commit hooks
uses: j178/prek-action@v2
with:
extra-args: --files ${{ steps.changed_files.outputs.files }}
type-check:
if: github.ref != 'refs/heads/main'
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: ${{ env.PYTHON_VERSION }}
- uses: astral-sh/setup-uv@v7
with:
enable-cache: true
- name: Install dependencies
run: |
uv venv
uv sync --locked --dev
- name: Run ty type checker
run: uv run ty check apps/
inline-imports:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v6
- id: file_changes
uses: trilom/file-changes-action@v1.2.4
- id: py_files
name: Filter changed Python files
env:
CHANGED_FILES: ${{ steps.file_changes.outputs.files }}
run: |
files=$(printf '%s' "$CHANGED_FILES" | jq -r '.[]' | grep -E '^apps/.*\.py$' | tr '\n' ' ' || true)
echo "files=$files" >> "$GITHUB_OUTPUT"
- name: Set up Python
if: steps.py_files.outputs.files != ''
uses: actions/setup-python@v6
with:
python-version: ${{ env.PYTHON_VERSION }}
- uses: astral-sh/setup-uv@v7
if: steps.py_files.outputs.files != ''
with:
enable-cache: true
- name: Install dependencies
if: steps.py_files.outputs.files != ''
run: |
uv venv
uv sync --locked --dev
- name: Check inline imports in changed files
if: steps.py_files.outputs.files != ''
env:
SECRET_KEY: secret-test-key
CHANGED_FILES: ${{ steps.py_files.outputs.files }}
run: |
read -r -a files <<< "$CHANGED_FILES"
uv run python scripts/check_inline_imports.py apps --files "${files[@]}"
check-uv-lock:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: ${{ env.PYTHON_VERSION }}
- uses: astral-sh/setup-uv@v7
- name: Check lockfile
run: uv lock --check
python-tests:
runs-on: ubuntu-latest
timeout-minutes: 60
services:
postgres:
image: pgvector/pgvector:pg16
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres_password
POSTGRES_INITDB_ARGS: "--no-sync"
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
--tmpfs /var/lib/postgresql/data
ports:
- 5432:5432
redis:
image: redis
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379
steps:
- uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: ${{ env.PYTHON_VERSION }}
- uses: astral-sh/setup-uv@v7
with:
enable-cache: true
- name: Install Dependencies
run: |
uv venv
uv sync --locked --dev
- name: Configure Postgres for performance
run: |
PGPASSWORD=postgres_password psql -h localhost -U postgres \
-c "ALTER SYSTEM SET fsync = off;" \
-c "ALTER SYSTEM SET synchronous_commit = off;" \
-c "ALTER SYSTEM SET full_page_writes = off;" \
-c "ALTER SYSTEM SET checkpoint_completion_target = 0.9;" \
-c "SELECT pg_reload_conf();"
# Create extensions in template1 so test databases inherit them. This lets PR runs
# use --no-migrations (the extensions are normally created by a migration).
PGPASSWORD=postgres_password psql -h localhost -U postgres -d template1 \
-c "CREATE EXTENSION IF NOT EXISTS vector;" \
-c "CREATE EXTENSION IF NOT EXISTS pg_trgm;"
- name: Set test flags
id: test_flags
run: |
# On main, run with migrations (and coverage) so migrations stay exercised before deploy.
# On PRs, skip migrations for faster feedback.
if [ "$GITHUB_REF" = "refs/heads/main" ]; then
echo "flags=--cov --cov-report=xml" >> "$GITHUB_OUTPUT"
else
echo "flags=--no-migrations" >> "$GITHUB_OUTPUT"
fi
- name: Run Tests
env:
DJANGO_DATABASE_USER: postgres
DJANGO_DATABASE_PASSWORD: postgres_password
SECRET_KEY: secret-test-key
PYTHONWARNINGS: default
run: uv run pytest -n auto ${{ steps.test_flags.outputs.flags }} --junitxml=junit.xml -o junit_family=legacy
- name: Upload results to Codecov
if: ${{ !cancelled() && github.ref == 'refs/heads/main' }}
uses: codecov/codecov-action@v7
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: Upload test results to Codecov
if: ${{ !cancelled() }}
uses: codecov/test-results-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}