evennia/.github/actions/run-tests/action.yml
2025-12-19 11:26:46 +01:00

126 lines
4.6 KiB
YAML

# evennia/run-tests
# Use this action to run the Evennia test suite after database setup.
# This action handles Python setup, dependency installation, evennia initialization,
# and test execution with optional coverage.
name: Run Evennia tests
description: "Sets up Python, installs dependencies, initializes Evennia, and runs the test suite."
inputs:
python-version:
description: "Python version to use for testing."
required: true
testing-db:
description: "Database type being tested (sqlite3, mysql, postgresql)."
required: true
coverage-test:
description: "Whether to run tests with coverage (true/false)."
required: false
default: "false"
needs-mysql-package:
description: "Whether to install mysqlclient package (true/false)."
required: false
default: "false"
needs-postgres-package:
description: "Whether to install psycopg2-binary package (true/false)."
required: false
default: "false"
coveralls-token:
description: "Coveralls repository token (optional, only needed for coverage tests)."
required: false
default: ""
runs:
using: "composite"
steps:
- name: Set up Python ${{ inputs.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python-version }}
cache: pip
cache-dependency-path: |
pyproject.toml
- name: Install package dependencies
run: |
python -m pip install --upgrade pip
pip install wheel
if [ "${{ inputs.needs-postgres-package }}" == "true" ]; then
pip install psycopg2-binary==2.9.5 # req by postgresql
fi
if [ "${{ inputs.needs-mysql-package }}" == "true" ]; then
pip install mysqlclient
fi
pip install coveralls
pip install tblib
pip install .
pip install .[extra]
shell: bash
- name: Initialize evennia
run: |
evennia --init testing_mygame
cp .github/workflows/${{ inputs.testing-db }}_settings.py testing_mygame/server/conf/settings.py
cd testing_mygame
shell: bash
- name: Verify MySQL settings before migrations
if: ${{ inputs.testing-db == 'mysql' }}
run: |
mysql -h 127.0.0.1 -u evennia -ppassword evennia -e "SELECT @@innodb_default_row_format as row_format, @@innodb_large_prefix as large_prefix;"
shell: bash
- name: Run migrations
working-directory: testing_mygame
run: |
evennia migrate
shell: bash
- name: Set MySQL table row format after migrations (safety check)
if: ${{ inputs.testing-db == 'mysql' }}
working-directory: testing_mygame
run: |
python -c "import os; import django; os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'server.conf.settings'); django.setup(); from django.db import connection; cursor = connection.cursor(); cursor.execute(\"SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE() AND ENGINE = 'InnoDB'\"); tables = [row[0] for row in cursor.fetchall()]; [cursor.execute(f'ALTER TABLE \`{table}\` ROW_FORMAT=DYNAMIC') or print(f'Set ROW_FORMAT=DYNAMIC for table {table}') for table in tables]"
shell: bash
- name: Collect static files
working-directory: testing_mygame
run: |
evennia collectstatic --noinput
shell: bash
# For non-coverage tests, run them in parallel.
- name: Run test suite
if: ${{ inputs.coverage-test != 'true' }}
working-directory: testing_mygame
run: |
evennia test --settings=settings --keepdb --timing evennia
shell: bash
# OBS - it's important to not run the coverage tests with --parallel, it messes up the coverage
# calculation!
- name: Run test suite with coverage
if: ${{ inputs.coverage-test == 'true' }}
working-directory: testing_mygame
run: |
coverage run --rcfile=../pyproject.toml ../bin/unix/evennia test --settings=settings --timing evennia
coverage combine
coverage xml
coverage --version
coverage report | grep TOTAL
shell: bash
# we only want to run coverall once, so we only do it for the designated matrix combination(s)
# it's also not critical if pushing to either service fails (happens for PRs since env is not
# available outside of the evennia org)
- name: Send data to Coveralls
if: ${{ inputs.coverage-test == 'true' && github.ref == 'refs/heads/main' && inputs.coveralls-token != '' }}
continue-on-error: true
env:
COVERALLS_REPO_TOKEN: ${{ inputs.coveralls-token }}
working-directory: testing_mygame
run: |
coveralls
shell: bash