-
Notifications
You must be signed in to change notification settings - Fork 20
129 lines (113 loc) · 4.79 KB
/
tests.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
name: Run Tests
on:
- pull_request
- push
- workflow_call
jobs:
test:
runs-on: ubuntu-latest
# #no-ci in the commit log flags commit we don't want CI-validated
if: ${{ !contains(github.event.head_commit.message, '#no-ci') }}
steps:
- uses: actions/checkout@v4
- uses: FedericoCarboni/setup-ffmpeg@v2
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.8"
cache: "pip"
- name: Install Python dependencies
run: |
# Keep pip up to date
python -m pip install --upgrade pip
# Some dependencies are built using wheel
pip install wheel
# Install all Python dependencies in just one pip call, including Studio itself
pip install -r requirements.txt \
-r requirements.dev.txt \
-r requirements.ci.txt \
-e .
- name: Run tests
run: |
cd test
coverage run --parallel-mode run.py prod
DEVELOPMENT=1 coverage run --parallel-mode test_web_api.py
coverage combine
coverage xml
- name: Exercise the Heroku Procfile
run: |
cmd=$(grep web: Procfile | cut -d' ' -f2-)
echo "Running $cmd"
$cmd &
curl --retry 20 --retry-delay 1 --retry-all-errors http://127.0.0.1:8000/api/v1/docs | grep SwaggerUIBundle
curl http://127.0.0.1:8000/api/v1/langs | grep Cree
kill %1
- name: Nitpicking
run: |
# coding style: we want black compliance
find . -name \*.py | xargs black --check
# Legal check: make sure we don't have or introduce GPL dependencies
if pip-licenses | grep -v 'Artistic License' | grep -v LGPL | grep GNU; then echo 'Please avoid introducing *GPL dependencies'; false; fi
- uses: codecov/codecov-action@v4
with:
directory: ./test
token: ${{ secrets.CODECOV_TOKEN }} # optional but apparently makes upload more reliable
fail_ci_if_error: false # too many upload errors to keep "true"
- name: Make sure the CLI stays fast
id: cli-load-time
run: |
PYTHONPROFILEIMPORTTIME=1 readalongs -h 2> importtime.txt > /dev/null
CLI_LOAD_TIME="$((/usr/bin/time --format=%E readalongs -h > /dev/null) 2>&1)"
echo "CLI load time: $CLI_LOAD_TIME" > import-message.txt
PR_HEAD="${{ github.event.pull_request.head.sha }}"
[[ $PR_HEAD ]] && echo "Pull Request HEAD: $PR_HEAD" >> import-message.txt
echo "Imports that take more than 0.1 s:" >> import-message.txt
grep -E 'cumulative|[0-9]{6} ' importtime.txt >> import-message.txt
cat import-message.txt
echo "Full import time log:"
cat importtime.txt
if [[ "$CLI_LOAD_TIME" > "0:01.00" ]]; then \
echo "ERROR: readalongs --help is too slow."; \
echo "Please run 'PYTHONPROFILEIMPORTTIME=1 readalongs -h 2> importtime.txt; tuna importtime.txt' and tuck away expensive imports so that the CLI doesn't load them until it uses them."; \
false; \
fi
- name: Report help speed in a PR comment
if: github.event_name == 'pull_request'
continue-on-error: true
uses: mshick/add-pr-comment@v2
with:
preformatted: true
message-path: import-message.txt
test-on-windows:
runs-on: windows-latest
if: ${{ !contains(github.event.head_commit.message, '#no-ci') }}
steps:
- uses: actions/checkout@v4
- uses: FedericoCarboni/setup-ffmpeg@v2
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.8"
cache: "pip"
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install wheel
pip install -r requirements.txt `
-r requirements.dev.txt `
-r requirements.ci.txt `
-e .
- name: Run tests on Windows
run: cd test && python run.py prod
- name: Make sure the CLI outputs utf8 on Windows
# Note: we're checking something CLI specific, from a prompt, so we don't want to run
# in from a testing harness or framework, we want direct CLI.
# This test will fail if the output encoding is cp1252
# Warning: the diff line below is PowerShell syntax, not bash!
run: |
echo ćś | readalongs make-xml -l fra - - | findstr /v meta > cs.readalong
echo Output ====
cat cs.readalong
echo Reference ====
cat test/data/cs-ref.readalong
if (diff (cat cs.readalong) (cat test/data/cs-ref.readalong)) { throw "Output did not match reference" }