Files
romm/.github/workflows/pytest.yml
Sam Dornan 12ed0b2d8c feat(soundtrack): extract CD audio from CHD images too
Most disc libraries are stored as CHD, which wraps the tracks in
compressed hunks. Extraction now reads them through libchdr (BSD-3), a
small decode-only library loaded with ctypes:

- The CHT2/CHTR track metadata gives each track's type, frames and
  whether its pregap is stored; tracks are padded to four frames, and
  audio comes back big-endian, so flac reads it with --endian=big.
- A lone CHD in the platform folder is promoted into a folder of its own
  first, as an upload would. A lone cue sheet still gets the 409, since
  moving it would leave its bins behind.
- A disc with a CHD but no libchdr gets a 503, like a missing flac.
- Reading and encoding now go through one AudioSource per track, so cue
  bins and CHDs share the encoder.

libchdr is built from a pinned commit in its own stage for the
production image and in the dev image (Ubuntu 22.04 doesn't package
it); the pytest workflow installs libchdr0 and mame-tools, whose chdman
builds the CHD fixtures. GD-ROM (Dreamcast) CHDs aren't read yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014XHgJG3xRgUKwuHJHwKkPg
2026-09-25 21:48:21 +00:00

106 lines
3.3 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
permissions:
contents: read
jobs:
pytest:
runs-on: ubuntu-latest
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:18
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.6
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: Install mariadb connectors
run: |
sudo apt-get update
sudo apt-get install -y libmariadb3 libmariadb-dev 7zip flac libchdr0 mame-tools
- name: Install uv
uses: astral-sh/setup-uv@c18668ad3cf93ea998bef934396af7bb5c839dc7 # v10.2.0
- name: Install python
run: |
uv python install
- name: Install dependencies
run: |
uv sync --frozen --extra test
- 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.
uv run pytest -n 4 -vv --maxfail=10 --junitxml=pytest-report.xml --cov --cov-report xml:coverage.xml --cov-config=.coveragerc .