-
Notifications
You must be signed in to change notification settings - Fork 47
378 lines (309 loc) · 11.3 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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
name: ci
on:
push:
# A branch github-ci can be created and used for ci
# experiments and tweaks.
branches: [ "develop", "master", "github-ci", "windows" ]
pull_request:
branches: [ "develop", "master" ]
permissions:
contents: read
jobs:
# Run all tests.
base-ci:
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
matrix:
python_version: [ '3.8', '3.9', '3.10', '3.11', '3.12', '3.13' ]
steps:
- name: Install Dependencies
run: |
sudo apt-get update -y
sudo apt-get install -y mecab mecab-ipadic-utf8
# Helper checks to find the mecab library path,
# so it can be exported before running tests.
# Without the export, natto-py fails on github.
# echo FIND THE LIB:
# which mecab
# actual=`readlink -f /usr/bin/mecab`
# ldd $actual
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python_version }}
cache: 'pip' # caching pip dependencies
- name: Install packages using flit
run: |
pip install flit
# --only-deps: Installs only the dependencies, not Lute itself
# --deps develop: both regular and optional dependencies.
flit install --only-deps --deps develop
- name: Setup config
run: |
mkdir ${{ github.workspace }}/data
echo "ENV: dev" > ${{ github.workspace }}/lute/config/config.yml
echo "DATAPATH: ${{ github.workspace }}/data" >> ${{ github.workspace }}/lute/config/config.yml
echo "DBNAME: test_lute.db" >> ${{ github.workspace }}/lute/config/config.yml
ls ${{ github.workspace }}
cat ${{ github.workspace }}/lute/config/config.yml
- name: Test
run: |
set -e
# Have to explicitly set MECAB_PATH for natto-py.
export MECAB_PATH=/lib/x86_64-linux-gnu/libmecab.so.2
pytest
# Skipping acceptance tests for 3.8, just to save some time.
- name: Acceptance testing
if: matrix.python_version != '3.8'
uses: nick-fields/retry@v3
with:
max_attempts: 3
timeout_minutes: 30
command: |
# handle errors manually, so that the retry works.
exit_code=0
# Have to explicitly set MECAB_PATH for natto-py.
export MECAB_PATH=/lib/x86_64-linux-gnu/libmecab.so.2
inv accept --show --verbose || exit_code=$?
if [ "$exit_code" -ne 0 ]; then
echo "Command failed with exit code $exit_code, retrying..."
fi
exit $exit_code
# Playwright tests were hanging far too often on github ci,
# but not consistently. No idea what was going wrong.
# TODO github ci: fix playwright hanging.
- name: Playwright install
run: playwright install
- name: Playwright smoke test
run: |
set -x
set -e
inv playwright
- name: Check flit package
run: |
mkdir ${{ github.workspace }}/../lute_flit
cd ${{ github.workspace }}/../lute_flit
flit -f ${{ github.workspace }}/pyproject.toml install
python -m lute.main & # Start in background process
sleep 10
# Verify with utils script back in the workspace
# (verify.py is not included in flit install)
pushd ${{ github.workspace }}
python -m utils.verify 5001
popd
pkill -f "python -m lute.main" # Kill that process.
# Lute should still work if the user doesn't have mecab installed.
no-mecab-check:
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
matrix:
# Only checking early and late versions.
python_version: [ '3.8', '3.11' ]
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python_version }}
cache: 'pip' # caching pip dependencies
- name: Install packages using flit
run: |
pip install flit
flit install --only-deps --deps develop
- name: Setup config
run: |
mkdir ${{ github.workspace }}/data
echo "ENV: dev" > ${{ github.workspace }}/lute/config/config.yml
echo "DATAPATH: ${{ github.workspace }}/data" >> ${{ github.workspace }}/lute/config/config.yml
echo "DBNAME: test_lute.db" >> ${{ github.workspace }}/lute/config/config.yml
ls ${{ github.workspace }}
cat ${{ github.workspace }}/lute/config/config.yml
# Run one particular sanity check.
#
# Note this isn't _completely_ valid because the test loads
# only supported language stories, whereas a prod release
# comes with _all_ stories pre-loaded and the invalid ones
# are deleted ...
- name: Smoke test no mecab
run: inv accept -s -k disabled_data_is_hidden
# Run all plugin tests.
#
# For each plugin:
# - install Lute requirements
# - install plugin reqs
# - run tests.
#
# The Lute requirements are installed first b/c the plugins may come
# with their own conflicting requirements. Doing a full req install
# will (hopefully) uncover conflicts.
plugins:
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
matrix:
python_version: [ '3.8', '3.9', '3.10', '3.11' ]
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python_version }}
cache: 'pip' # caching pip dependencies
# Plugins likely won't need this config file, but just in case ...
- name: Setup config
run: |
mkdir ${{ github.workspace }}/data
echo "ENV: dev" > ${{ github.workspace }}/lute/config/config.yml
echo "DATAPATH: ${{ github.workspace }}/data" >> ${{ github.workspace }}/lute/config/config.yml
echo "DBNAME: test_lute.db" >> ${{ github.workspace }}/lute/config/config.yml
ls ${{ github.workspace }}
cat ${{ github.workspace }}/lute/config/config.yml
- name: test all plugins
run: |
# Lute reqs, such as pytest.
# This also installs Lute itself,
# so that it can be found
# by each plugin's own "pip install ."
pip install flit
flit install --deps develop
for plugin in $(ls plugins); do
pushd plugins/$plugin
pip install .
# Note for future: some plugins may have extra reqs not covered by pip
# (e.g. mecab uses apt-get and exports etc). Idea for future: plugin
# could have a .github folder as well with additional setup scripts.
pytest tests
# pip uninstall $plugin -y
# NOTE: Not bothering to do an uninstall!
# if multiple plugins have different/clashing version requirements,
# perhaps it is best to run into problems in ci.
# This may ultimately come back to haunt me, but it will do for now.
popd
done
code-quality:
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
matrix:
python_version: [ '3.11' ]
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python_version }}
cache: 'pip' # caching pip dependencies
- run: |
pip install flit
flit install --only-deps --deps develop
- name: Lint
run: inv lint
- name: Coding style
run: |
black --check .
# Test build docker container and try running.
# Slightly wasteful re-setup of node.
docker-build:
runs-on: ubuntu-latest
timeout-minutes: 30
needs: base-ci
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/setup-python@v4
with:
python-version: 3.11
cache: 'pip' # caching pip dependencies
- run: |
pip install flit
flit install --only-deps --deps develop
- name: Test docker build
run: |
docker build -f docker/Dockerfile --build-arg INSTALL_EVERYTHING=false -t lute3 .
# Run container in the background, and check.
docker run -d -p 5001:5001 -v ./my_data:/lute_data -v ./my_backups:/lute_backup --name my-lute lute3:latest
sleep 10 # Give it a moment to start.
python -m utils.verify 5001
docker stop my-lute
docker rm my-lute
# Ensure that basic things work correctly on Windows,
# particularly PlatformDirs package.
windows-ci:
runs-on: windows-latest
timeout-minutes: 30
strategy:
matrix:
python_version: [ '3.8', '3.9', '3.10', '3.11' ]
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python_version }}
cache: 'pip' # caching pip dependencies
- name: Setup config
run: |
mkdir ${{ github.workspace }}\data
echo ENV: dev > ${{ github.workspace }}\lute\config\config.yml
echo DATAPATH: ${{ github.workspace }}\data >> ${{ github.workspace }}\lute\config\config.yml
echo DBNAME: test_lute.db >> ${{ github.workspace }}\lute\config\config.yml
shell: cmd
- name: Replace config slashes.
run: |
$content = [System.IO.File]::ReadAllText("${{ github.workspace }}\lute\config\config.yml").Replace('\','/')
[System.IO.File]::WriteAllText("${{ github.workspace }}\lute\config\config.yml", $content)
Get-Content -Path "${{ github.workspace }}\lute\config\config.yml"
- run: |
pip install flit
flit install --only-deps --deps develop
# Can't get playwright to run reliably on Windows.
# - name: Playwright install
# run: playwright install
# - name: Playwright smoke test
# run: inv playwright || exit /b
# Now having problems with tests not working on windows ...
# getting failure message:
# javascript error: clear_datatable_state is not defined
#
# The above message is called from lute_test_client to clear book
# datatables state. This _used_ to work (e.g. in v3.3.0), and
# I can't track it down at the moment!!!!!!
#
# TODO ci: RESTORE AT LEAST ONE SANITY CHECK TEST ON WINDOWS.
#
# Run specific sanity check.
# Old tests no longer run -- datatables may have timing issues on Windows tests,
# tests were far too flaky.
# inv accept -s -k test_unsupported_language_not_shown || exit /b
# inv accept -s -k import_a_valid_term_file || exit /b
# - name: Smoke tests
# run: |
# inv accept -s -k test_updating_term_status_updates_the_reading_frame || exit /b
- name: Remove config to force using prod config
run: del ${{ github.workspace }}\lute\config\config.yml
shell: cmd
- name: Install prod-like flit package
run: |
mkdir ${{ github.workspace }}\..\lute_flit
cd ${{ github.workspace }}\..\lute_flit
flit -f ${{ github.workspace }}\pyproject.toml install
shell: cmd
- name: Run Lute application
run: |
echo "python -m lute.main" > run-server.bat
cmd /c "START /b run-server.bat"
- name: Wait for application to start
run: Start-Sleep -Seconds 10
- name: Verify flit install
run: |
cd ${{ github.workspace }}
python -m utils.verify 5001