Skip to content

ci: change cron job to run on Monday at 9:24am UTC #2091

ci: change cron job to run on Monday at 9:24am UTC

ci: change cron job to run on Monday at 9:24am UTC #2091

Workflow file for this run

name: Run all tests
on:
pull_request:
push:
workflow_call:
schedule:
# Every Monday morning so the weekly caches are refreshed and we exercise
# the effect of newly published versions of our dependencies.
# Minute 24 so it's not on the hour, and thus hopefully a less busy time at GHA
# and we don't get delayed as much, but this can still get delayed by hours.
# 24:minute 9:9am-UTC *:any-day-of-month *:any-month 1:Monday
- cron: '24 9 * * 1'
# 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
UV_SYSTEM_PYTHON: 1
permissions:
contents: read
jobs:
test-all-on-linux:
# This is our main test job, exercising everything and uploading to coverage
runs-on: ubuntu-latest
permissions:
pull-requests: write # for add-pr-comment
steps:
- uses: actions/checkout@v5
with:
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.9"
- uses: astral-sh/setup-uv@v7
with:
enable-cache: true
- name: Install dependencies
run: |
SETUPTOOLS_SCM_PRETEND_VERSION=$(cat .SETUPTOOLS_SCM_PRETEND_VERSION) uv pip install -e .[test] licensecheck
- run: uv pip list
- run: uv pip freeze
- name: Check licenses
# Automatically check that we don't introduce imcompatibly licensed dependencies
# text-unidecode is OK (Artistic License) but not detected automatically
# setuptools is OK (MIT License) but intermittently not detected automatically
run: licensecheck --zero --ignore-packages text-unidecode setuptools --requirements-paths pyproject.toml
- name: Get current week number
run: echo "WEEK_NUMBER=$(date -u +%Y-%V)" >> $GITHUB_OUTPUT
id: weekno
- name: Cache Playwright binaries
uses: actions/cache@v5
id: playwright-cache
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-ms-playwright-${{ steps.weekno.outputs.WEEK_NUMBER }}
- name: Ensure browser is installed
if: steps.playwright-cache.outputs.cache-hit != 'true'
run: python -m playwright install --with-deps chromium
- name: Run most tests
# This will skip neural test, not having installed .[neural] yet
# This will also skip updating schemas, having installed pydantic>=2.9
run: coverage run -m pytest
# Neural tests, with huggingface models cached
- uses: actions/cache@v5
with:
key: g2p-neural-${{ steps.weekno.outputs.WEEK_NUMBER }}
path: ~/.cache/huggingface
- run: uv pip install -e .[neural]
- name: Run the neural unit tests
run: |
coverage run g2p/tests/test_neural.py |& tee neural-test.log
! grep -i skip neural-test.log || ! echo "Error: neural test got skipped, something went wrong."
- 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: Make sure schemas are up to date, using pydantic<2.9
shell: bash
run: |
uv pip install 'pydantic<2.9'
coverage run -m unittest -v g2p.tests.test_cli.CliTest.test_update_schema_with_pydantic_lt29 |& tee schema-test.log
! grep -i skip schema-test.log || ! echo "Error: Schema update test got skipped, something went wrong."
- name: Post test analyses
run: |
coverage combine
coverage report
coverage xml
- name: Upload coverage information
uses: codecov/codecov-action@v5
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@7c1a3a3e5a072270dc21c0639df39ca11e860b2b # v3.5.0
with:
preformatted: true
message-path: import-message.txt
- name: Make sure g2p databases are up to date
# for static/*.json, a straight git status works
# for mappings/langs/*.json.gz, bit-for-bit-stable gzip is no longer possible since zlib-ng
# replaced zlib in Python 3.14 on Windows and will arrive sooner or later on all platforms.
# Ref: https://www.man.com/technology/faster-python
run: |
OUT_OF_DATE=
if git status | grep -E 'static.*json'; then OUT_OF_DATE=1; fi
if git status | grep 'mappings.*.json.gz'; then \
echo "*.json.gz diff=zcat" > .gitattributes; \
git config set diff.zcat.textconv zcat; \
if git diff | grep 'mappings.*.json.gz'; then OUT_OF_DATE=1; fi; \
fi
if [[ $OUT_OF_DATE ]]; then echo 'g2p databases out of date, please run "g2p update" and commit the results.'; false; else echo OK; fi
test-on-windows:
# Make sure stuff stays compatible with Windows by testing there too.
runs-on: windows-latest
steps:
- uses: actions/checkout@v5
with:
persist-credentials: false
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.9"
- uses: astral-sh/setup-uv@v7
with:
enable-cache: true
- name: Install dependencies
shell: bash
run: |
SETUPTOOLS_SCM_PRETEND_VERSION=`cat .SETUPTOOLS_SCM_PRETEND_VERSION` uv 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@v5
- 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@v6
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: Get current week number
run: echo "WEEK_NUMBER=$(date -u +%Y-%V)" >> $GITHUB_OUTPUT
id: weekno
- name: Install test dependencies
run: |
SETUPTOOLS_SCM_PRETEND_VERSION=`cat .SETUPTOOLS_SCM_PRETEND_VERSION` pip install -e .[test]
- name: Cache Playwright binaries
uses: actions/cache@v5
id: playwright-cache
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-ms-playwright-${{ steps.weekno.outputs.WEEK_NUMBER }}
- name: Ensure browser is installed
if: steps.playwright-cache.outputs.cache-hit != 'true'
run: 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 installing .[test] did not override anything
pip install -r requirements.txt
bin/post_compile
- name: Launch the API
run: ${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