Merge pull request #3006 from dvoraen/new_workflows
Unit testing workflow updates
This commit is contained in:
commit
dfa93e9206
2 changed files with 197 additions and 162 deletions
86
.github/actions/setup-database.yml
vendored
Normal file
86
.github/actions/setup-database.yml
vendored
Normal file
|
|
@ -0,0 +1,86 @@
|
||||||
|
# evennia/setup-database
|
||||||
|
|
||||||
|
# Use this action in a workflow for when you need to do initialization of database services
|
||||||
|
# (such as with PostgreSQL and MySQL) before you initiate unit tests that will employ that
|
||||||
|
# database service.
|
||||||
|
|
||||||
|
# NOTE: This action was intended for use with the core Evennia workflows ONLY.
|
||||||
|
|
||||||
|
name: Set up Evennia database service
|
||||||
|
author: dvoraen
|
||||||
|
description: "Activates the database server for the passed in service and ensures it's ready for use."
|
||||||
|
|
||||||
|
inputs:
|
||||||
|
database:
|
||||||
|
description: "Database service being initialized."
|
||||||
|
type: string
|
||||||
|
required: true
|
||||||
|
|
||||||
|
runs:
|
||||||
|
using: "composite"
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Set up PostgreSQL server
|
||||||
|
if: ${{ inputs.database == "postgresql" }}
|
||||||
|
uses: harmon758/postgresql-action@v1
|
||||||
|
with:
|
||||||
|
postgresql version: "11"
|
||||||
|
postgresql db: "evennia"
|
||||||
|
postgresql user: "evennia"
|
||||||
|
postgresql password: "password"
|
||||||
|
|
||||||
|
- name: Wait for PostgreSQL to activate
|
||||||
|
if: ${{ inputs.database == "postgresql" }}
|
||||||
|
run: |
|
||||||
|
while ! pg_isready -h 127.0.0.1 -q >/dev/null 2>&1
|
||||||
|
do
|
||||||
|
sleep 1
|
||||||
|
echo -n .
|
||||||
|
done
|
||||||
|
echo
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
- name: Set up MySQL server
|
||||||
|
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" }}
|
||||||
|
run: |
|
||||||
|
while ! mysqladmin ping -h 127.0.0.1 -u root -proot_password -s >/dev/null 2>&1
|
||||||
|
do
|
||||||
|
sleep 1
|
||||||
|
echo -n .
|
||||||
|
done
|
||||||
|
echo
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
- name: Set up MySQL Privileges
|
||||||
|
if: ${{ inputs.database == "mysql" }}
|
||||||
|
run: |
|
||||||
|
cat <<EOF | mysql -u root -proot_password -h 127.0.0.1 mysql
|
||||||
|
create user 'evennia'@'%' identified by 'password';
|
||||||
|
grant all on \`evennia%\`.* to 'evennia'@'%';
|
||||||
|
grant process on *.* to 'evennia'@'%';
|
||||||
|
flush privileges
|
||||||
|
EOF
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
# get logs from db start
|
||||||
|
- name: Database container logs
|
||||||
|
if: ${{ inputs.database == "postgresql" || inputs.database == "mysql" }}
|
||||||
|
uses: jwalton/gh-docker-logs@v2
|
||||||
|
|
||||||
|
- name: Check running containers
|
||||||
|
if: ${{ inputs.database == "postgresql" || inputs.database == "mysql" }}
|
||||||
|
run: docker ps -a
|
||||||
273
.github/workflows/github_action_test_suite.yml
vendored
273
.github/workflows/github_action_test_suite.yml
vendored
|
|
@ -5,188 +5,137 @@ name: test-suite
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ master, develop ]
|
branches: [master, develop]
|
||||||
paths-ignore:
|
paths-ignore:
|
||||||
- 'docs/**'
|
- "docs/**"
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ master, develop ]
|
branches: [master, develop]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
test:
|
||||||
|
name: Test
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
python-version: ['3.9', '3.10', '3.11']
|
python-version: ["3.9", "3.10", "3.11"]
|
||||||
TESTING_DB: ['sqlite3', 'postgresql', 'mysql']
|
TESTING_DB: ["sqlite3", "postgresql", "mysql"]
|
||||||
|
include:
|
||||||
|
- python-version: "3.10"
|
||||||
|
TESTING_DB: "sqlite3"
|
||||||
|
coverage-test: true
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
- uses: actions/checkout@v3
|
- name: Set up database (${{ matrix.TESTING_DB }})
|
||||||
|
uses: ./.github/actions/setup-database
|
||||||
|
with:
|
||||||
|
database: ${{ matrix.TESTING_DB }}
|
||||||
|
timeout-minutes: 5
|
||||||
|
|
||||||
- name: Set up PostgreSQL server
|
- name: Set up Python ${{ matrix.python-version }}
|
||||||
uses: harmon758/postgresql-action@v1
|
uses: actions/setup-python@v4
|
||||||
if: ${{ matrix.TESTING_DB == 'postgresql' }}
|
with:
|
||||||
with:
|
python-version: ${{ matrix.python-version }}
|
||||||
postgresql version: '11'
|
cache: pip
|
||||||
postgresql db: 'evennia'
|
cache-dependency-path: |
|
||||||
postgresql user: 'evennia'
|
pyproject.toml
|
||||||
postgresql password: 'password'
|
|
||||||
|
|
||||||
- name: Set up MySQL server
|
- name: Install package dependencies
|
||||||
uses: mirromutth/mysql-action@v1.1
|
run: |
|
||||||
if: ${{ matrix.TESTING_DB == 'mysql'}}
|
python -m pip install --upgrade pip
|
||||||
with:
|
pip install wheel
|
||||||
host port: 3306
|
pip install psycopg2-binary==2.9.5 # req by postgresql
|
||||||
# character set server: 'utf8mb4'
|
pip install mysqlclient
|
||||||
# collation server: 'utf8mb4_unicode_ci'
|
pip install coveralls
|
||||||
character set server: 'utf8'
|
pip install tblib
|
||||||
collation server: 'utf8_general_ci'
|
pip install .
|
||||||
mysql database: 'evennia'
|
pip install .[extra]
|
||||||
mysql user: 'evennia'
|
|
||||||
mysql password: 'password'
|
|
||||||
mysql root password: root_password
|
|
||||||
|
|
||||||
# wait for db to activate
|
- name: Initialize evennia
|
||||||
- name: wait for db to activate
|
run: |
|
||||||
if: matrix.TESTING_DB == 'postgresql' || matrix.TESTING_DB == 'mysql'
|
evennia --init testing_mygame
|
||||||
run: |
|
cp .github/workflows/${{ matrix.TESTING_DB }}_settings.py testing_mygame/server/conf/settings.py
|
||||||
|
cd testing_mygame
|
||||||
|
evennia migrate
|
||||||
|
evennia collectstatic --noinput
|
||||||
|
|
||||||
if [ ${{ matrix.TESTING_DB }} = mysql ]
|
# For non-coverage tests, run them in parallel.
|
||||||
then
|
- name: Run test suite
|
||||||
while ! mysqladmin ping -h 127.0.0.1 -u root -proot_password -s >/dev/null 2>&1
|
if: ${{ ! matrix.coverage-test }}
|
||||||
do
|
working-directory: testing_mygame
|
||||||
sleep 1
|
run: |
|
||||||
echo -n .
|
evennia test \
|
||||||
done
|
|
||||||
echo
|
|
||||||
else
|
|
||||||
while ! pg_isready -h 127.0.0.1 -q >/dev/null 2>&1
|
|
||||||
do
|
|
||||||
sleep 1
|
|
||||||
echo -n .
|
|
||||||
done
|
|
||||||
echo
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: mysql privileges
|
|
||||||
if: matrix.TESTING_DB == 'mysql'
|
|
||||||
run: |
|
|
||||||
|
|
||||||
cat <<EOF | mysql -u root -proot_password -h 127.0.0.1 mysql
|
|
||||||
create user 'evennia'@'%' identified by 'password';
|
|
||||||
grant all on \`evennia%\`.* to 'evennia'@'%';
|
|
||||||
grant process on *.* to 'evennia'@'%';
|
|
||||||
flush privileges
|
|
||||||
EOF
|
|
||||||
|
|
||||||
# get logs from db start
|
|
||||||
- name: Database container logs
|
|
||||||
if: matrix.TESTING_DB == 'postgresql' || matrix.TESTING_DB == 'mysql'
|
|
||||||
uses: jwalton/gh-docker-logs@v2
|
|
||||||
|
|
||||||
- name: Check running containers
|
|
||||||
if: matrix.TESTING_DB == 'postgresql' || matrix.TESTING_DB == 'mysql'
|
|
||||||
run: docker ps -a
|
|
||||||
|
|
||||||
- name: Set up Python ${{ matrix.python-version }}
|
|
||||||
uses: actions/setup-python@v4
|
|
||||||
with:
|
|
||||||
python-version: ${{ matrix.python-version }}
|
|
||||||
cache: pip
|
|
||||||
cache-dependency-path: |
|
|
||||||
pyproject.toml
|
|
||||||
|
|
||||||
- name: Install package dependencies
|
|
||||||
run: |
|
|
||||||
python -m pip install --upgrade pip
|
|
||||||
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
|
|
||||||
run: |
|
|
||||||
evennia --init testing_mygame
|
|
||||||
cp .github/workflows/${{ matrix.TESTING_DB }}_settings.py testing_mygame/server/conf/settings.py
|
|
||||||
cd testing_mygame
|
|
||||||
evennia migrate
|
|
||||||
evennia collectstatic --noinput
|
|
||||||
|
|
||||||
# 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: matrix.TESTING_DB == 'sqlite3' && matrix.python-version == '3.10'
|
|
||||||
working-directory: testing_mygame
|
|
||||||
run: |
|
|
||||||
coverage run \
|
|
||||||
--source=../evennia \
|
|
||||||
--omit=*/migrations/*,*/urls.py,*/test*.py,*.sh,*.txt,*.md,*.pyc,*.service \
|
|
||||||
../bin/unix/evennia test \
|
|
||||||
--settings=settings \
|
--settings=settings \
|
||||||
|
--keepdb \
|
||||||
|
--parallel 4 \
|
||||||
--timing \
|
--timing \
|
||||||
evennia
|
evennia
|
||||||
coverage xml
|
|
||||||
coverage --version
|
|
||||||
coverage report | grep TOTAL
|
|
||||||
|
|
||||||
# For other runs, run tests in parallel
|
# OBS - it's important to not run the coverage tests with --parallel, it messes up the coverage
|
||||||
- name: Run test suite
|
# calculation!
|
||||||
if: matrix.TESTING_DB != 'sqlite3' || matrix.python-version != '3.10'
|
- name: Run test suite with coverage
|
||||||
working-directory: testing_mygame
|
if: ${{ matrix.coverage-test }}
|
||||||
run: |
|
working-directory: testing_mygame
|
||||||
evennia test \
|
run: |
|
||||||
--settings=settings \
|
coverage run \
|
||||||
--keepdb \
|
--source=../evennia \
|
||||||
--parallel 4 \
|
--omit=*/migrations/*,*/urls.py,*/test*.py,*.sh,*.txt,*.md,*.pyc,*.service \
|
||||||
--timing \
|
../bin/unix/evennia test \
|
||||||
evennia
|
--settings=settings \
|
||||||
|
--timing \
|
||||||
|
evennia
|
||||||
|
coverage xml
|
||||||
|
coverage --version
|
||||||
|
coverage report | grep TOTAL
|
||||||
|
|
||||||
# we only want to run coverall once, so we only do it for one of the matrix combinations
|
# 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
|
# it's also not critical if pushing to either service fails (happens for PRs since env is not
|
||||||
# available outside of the evennia org)
|
# available outside of the evennia org)
|
||||||
- name: Send data to Coveralls
|
- name: Send data to Coveralls
|
||||||
if: matrix.TESTING_DB == 'sqlite3' && matrix.python-version == '3.10' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop')
|
if: ${{ matrix.coverage-test && (github.ref == "refs/heads/master" || github.ref == "refs/heads/develop") }}
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
env:
|
env:
|
||||||
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
|
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
cd testing_mygame
|
cd testing_mygame
|
||||||
coveralls
|
coveralls
|
||||||
|
|
||||||
# docker setup and push
|
deploy:
|
||||||
-
|
name: Deploy Docker Image
|
||||||
name: Set up QEMU
|
needs: test
|
||||||
if: matrix.TESTING_DB == 'sqlite3' && matrix.python-version == '3.10'
|
runs-on: ubuntu-latest
|
||||||
uses: docker/setup-qemu-action@v2
|
if: ${{ github.repository == "evennia/evennia" }}
|
||||||
-
|
steps:
|
||||||
name: Set up Docker Buildx
|
- uses: actions/checkout@v3
|
||||||
if: matrix.TESTING_DB == 'sqlite3' && matrix.python-version == '3.10'
|
|
||||||
uses: docker/setup-buildx-action@v2
|
- name: Set up QEMU
|
||||||
-
|
uses: docker/setup-qemu-action@v2
|
||||||
name: Login to DockerHub
|
|
||||||
if: matrix.TESTING_DB == 'sqlite3' && matrix.python-version == '3.10' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop')
|
- name: Set up Docker Buildx
|
||||||
uses: docker/login-action@v2
|
uses: docker/setup-buildx-action@v2
|
||||||
with:
|
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
- name: Login to DockerHub
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
if: ${{ github.ref == "refs/heads/master" || github.ref == "refs/heads/develop" }}
|
||||||
-
|
uses: docker/login-action@v2
|
||||||
name: Build and push for master
|
with:
|
||||||
if: matrix.TESTING_DB == 'sqlite3' && matrix.python-version == '3.10' && github.ref == 'refs/heads/master'
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
id: docker_build_master
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
uses: docker/build-push-action@v3
|
|
||||||
with:
|
- name: Build and push for master
|
||||||
push: true
|
if: ${{ github.ref == "refs/heads/master" }}
|
||||||
tags: evennia/evennia:latest
|
id: docker_build_master
|
||||||
-
|
uses: docker/build-push-action@v3
|
||||||
name: Build and push for develop
|
with:
|
||||||
if: matrix.TESTING_DB == 'sqlite3' && matrix.python-version == '3.10' && github.ref == 'refs/heads/develop'
|
push: true
|
||||||
id: docker_build_develop
|
tags: evennia/evennia:latest
|
||||||
uses: docker/build-push-action@v3
|
|
||||||
with:
|
- name: Build and push for develop
|
||||||
push: true
|
if: ${{ github.ref == "refs/heads/develop" }}
|
||||||
tags: evennia/evennia:develop
|
id: docker_build_develop
|
||||||
|
uses: docker/build-push-action@v3
|
||||||
|
with:
|
||||||
|
push: true
|
||||||
|
tags: evennia/evennia:develop
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue