Test refactor CI test workflow, re-adding postgres
This commit is contained in:
parent
0b92202ae6
commit
a652cbea61
4 changed files with 224 additions and 97 deletions
99
.github/actions/run-tests/action.yml
vendored
Normal file
99
.github/actions/run-tests/action.yml
vendored
Normal file
|
|
@ -0,0 +1,99 @@
|
||||||
|
# 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"
|
||||||
|
|
||||||
|
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
|
||||||
|
evennia migrate
|
||||||
|
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' }}
|
||||||
|
continue-on-error: true
|
||||||
|
env:
|
||||||
|
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
|
||||||
|
working-directory: testing_mygame
|
||||||
|
run: |
|
||||||
|
coveralls
|
||||||
|
shell: bash
|
||||||
52
.github/actions/setup-database/action.yml
vendored
52
.github/actions/setup-database/action.yml
vendored
|
|
@ -19,59 +19,39 @@ runs:
|
||||||
using: "composite"
|
using: "composite"
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Set up PostgreSQL server
|
- name: Wait for PostgreSQL to be ready
|
||||||
if: ${{ inputs.database == 'postgresql' }}
|
|
||||||
uses: harmon758/postgresql-action@v1
|
|
||||||
with:
|
|
||||||
postgresql version: "13"
|
|
||||||
postgresql db: "evennia"
|
|
||||||
postgresql user: "evennia"
|
|
||||||
postgresql password: "password"
|
|
||||||
|
|
||||||
- name: Wait for PostgreSQL to activate
|
|
||||||
if: ${{ inputs.database == 'postgresql' }}
|
if: ${{ inputs.database == 'postgresql' }}
|
||||||
run: |
|
run: |
|
||||||
while ! pg_isready -h 127.0.0.1 -q >/dev/null 2>&1
|
# Wait for PostgreSQL service container to be healthy
|
||||||
do
|
until pg_isready -h localhost -U evennia -d evennia; do
|
||||||
sleep 1
|
sleep 1
|
||||||
echo -n .
|
echo -n .
|
||||||
done
|
done
|
||||||
echo
|
echo "PostgreSQL is ready"
|
||||||
shell: bash
|
shell: bash
|
||||||
|
env:
|
||||||
|
PGPASSWORD: password
|
||||||
|
|
||||||
- name: Set up MySQL server
|
- name: Wait for MySQL to be ready
|
||||||
if: ${{ inputs.database == 'mysql' }}
|
|
||||||
uses: mirromutth/mysql-action@v1.1
|
|
||||||
with:
|
|
||||||
host port: 3306
|
|
||||||
# character set server: "utf8mb4"
|
|
||||||
# collation server: "utf8mb4_unicode_ci"
|
|
||||||
character set server: "utf8"
|
|
||||||
collation server: "utf8_general_ci"
|
|
||||||
mysql database: "evennia"
|
|
||||||
mysql user: "evennia"
|
|
||||||
mysql password: "password"
|
|
||||||
mysql root password: root_password
|
|
||||||
|
|
||||||
- name: Wait for MySQL to activate
|
|
||||||
if: ${{ inputs.database == 'mysql' }}
|
if: ${{ inputs.database == 'mysql' }}
|
||||||
run: |
|
run: |
|
||||||
while ! mysqladmin ping -h 127.0.0.1 -u root -proot_password -s >/dev/null 2>&1
|
# Wait for MySQL service container to be healthy
|
||||||
do
|
until mysqladmin ping -h 127.0.0.1 -u root -proot_password --silent; do
|
||||||
sleep 1
|
sleep 1
|
||||||
echo -n .
|
echo -n .
|
||||||
done
|
done
|
||||||
echo
|
echo "MySQL is ready"
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
- name: Set up MySQL Privileges
|
- name: Set up MySQL Privileges
|
||||||
if: ${{ inputs.database == 'mysql' }}
|
if: ${{ inputs.database == 'mysql' }}
|
||||||
run: |
|
run: |
|
||||||
cat <<EOF | mysql -u root -proot_password -h 127.0.0.1 mysql
|
# Ensure user exists and has proper privileges
|
||||||
create user 'evennia'@'%' identified by 'password';
|
mysql -u root -proot_password -h 127.0.0.1 mysql <<EOF
|
||||||
grant all on \`evennia%\`.* to 'evennia'@'%';
|
CREATE USER IF NOT EXISTS 'evennia'@'%' IDENTIFIED BY 'password';
|
||||||
grant process on *.* to 'evennia'@'%';
|
GRANT ALL PRIVILEGES ON \`evennia%\`.* TO 'evennia'@'%';
|
||||||
flush privileges
|
GRANT PROCESS ON *.* TO 'evennia'@'%';
|
||||||
|
FLUSH PRIVILEGES;
|
||||||
EOF
|
EOF
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
|
|
|
||||||
166
.github/workflows/github_action_test_suite.yml
vendored
166
.github/workflows/github_action_test_suite.yml
vendored
|
|
@ -12,98 +12,146 @@ on:
|
||||||
branches: [main, develop]
|
branches: [main, develop]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test-sqlite:
|
||||||
name: Test
|
name: Test (SQLite)
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
python-version: ["3.11", "3.12", "3.13"]
|
python-version: ["3.11", "3.12", "3.13"]
|
||||||
TESTING_DB: ["sqlite3", "mysql"]
|
|
||||||
include:
|
include:
|
||||||
- python-version: "3.11"
|
- python-version: "3.11"
|
||||||
TESTING_DB: "sqlite3"
|
|
||||||
coverage-test: true
|
coverage-test: true
|
||||||
|
|
||||||
timeout-minutes: 35
|
timeout-minutes: 35
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up database (sqlite3)
|
||||||
|
uses: ./.github/actions/setup-database
|
||||||
|
with:
|
||||||
|
database: sqlite3
|
||||||
|
timeout-minutes: 5
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
uses: ./.github/actions/run-tests
|
||||||
|
with:
|
||||||
|
python-version: ${{ matrix.python-version }}
|
||||||
|
testing-db: sqlite3
|
||||||
|
coverage-test: ${{ matrix.coverage-test == true && 'true' || 'false' }}
|
||||||
|
needs-postgres-package: "false"
|
||||||
|
needs-mysql-package: "false"
|
||||||
|
|
||||||
|
test-mysql:
|
||||||
|
name: Test (MySQL)
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
python-version: ["3.11", "3.12", "3.13"]
|
||||||
|
|
||||||
|
timeout-minutes: 35
|
||||||
|
|
||||||
|
services:
|
||||||
|
mysql:
|
||||||
|
image: mysql:8.0
|
||||||
env:
|
env:
|
||||||
UNIT_TEST_SETTINGS: "--settings=settings --keepdb --timing"
|
MYSQL_DATABASE: evennia
|
||||||
COVERAGE_TEST_SETTINGS: "--settings=settings --timing"
|
MYSQL_USER: evennia
|
||||||
|
MYSQL_PASSWORD: password
|
||||||
|
MYSQL_ROOT_PASSWORD: root_password
|
||||||
|
ports:
|
||||||
|
- 3306:3306
|
||||||
|
options: >-
|
||||||
|
--health-cmd="mysqladmin ping -h localhost"
|
||||||
|
--health-interval=10s
|
||||||
|
--health-timeout=5s
|
||||||
|
--health-retries=3
|
||||||
|
--character-set-server=utf8mb4
|
||||||
|
--collation-server=utf8mb4_unicode_ci
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Set up database (${{ matrix.TESTING_DB }})
|
- name: Install MySQL client
|
||||||
|
run: |
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y default-mysql-client
|
||||||
|
timeout-minutes: 2
|
||||||
|
|
||||||
|
- name: Set up database (mysql)
|
||||||
uses: ./.github/actions/setup-database
|
uses: ./.github/actions/setup-database
|
||||||
with:
|
with:
|
||||||
database: ${{ matrix.TESTING_DB }}
|
database: mysql
|
||||||
timeout-minutes: 5
|
timeout-minutes: 5
|
||||||
|
|
||||||
- name: Set up Python ${{ matrix.python-version }}
|
- name: Run tests
|
||||||
uses: actions/setup-python@v4
|
uses: ./.github/actions/run-tests
|
||||||
with:
|
with:
|
||||||
python-version: ${{ matrix.python-version }}
|
python-version: ${{ matrix.python-version }}
|
||||||
cache: pip
|
testing-db: mysql
|
||||||
cache-dependency-path: |
|
coverage-test: "false"
|
||||||
pyproject.toml
|
needs-postgres-package: "false"
|
||||||
|
needs-mysql-package: "true"
|
||||||
|
|
||||||
- name: Install package dependencies
|
test-postgresql:
|
||||||
run: |
|
name: Test (PostgreSQL)
|
||||||
python -m pip install --upgrade pip
|
runs-on: ubuntu-latest
|
||||||
pip install wheel
|
|
||||||
pip install psycopg2-binary==2.9.5 # req by postgresql
|
|
||||||
pip install mysqlclient
|
|
||||||
pip install coveralls
|
|
||||||
pip install tblib
|
|
||||||
pip install .
|
|
||||||
pip install .[extra]
|
|
||||||
|
|
||||||
- name: Initialize evennia
|
strategy:
|
||||||
run: |
|
fail-fast: false
|
||||||
evennia --init testing_mygame
|
matrix:
|
||||||
cp .github/workflows/${{ matrix.TESTING_DB }}_settings.py testing_mygame/server/conf/settings.py
|
python-version: ["3.11", "3.12", "3.13"]
|
||||||
cd testing_mygame
|
|
||||||
evennia migrate
|
|
||||||
evennia collectstatic --noinput
|
|
||||||
|
|
||||||
# For non-coverage tests, run them in parallel.
|
timeout-minutes: 35
|
||||||
- name: Run test suite
|
|
||||||
if: ${{ ! matrix.coverage-test }}
|
|
||||||
working-directory: testing_mygame
|
|
||||||
run: |
|
|
||||||
evennia test ${{ env.UNIT_TEST_SETTINGS }} evennia
|
|
||||||
|
|
||||||
# OBS - it's important to not run the coverage tests with --parallel, it messes up the coverage
|
services:
|
||||||
# calculation!
|
postgres:
|
||||||
- name: Run test suite with coverage
|
image: postgres:13
|
||||||
if: ${{ matrix.coverage-test }}
|
|
||||||
working-directory: testing_mygame
|
|
||||||
run: |
|
|
||||||
coverage run --rcfile=../pyproject.toml ../bin/unix/evennia test ${{ env.COVERAGE_TEST_SETTINGS }} evennia
|
|
||||||
coverage combine
|
|
||||||
coverage xml
|
|
||||||
coverage --version
|
|
||||||
coverage report | grep TOTAL
|
|
||||||
|
|
||||||
# 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: ${{ matrix.coverage-test && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop') }}
|
|
||||||
continue-on-error: true
|
|
||||||
env:
|
env:
|
||||||
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
|
POSTGRES_DB: evennia
|
||||||
|
POSTGRES_USER: evennia
|
||||||
|
POSTGRES_PASSWORD: password
|
||||||
|
ports:
|
||||||
|
- 5432:5432
|
||||||
|
options: >-
|
||||||
|
--health-cmd pg_isready
|
||||||
|
--health-interval=10s
|
||||||
|
--health-timeout=5s
|
||||||
|
--health-retries=5
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install PostgreSQL client
|
||||||
run: |
|
run: |
|
||||||
cd testing_mygame
|
sudo apt-get update
|
||||||
coveralls
|
sudo apt-get install -y postgresql-client
|
||||||
|
timeout-minutes: 2
|
||||||
|
|
||||||
|
- name: Set up database (postgresql)
|
||||||
|
uses: ./.github/actions/setup-database
|
||||||
|
with:
|
||||||
|
database: postgresql
|
||||||
|
timeout-minutes: 5
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
uses: ./.github/actions/run-tests
|
||||||
|
with:
|
||||||
|
python-version: ${{ matrix.python-version }}
|
||||||
|
testing-db: postgresql
|
||||||
|
coverage-test: "false"
|
||||||
|
needs-postgres-package: "true"
|
||||||
|
needs-mysql-package: "false"
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
name: Deploy Docker Image
|
name: Deploy Docker Image
|
||||||
needs: test
|
needs: [test-sqlite, test-mysql, test-postgresql]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: ${{ github.repository == 'evennia/evennia' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop') }}
|
if: ${{ github.repository == 'evennia/evennia' && github.ref == 'refs/heads/main' }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
"""
|
r"""
|
||||||
Pseudo-random generator and registry
|
Pseudo-random generator and registry
|
||||||
|
|
||||||
Evennia contribution - Vincent Le Goff 2017
|
Evennia contribution - Vincent Le Goff 2017
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue