-
Notifications
You must be signed in to change notification settings - Fork 27
137 lines (132 loc) · 5.86 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
130
131
132
133
134
135
136
137
name: Run all tests
on:
- pull_request
- push
- workflow_call
# Since we don't checkout the full history, we use a default version so certain tests
# (pep440, update_schema) will still function. The fake version is set in file
# .SETUPTOOLS_SCM_PRETEND_VERSION
env:
G2P_STUDIO_DEBUG: 1
jobs:
test-all-on-linux:
# This is our main test job, exercising everything and uploading to coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.8"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
SETUPTOOLS_SCM_PRETEND_VERSION=`cat .SETUPTOOLS_SCM_PRETEND_VERSION` pip install -e .[test]
pip install pip-licenses
if pip-licenses | grep -v 'Artistic License' | grep -v LGPL | grep GNU; then echo 'Please avoid introducing *GPL dependencies'; false; fi
pip install coverage
- name: Ensure browser is installed
run: python -m playwright install --with-deps chromium
- name: Launch the API
run: coverage run run_studio.py &
- name: Run dev suite
run: coverage run run_tests.py dev
- name: Run test-studio
run: coverage run g2p/tests/test_studio.py
- name: Run generate-mapping
shell: bash
run: |
coverage run $(which g2p) generate-mapping --from crg --to eng
git status --porcelain=v1 | grep 'M g2p/mappings/langs/generated/config-g2p.yaml' || { echo 'g2p generate-mapping did not update generated/config-g2p.yaml as expected'; false; }
- name: Post test analyses
run: |
pkill -INT coverage
sleep 10
coverage combine
coverage report
coverage xml
if git status | grep -E 'static.*json|mapping.*pkl|mapping.*.json.gz'; then echo 'g2p databases out of date, please run "g2p update" and commit the results.'; false; else echo OK; fi
- name: Upload coverage information
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
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 g2p -h 2> importtime.txt > /dev/null
CLI_LOAD_TIME="$((/usr/bin/time --format=%E g2p -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: g2p --help is too slow."; \
echo "Please run 'PYTHONPROFILEIMPORTTIME=1 g2p -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:
# Make sure stuff stays compatible with Windows by testing there too.
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
# Note: this is where we also test that the g2p library still works on 3.7
python-version: "3.7"
- name: Install dependencies
shell: bash
run: |
python -m pip install --upgrade pip
SETUPTOOLS_SCM_PRETEND_VERSION=`cat .SETUPTOOLS_SCM_PRETEND_VERSION` pip install -e .[test]
- name: Run tests on Windows
run: python run_tests.py dev
- name: Make sure the CLI outputs utf8 on Windows
run: |
# Warning: This is PowerShell syntax, not bash!
g2p convert est fra fra-ipa > out
if (diff (echo ɛ) (cat out)) { throw "Output did not match reference" }
test-heroku-env:
# Replicate what heroku will run
runs-on: ubuntu-22.04 # https://devcenter.heroku.com/articles/heroku-22-stack
steps:
- uses: actions/checkout@v4
- name: Read the Heroku run time env and cmd
run: |
echo "PYTHON_VERSION=$(cat runtime.txt | sed 's/python-//')" >> $GITHUB_ENV
echo "RUNTIME_CMD=$(cat Procfile | sed 's/web: *//')" >> $GITHUB_ENV
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- run: python -m pip install --upgrade pip
- name: Start with requirements.txt
# This is for optimization purposes, so that .[test] below doesn't install wrong
# versions just to have them replaced by requirements.txt in the next step.
run: pip install -r requirements.txt
- name: Install all test dependencies
run: |
SETUPTOOLS_SCM_PRETEND_VERSION=`cat .SETUPTOOLS_SCM_PRETEND_VERSION` pip install -e .[test]
python -m playwright install --with-deps chromium
- name: Overwrite dependencies and g2p, the Heroku way, to replicate the production env
run: |
# Possibly redundant, but make sure .[test] did not override anything
pip install -r requirements.txt
bin/post_compile
- name: Launch the API
run: ${{ env.RUNTIME_CMD }} --bind localhost:5000 &
- name: Run the regular dev suite
run: python run_tests.py dev
- name: Run test-studio
run: python g2p/tests/test_studio.py