-
Notifications
You must be signed in to change notification settings - Fork 161
305 lines (249 loc) · 9.01 KB
/
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
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
name: CI
on:
push:
pull_request:
schedule:
- cron: "30 3 * * WED" # every Wednesday at 3:30 AM, only main branch
env:
NODE_VERSION: "16" # needs to be also updated in .nvmrc
PYTHON_VERSION: "3.7"
MARIADB_VERSION: "10.4.10"
COVERALLS_VERSION: "3.3.1" # check if Coverage needs to be also updated in requirements-ci.txt
GECKODRIVER_VERSION: "0.33.0"
# As GitHub Action does not allow environment variables
# to be used in services definitions, these are only for
# reference. If you update these versions, you HAVE TO
# update the versions in the services definitions of the
# test job.
ELASTICSEARCH_VERSION: "5.5.2"
MEMCACHED_VERSION: "1.6"
jobs:
# Lint all source files by executing pre-commit hooks.
lint:
name: Lint
runs-on: ubuntu-22.04
# do not execute scheduled jobs on forks:
if: ${{ github.event_name != 'schedule' || github.repository_owner == 'zestedesavoir' }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v4
with:
python-version: "${{ env.PYTHON_VERSION }}"
- name: Execute pre-commit
uses: pre-commit/action@v3.0.0
# Build the documentation and upload it as an artifact.
build-doc:
name: Build Sphinx documentation
runs-on: ubuntu-22.04
# do not execute scheduled jobs on forks:
if: ${{ github.event_name != 'schedule' || github.repository_owner == 'zestedesavoir' }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v4
with:
python-version: "${{ env.PYTHON_VERSION }}"
- name: Upgrade pip
run: pip install --upgrade pip
- name: Retrieve pip cache directory
id: pip-cache
run: echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
- name: Cache pip packages
uses: actions/cache@v3
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ runner.os }}-pip-${{ hashFiles('requirements-dev.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install python dependencies
run: pip install -r requirements-dev.txt
- name: Build documentation
run: make generate-doc
- name: Upload documentation as a page artifact
uses: actions/upload-pages-artifact@v1
with:
path: doc/build/html
# Build the website front-end and upload built assets as an artifact.
build-front:
name: Lint and build front-end
runs-on: ubuntu-22.04
# do not execute scheduled jobs on forks:
if: ${{ github.event_name != 'schedule' || github.repository_owner == 'zestedesavoir' }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up NodeJS ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
with:
node-version: "${{ env.NODE_VERSION }}"
- name: Retrieve yarn cache directory
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
- name: Cache Node modules
uses: actions/cache@v3
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install front-end
run: make install-front
- name: Lint front-end
run: make lint-front
- name: Build front-end
run: make build-front
- name: Upload font-end assets for subsequent tests
uses: actions/upload-artifact@v3
with:
name: assets
path: dist
retention-days: 1
# Test the zds-site project.
# Install the project, using assets created during the previous job,
# and install elasticsearch & memcache as a service. Then, run the tests
# in a matrix build to parallelize multiple components.
test:
name: Install and test zds-site
needs: build-front
runs-on: ubuntu-22.04
strategy:
matrix:
module:
[
"zds.tutorialv2",
"zds.member zds.gallery zds.searchv2 zds.middlewares zds.pages",
"zds.forum zds.featured zds.mp zds.notification zds.utils",
]
services:
elasticsearch:
image: "elasticsearch:5.5.2"
ports:
- "9200:9200"
env:
"http.host": "0.0.0.0"
"transport.host": "127.0.0.1"
"xpack.security.enabled": false
"ES_JAVA_OPTS": "-Xms512m -Xmx512m"
options: >-
-e="discovery.type=single-node"
--health-cmd="curl http://localhost:9200/_cluster/health"
--health-interval=10s
--health-timeout=5s
--health-retries=10
memcached:
image: "memcached:1.6"
ports:
- "11211:11211"
steps:
- name: Shutdown Ubuntu MySQL
run: sudo service mysql stop
- name: Set up MariaDB ${{ env.MARIADB_VERSION }}
uses: getong/mariadb-action@v1.1
with:
character set server: "utf8mb4"
collation server: "utf8mb4_unicode_ci"
mariadb version: "${{ env.MARIADB_VERSION }}"
mysql database: "ci_db_name"
mysql root password: "ci_root_password"
- name: Install Firefox
run: sudo apt-get update && sudo apt-get install firefox
- name: Install Geckodriver
run: |
wget https://github.com/mozilla/geckodriver/releases/download/v${{ env.GECKODRIVER_VERSION }}/geckodriver-v${{ env.GECKODRIVER_VERSION }}-linux64.tar.gz
mkdir geckodriver
tar -xzf geckodriver-v${{ env.GECKODRIVER_VERSION }}-linux64.tar.gz -C geckodriver
- name: Checkout
uses: actions/checkout@v3
- name: Download previously built assets
uses: actions/download-artifact@v3
with:
name: assets
path: dist
- name: Upgrade pip
run: |
pip install --upgrade pip
- name: Retrieve pip cache directory
id: pip-cache
run: echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
- name: Cache pip packages
uses: actions/cache@v3
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ runner.os }}-pip-${{ hashFiles('requirements*.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Cache Node modules
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('zmd/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v4
with:
python-version: "${{ env.PYTHON_VERSION }}"
- name: Set up NodeJS ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
with:
node-version: "${{ env.NODE_VERSION }}"
- name: Install Python dependencies
run: pip install -r requirements-ci.txt
- name: Check that no migration is missing
run: python manage.py makemigrations --check --dry-run
- name: Build and start zmarkdown
run: |
make zmd-install
make zmd-start
- name: Run tests for ${{ matrix.module }}
run: |
export PATH="$PATH:$PWD/geckodriver"
coverage run --source='.' manage.py test -v=2 --keepdb --settings zds.settings.ci_test ${{ matrix.module }}
- name: Analyze coverage
shell: bash -l {0}
run: |
echo $COVERALLS_FLAG_NAME
python -m pip install coveralls==${{ env.COVERALLS_VERSION }}
coveralls --service=github # See https://github.com/TheKevJames/coveralls-python/issues/252
env:
GITHUB_TOKEN: ${{ secrets.github_token }}
COVERALLS_PARALLEL: true
COVERALLS_FLAG_NAME: "${{ matrix.module }}"
# Push coverage data to Coveralls.
coverage:
name: Push coverage to Coveralls
needs: test
runs-on: ubuntu-22.04
steps:
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v4
with:
python-version: "${{ env.PYTHON_VERSION }}"
- name: Upload coverage data
run: |
python -m pip install coveralls==${{ env.COVERALLS_VERSION }}
coveralls --finish --service=github # See https://github.com/TheKevJames/coveralls-python/issues/252
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# If we're on the dev branch (i.e. for merged pull requests), push the built
# documentation to the gh-page branch.
push_doc:
name: Push documentation to GitHub Pages
needs: ["build-doc", "test"]
runs-on: ubuntu-22.04
if: "github.ref == 'refs/heads/dev'"
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
permissions:
contents: read
pages: write
id-token: write
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2