fix(tests): do not let tests leave files around #1055
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Run Tests | |
| on: | |
| - pull_request | |
| - push | |
| - workflow_call | |
| - workflow_dispatch | |
| 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') }} | |
| permissions: | |
| pull-requests: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: FedericoCarboni/setup-ffmpeg@v2 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.9" | |
| cache: "pip" | |
| - name: Install Python dependencies | |
| run: | | |
| # Keep pip up to date | |
| python -m pip install --upgrade pip | |
| # Install all Python dependencies in just one pip call, including Studio itself | |
| pip install -e .[all] | |
| - name: Run tests | |
| run: | | |
| coverage run --parallel-mode run_tests.py prod | |
| DEVELOPMENT=1 coverage run --parallel-mode -m tests.test_web_api | |
| coverage combine | |
| coverage xml | |
| - run: coverage report | |
| - name: Make sure pre-commit hooks pass | |
| uses: pre-commit/[email protected] | |
| - name: Automated license checking | |
| # Make sure we don't have or introduce dependencies with incompatible licenses. | |
| # Exclusions where auto detection and analysis do not work: | |
| # - pympi-ling is MIT, but not auto-detected. https://github.com/dopefishh/pympi | |
| # - text-unidecode is Artistic License or GPL (at our choice): MIT is | |
| # compatible with the former. https://github.com/kmike/text-unidecode/ | |
| # - setuptools is MIT, but not always auto-detected. | |
| run: licensecheck --requirements-path pyproject.toml --zero --ignore-packages pympi-ling text-unidecode setuptools | |
| - uses: codecov/codecov-action@v4 | |
| with: | |
| directory: ./tests | |
| 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 | |
| if grep -q -E '[0-9]{6} ' importtime.txt; then \ | |
| echo "Imports that take more than 0.1 s:" >> import-message.txt; \ | |
| grep -E 'cumulative|[0-9]{6} ' importtime.txt >> import-message.txt; \ | |
| else \ | |
| echo "No imports take more than 0.1 s." >> import-message.txt; \ | |
| fi | |
| 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.9" | |
| cache: "pip" | |
| - name: Install Python dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -e .[all] | |
| - name: Run tests on Windows | |
| run: python run_tests.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 tests/data/cs-ref.readalong | |
| if (diff (cat cs.readalong) (cat tests/data/cs-ref.readalong)) { throw "Output did not match reference" } | |
| test-heroku-env: | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Read the Heroku run time env and cmd | |
| run: | | |
| echo "PYTHON_VERSION=$(cat .python-version)" >> $GITHUB_ENV | |
| echo "RUNTIME_CMD=$(cat Procfile | grep web: | sed 's/web: *//')" >> $GITHUB_ENV | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "${{ env.PYTHON_VERSION }}" | |
| cache: "pip" | |
| - name: Install Python dependencies the way Heroku would | |
| run: | | |
| pip install -r requirements.txt | |
| bin/post_compile | |
| - name: Launch the API via the Heroku Procfile | |
| run: | | |
| ${{ env.RUNTIME_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: Install test dependency | |
| run: pip install httpx | |
| - name: unit test the web API | |
| run: python -m tests.test_web_api |