-
Notifications
You must be signed in to change notification settings - Fork 11
140 lines (117 loc) · 3.71 KB
/
main.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
---
name: Test and build Docker image
on:
merge_group:
pull_request:
workflow_call:
workflow_dispatch:
jobs:
check:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: "opensafely-core/setup-action@v1"
with:
python-version: "3.12"
install-just: true
- name: Check formatting, linting and import sorting
run: just check
test:
runs-on: ubuntu-22.04
services:
postgres:
image: postgres:13
env:
POSTGRES_USER: user
POSTGRES_PASSWORD: password
POSTGRES_DB: jobserver
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
- uses: "opensafely-core/setup-action@v1"
with:
python-version: "3.12"
install-just: true
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version-file: ".node-version"
cache: "npm"
cache-dependency-path: package-lock.json
- name: Install node_modules
run: just assets-install --ignore-scripts
- name: Lint assets
run: npm run lint
- name: Run JS tests
run: just assets-test
- name: Build assets
run: just assets-build
- name: Install venv
run: just devenv
- name: Run tests
env:
DATABASE_URL: postgres://user:password@localhost/jobserver
GITHUB_TOKEN: empty
GITHUB_TOKEN_TESTING: ${{ secrets.OPENSAFELY_GITHUB_TESTING_ORG_PAT }}
SECRET_KEY: 12345
SOCIAL_AUTH_GITHUB_KEY: test
SOCIAL_AUTH_GITHUB_SECRET: test
run: |
just check-migrations
# hardcode n because auto=2 in CI for some reason
just test-ci -n 4
- name: Upload HTML coverage report if tests failed
uses: actions/upload-artifact@v4
with:
name: python-coverage-report
path: htmlcov
# don't fail the job because no files were found, we expect this when
# * the tests passed with 100% coverage
# * a test failed and coverage didn't run
if-no-files-found: ignore
if: ${{ failure() }} # only upload when the previous step, run tests, fails
lint-dockerfile:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: hadolint/hadolint-action@54c9adbab1582c2ef04b2016b760714a4bfde3cf # v3.1.0
with:
dockerfile: docker/Dockerfile
docker-test:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: "opensafely-core/setup-action@v1"
with:
install-just: true
- name: Build docker image for both prod and dev
run: |
just docker-build prod
just docker-build dev
- name: Run unit tests on docker dev image
env:
GITHUB_TOKEN_TESTING: ${{ secrets.OPENSAFELY_GITHUB_TESTING_ORG_PAT }}
INTERACTIVE_GITHUB_TOKEN:
run: |
# build docker and run test
just docker-test -n 4 # hardcode n because auto does not dtrt in docker
- name: Run smoke test on prod
run: |
just docker-serve prod -d
sleep 5
just docker-smoke-test || { docker logs job-server_prod_1; exit 1; }
- name: Save docker image
run: |
docker save job-server | zstd --fast -o /tmp/job-server.tar.zst
- name: Upload docker image
uses: actions/upload-artifact@v4
with:
name: job-server-image
path: /tmp/job-server.tar.zst
compression-level: 0