Files
romm/.github/workflows/pytest.yml
renovate[bot] 146a23089a chore(deps): update postgres docker tag to v19 (#5742)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2026-11-22 19:32:36 -06:00

149 lines
5.4 KiB
YAML

name: Run Pytest
on:
pull_request:
paths:
- "backend/**"
- ".github/workflows/pytest.yml"
- pyproject.toml
- uv.lock
- .python-version
- Dockerfile
- docker/Dockerfile
push:
branches:
- "master"
paths:
- "backend/**"
- ".github/workflows/pytest.yml"
- pyproject.toml
- uv.lock
- .python-version
- Dockerfile
- docker/Dockerfile
# A new push cancels a PR's superseded run; each master commit keeps its own.
concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.event.pull_request.number || github.sha }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
permissions:
contents: read
jobs:
pytest:
runs-on: ubuntu-24.04
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
db: [mariadb, postgresql]
services:
mariadb:
image: mariadb:13.0.2
ports:
- 3306
env:
MYSQL_USER: romm_test
MYSQL_PASSWORD: passwd
MYSQL_DATABASE: romm_test
MYSQL_ROOT_PASSWORD: passwd
options: --health-cmd="healthcheck.sh --connect --innodb_initialized" --health-interval=5s --health-timeout=2s --health-retries=3 --health-start-period=30s
postgresql:
image: postgres:19
ports:
- 5432
env:
POSTGRES_USER: romm_test
POSTGRES_PASSWORD: passwd
POSTGRES_DB: romm_test
options: --health-cmd="pg_isready" --health-interval=5s --health-timeout=2s --health-retries=3
valkey:
image: valkey/valkey:9.0.8
ports:
- 6379
options: >-
--health-cmd="redis-cli ping" --health-interval=5s --health-timeout=2s --health-retries=3
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Set up the backend
uses: ./.github/actions/setup-backend
with:
sync-args: --extra test
apt-packages: 7zip
# The ROM patcher tests run the real patcher.js, which needs RomPatcher.js.
- name: Set up Node.js
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version-file: frontend/.nvmrc
- name: Install the ROM patcher dependencies
working-directory: backend/utils/rom_patcher
run: npm ci --ignore-scripts --no-audit --no-fund
- name: Initiate MariaDB database
if: matrix.db == 'mariadb'
env:
MARIADB_PORT: ${{ job.services.mariadb.ports['3306'] }}
run: |
# Grant on the `romm_test%` namespace so the test user can create the
# per-worker databases (romm_test_gw0, ...) used under pytest-xdist,
# without granting it global privileges. The backticks are escaped so
# the shell doesn't treat them as command substitution.
mysql --host 127.0.0.1 --port "$MARIADB_PORT" -uroot -ppasswd -e "GRANT ALL PRIVILEGES ON \`romm\_test%\`.* TO 'romm_test'@'%' WITH GRANT OPTION; FLUSH PRIVILEGES;"
- name: Run python tests
env:
DB_HOST: 127.0.0.1
DB_PORT: ${{ matrix.db == 'mariadb' && job.services.mariadb.ports['3306'] || job.services.postgresql.ports['5432'] }}
ROMM_DB_DRIVER: ${{ matrix.db }}
REDIS_HOST: 127.0.0.1
REDIS_PORT: ${{ job.services.valkey.ports['6379'] }}
HYPOTHESIS_PROFILE: ci
run: |
cd backend
# GitHub-hosted Linux runners have 4 vCPUs; run one worker per core.
# --cov=.. makes report paths repo-relative (backend/...), as code coverage expects.
uv run pytest -n 4 -vv --maxfail=10 --junitxml=pytest-report.xml --cov=.. --cov-report xml:coverage.xml --cov-config=.coveragerc .
# Both legs cover the same code, so one report is enough. Fork PRs can't upload.
- name: Upload coverage report artifact
if: matrix.db == 'mariadb' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: coverage-report
path: backend/coverage.xml
if-no-files-found: error
retention-days: 1
# A separate job keeps code-quality: write away from the job that runs the PR's code.
upload-coverage:
needs: pytest
if: ${{ !cancelled() && needs.pytest.result == 'success' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) }}
runs-on: ubuntu-24.04
timeout-minutes: 10
permissions:
contents: read
# actionlint doesn't know the code-quality scope yet.
# trunk-ignore(actionlint)
code-quality: write
steps:
- name: Download coverage report
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: coverage-report
# Best-effort while GitHub code coverage is in preview; errors still show as annotations.
- name: Upload coverage to GitHub
uses: actions/upload-code-coverage@2b21a77928be8d5168c2b9581a67f2adbebacc52 # v1.4.4
with:
file: coverage.xml
language: Python
label: code-coverage/pytest
fail-on-error: false