-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
219 lines (195 loc) · 4.07 KB
/
.gitlab-ci.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# vim:set sw=2 ts=2 et:
stages:
- install
- build
- test
- deploy
# Base jobs for other jobs that need Python and Node dependencies to extend
.python:
# Make sure the Python and Poetry versions here match the Dockerfile
image: python:3.12
variables:
PYTHONUNBUFFERED: 1
before_script:
- . .venv/bin/activate
needs:
- poetry_install
cache:
key:
files:
- pyproject.toml
- poetry.lock
paths:
- .venv
policy: pull
.node:
image: node:20
needs:
- npm_install
cache:
key:
files:
- package.json
- package-lock.json
paths:
- node_modules
policy: pull
# Dependency installation jobs
poetry_install:
stage: install
extends: .python
before_script: []
needs: []
variables:
POETRY_VERSION: 1.7.1
script: >
if [ ! -d "./.venv" ];
then
pip install "poetry==${POETRY_VERSION}"
python -m venv --upgrade-deps .venv
. .venv/bin/activate
poetry install
fi
cache:
policy: pull-push
npm_install:
stage: install
extends: .node
needs: []
script: >
if [ ! -d "./node_modules" ];
then
npm ci
fi
cache:
policy: pull-push
# Front-end jobs
static:
stage: build
extends: .node
script:
- npm run build:prod
artifacts:
name: static-$CI_JOB_ID
paths:
- ./node_modules
- ./workshop/static_compiled
expire_in: 30 mins
lint_js:
stage: test
extends: .node
script:
- npm run lint:js
lint_css:
stage: test
extends: .node
script:
- npm run lint:css
lint_format:
stage: test
extends: .node
script:
- npm run lint:format
test_js:
stage: test
extends: .node
script:
- npm run test:coverage
# Back-end jobs
black:
stage: test
extends: .python
script:
- black --check --diff ./
flake8:
stage: test
extends: .python
script:
- flake8 ./
isort:
stage: test
extends: .python
script:
- isort --check --diff ./
djhtml:
stage: test
extends: .python
script:
- find workshop/ -name '*.html' | xargs djhtml --check
test_python:
stage: test
extends: .python
services:
# Make sure this matches the Postgres version you run on your servers.
- postgres:15
needs:
- poetry_install
- static
variables:
DATABASE_URL: postgres://postgres@postgres/postgres
DJANGO_SETTINGS_MODULE: workshop.settings.test
ENABLE_DJANGO_DEFENDER: 'false'
POSTGRES_HOST_AUTH_METHOD: trust
RECAPTCHA_PRIVATE_KEY: 'dummy-key-value'
RECAPTCHA_PUBLIC_KEY: 'dummy-key-value'
SECRET_KEY: fake_secret_key_to_run_tests
script:
- coverage erase
- apt-get update
- apt-get install --yes git libpq-dev
- python manage.py collectstatic --verbosity 0 --noinput --clear
- python manage.py check
- python manage.py makemigrations --check --noinput
- coverage run manage.py test --parallel
- coverage combine
- coverage xml
- coverage report
coverage: '/TOTAL.*\s+(\d+%)$/'
artifacts:
reports:
coverage_report:
coverage_format: cobertura
path: ./coverage.xml
# Deployment jobs
.heroku_deployment:
image: curlimages/curl:latest
stage: deploy
script:
- 'echo "Deploying to Heroku. To see progress, go to: https://dashboard.heroku.com/apps/$HEROKU_APP/activity"'
- curl --fail-with-body -s -X POST -m 900 https://heroku-deploy.torchbox.com/$HEROKU_APP/$CI_COMMIT_SHA?key=$DEPLOYMENT_KEY
deploy_staging:
extends: .heroku_deployment
variables:
HEROKU_APP: workshop-staging
only:
- staging
environment:
name: staging
url: https://workshop-staging.torchbox.dev
deploy_production:
extends: .heroku_deployment
variables:
HEROKU_APP: workshop-production
only:
- main
when: manual
environment:
name: production
url: https://workshop-production.torchbox.dev
# Gitlab Pages job (for project documentation)
pages:
stage: deploy
extends: .python
only:
refs:
- main
changes:
- docs/**/*
script:
- mkdocs build
- rm -rf public/
- mkdir public
- mv site/* public
artifacts:
paths:
- public