forked from FLawrence/tna-omega-ui-prototypes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
242 lines (216 loc) · 5.81 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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# vim:set sw=2 ts=2 et:
# This is a sample .gitlab-ci.yml created by wagtail-kit. You should review
# it for any necessary changes.
# Stages are groups that jobs can be grouped into.
# Jobs within each stage run in parallel and if one of them fails, the next
# stage won't be run.
# This will set up the following:
#
# - Build stage: build of static assets.
# - Test stage: code style, migration, basic configuration checks and unit
# tests.
# - Deploy stage: deploy to Heroku.
stages:
- build
- test
- deploy_site
- pages
# Test if static assets can be built successfully.
static:
image: node:16
stage: build
script:
- npm ci --no-optional --no-audit --progress=false
- npm run build:prod
# Saving the job result as an artifact means that the files can be used by
# other jobs.
artifacts:
name: 'static-$CI_JOB_ID'
paths:
- ./node_modules
- ./tnaomegauiprototypes/static_compiled
expire_in: 30 mins
poetry:
# If you update the python image version here, make sure you update all jobs that depend on this
# and the version in the Dockerfile and provision scripts as well
image: python:3.8
stage: build
variables:
POETRY_VERSION: 1.1.8
script:
- pip install poetry==$POETRY_VERSION
- python -m venv venv
- source venv/bin/activate
- poetry install
artifacts:
name: 'poetry-$CI_JOB_ID'
paths:
- ./venv/
expire_in: 30 mins
# Check python code style.
flake8:
# Make sure the python image version here matches the poetry job
image: python:3.8
stage: test
dependencies:
- poetry
before_script:
- source venv/bin/activate
script:
- flake8 tnaomegauiprototypes fabfile.py
# Check imports sort order, i.e. check whether they are in an alphabetical
# order and grouped properly.
isort:
# Make sure the python image version here matches the poetry job
image: python:3.8
stage: test
dependencies:
- poetry
before_script:
- source venv/bin/activate
script:
- isort --check-only --diff tnaomegauiprototypes fabfile.py
djhtml:
# Make sure the python image version here matches the poetry job
image: python:3.8
stage: test
dependencies:
- poetry
before_script:
- source venv/bin/activate
script:
- git ls-files '*.html' | xargs djhtml --check
lint_js:
image: node:16
stage: test
dependencies:
- static
script:
- npm run lint:js
lint_css:
image: node:16
stage: test
dependencies:
- static
script:
- npm run lint:css
lint_format:
image: node:16
stage: test
dependencies:
- static
script:
- npm run lint:format
# Run black and check for changes
black:
# Make sure the python image version here matches the poetry job
image: python:3.8
stage: test
dependencies:
- poetry
before_script:
- source venv/bin/activate
script:
- black --check ./
# Check settings, migrations and run tests.
test_python:
# Make sure the python image version here matches the poetry job
image: python:3.8
stage: test
services:
# Make sure this matches the Postgres version you run on your servers.
- postgres:12.3
dependencies:
- static
- poetry
variables:
POSTGRES_HOST_AUTH_METHOD: trust
# Run tests with the production settings.
DJANGO_SETTINGS_MODULE: tnaomegauiprototypes.settings.test
# SECRET_KEY is required by Django to start.
SECRET_KEY: fake_secret_key_to_run_tests
# Silence RECAPTCHA
RECAPTCHA_PUBLIC_KEY: 'dummy-key-value'
RECAPTCHA_PRIVATE_KEY: 'dummy-key-value'
# Disable django-defender
ENABLE_DJANGO_DEFENDER: 'false'
# This is the URL used by databases on our CI.
DATABASE_URL: postgres://postgres@postgres/postgres
# Don't redirect to HTTPS in tests.
SECURE_SSL_REDIRECT: 'false'
before_script:
- source venv/bin/activate
- coverage erase
script:
# We need to run the collectstatic command, because we use ManifestStaticFilesStorage.
# Otherwise the check command will fail
- python manage.py collectstatic --verbosity 0 --noinput --clear
# Run system checks
- python manage.py check
# Check for missing migrations
- python manage.py makemigrations --check --noinput
# Create cache table.
- python manage.py createcachetable
# Run back-end tests
- coverage run manage.py test
- coverage report
coverage: '/TOTAL.*\s+(\d+%)$/'
test_js:
image: node:16
stage: test
dependencies:
- static
script:
# Run front-end tests
- npm run test:coverage
.heroku_deployment_template: &heroku_deployment_template
stage: deploy_site
script:
- 'echo "Deploying to Heroku. To see progress, go to: https://dashboard.heroku.com/apps/$HEROKU_APP/activity"'
- curl -sf -X POST -m 900 https://heroku-deploy.torchbox.com/$HEROKU_APP/$CI_COMMIT_SHA?key=$DEPLOYMENT_KEY
# Deploy to the staging server.
deploy_staging:
variables:
# Your app's name.
# $ heroku apps -t torchbox
HEROKU_APP: tnaomegauiprototypes-staging
only:
- staging
environment:
name: staging
# Update with the correct staging URL
url: https://tnaomegauiprototypes.staging.torchbox.com
<<: *heroku_deployment_template
# Deploy to the production site.
deploy_production:
variables:
# Your app's name.
# $ heroku apps -t torchbox
HEROKU_APP: tnaomegauiprototypes-production
only:
- master
when: manual
environment:
name: production
# Update with the correct production URL
url: https://tnaomegauiprototypes.production.torchbox.com
<<: *heroku_deployment_template
pages:
# Make sure the python image version here matches the poetry job
image: python:3.8
stage: pages
only:
refs:
- master
changes:
- public/**/*
dependencies:
- poetry
before_script:
- . .venv/bin/activate
script:
- mkdocs build
- mv site/* public
artifacts:
paths:
- public