refactor of unit test workflow; uses new action

This commit is contained in:
dvoraen 2022-11-30 05:34:08 -08:00
parent 756e4fddaa
commit a5fc4dad35

View file

@ -7,88 +7,34 @@ 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:
- coverage-test: false
- coverage-test: true
python-version: "3.10"
TESTING_DB: "sqlite3"
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Set up PostgreSQL server - name: Set up database (${{ matrix.TESTING_DB }})
uses: harmon758/postgresql-action@v1 uses: ./.github/actions/setup-database
if: ${{ matrix.TESTING_DB == 'postgresql' }}
with: with:
postgresql version: '11' database: ${{ matrix.TESTING_DB }}
postgresql db: 'evennia' timeout-minutes: 5
postgresql user: 'evennia'
postgresql password: 'password'
- name: Set up MySQL server
uses: mirromutth/mysql-action@v1.1
if: ${{ matrix.TESTING_DB == 'mysql'}}
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
# wait for db to activate
- name: wait for db to activate
if: matrix.TESTING_DB == 'postgresql' || matrix.TESTING_DB == 'mysql'
run: |
if [ ${{ matrix.TESTING_DB }} = mysql ]
then
while ! mysqladmin ping -h 127.0.0.1 -u root -proot_password -s >/dev/null 2>&1
do
sleep 1
echo -n .
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 }} - name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4 uses: actions/setup-python@v4
@ -120,7 +66,7 @@ jobs:
# OBS - it's important to not run the coverage tests with --parallel, it messes up the coverage # OBS - it's important to not run the coverage tests with --parallel, it messes up the coverage
# calculation! # calculation!
- name: Run test suite with coverage - name: Run test suite with coverage
if: matrix.TESTING_DB == 'sqlite3' && matrix.python-version == '3.10' if: matrix.coverage-test
working-directory: testing_mygame working-directory: testing_mygame
run: | run: |
coverage run \ coverage run \
@ -136,7 +82,7 @@ jobs:
# For other runs, run tests in parallel # For other runs, run tests in parallel
- name: Run test suite - name: Run test suite
if: matrix.TESTING_DB != 'sqlite3' || matrix.python-version != '3.10' if: ! matrix.coverage-test
working-directory: testing_mygame working-directory: testing_mygame
run: | run: |
evennia test \ evennia test \
@ -150,7 +96,7 @@ jobs:
# 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 }}
@ -158,33 +104,34 @@ jobs:
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
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v2 uses: docker/setup-qemu-action@v2
-
name: Set up Docker Buildx - name: Set up Docker Buildx
if: matrix.TESTING_DB == 'sqlite3' && matrix.python-version == '3.10'
uses: docker/setup-buildx-action@v2 uses: docker/setup-buildx-action@v2
-
name: Login to DockerHub - name: Login to DockerHub
if: matrix.TESTING_DB == 'sqlite3' && matrix.python-version == '3.10' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop') if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop'
uses: docker/login-action@v2 uses: docker/login-action@v2
with: with:
username: ${{ secrets.DOCKERHUB_USERNAME }} username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }} password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push for master - name: Build and push for master
if: matrix.TESTING_DB == 'sqlite3' && matrix.python-version == '3.10' && github.ref == 'refs/heads/master' if: github.ref == 'refs/heads/master'
id: docker_build_master id: docker_build_master
uses: docker/build-push-action@v3 uses: docker/build-push-action@v3
with: with:
push: true push: true
tags: evennia/evennia:latest tags: evennia/evennia:latest
-
name: Build and push for develop - name: Build and push for develop
if: matrix.TESTING_DB == 'sqlite3' && matrix.python-version == '3.10' && github.ref == 'refs/heads/develop' if: github.ref == 'refs/heads/develop'
id: docker_build_develop id: docker_build_develop
uses: docker/build-push-action@v3 uses: docker/build-push-action@v3
with: with: