From 756e4fddaa3d3ac44ae63270f4c183b547a552f1 Mon Sep 17 00:00:00 2001 From: dvoraen <42825596+dvoraen@users.noreply.github.com> Date: Wed, 30 Nov 2022 05:32:00 -0800 Subject: [PATCH 1/6] setup-database action --- .github/actions/setup-database.yml | 89 ++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 .github/actions/setup-database.yml diff --git a/.github/actions/setup-database.yml b/.github/actions/setup-database.yml new file mode 100644 index 0000000000..b1afbc272b --- /dev/null +++ b/.github/actions/setup-database.yml @@ -0,0 +1,89 @@ +# 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 written for use with the core Evennia workflows ONLY. + +name: Set up Database +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 SQLite + # if: inputs.database == "sqlite3" + + - 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" && success() + 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" && success() + 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" && success() + run: | + cat < Date: Wed, 30 Nov 2022 05:34:08 -0800 Subject: [PATCH 2/6] refactor of unit test workflow; uses new action --- .../workflows/github_action_test_suite.yml | 271 +++++++----------- 1 file changed, 109 insertions(+), 162 deletions(-) diff --git a/.github/workflows/github_action_test_suite.yml b/.github/workflows/github_action_test_suite.yml index aefca993e1..32c823ca4f 100644 --- a/.github/workflows/github_action_test_suite.yml +++ b/.github/workflows/github_action_test_suite.yml @@ -5,188 +5,135 @@ name: test-suite on: push: - branches: [ master, develop ] + branches: [master, develop] paths-ignore: - - 'docs/**' + - "docs/**" pull_request: - branches: [ master, develop ] + branches: [master, develop] jobs: - build: + test: + name: Test runs-on: ubuntu-latest strategy: fail-fast: false matrix: - python-version: ['3.9', '3.10', '3.11'] - TESTING_DB: ['sqlite3', 'postgresql', 'mysql'] + python-version: ["3.9", "3.10", "3.11"] + TESTING_DB: ["sqlite3", "postgresql", "mysql"] + include: + - coverage-test: false + - coverage-test: true + python-version: "3.10" + TESTING_DB: "sqlite3" 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 - uses: harmon758/postgresql-action@v1 - if: ${{ matrix.TESTING_DB == 'postgresql' }} - with: - postgresql version: '11' - postgresql db: 'evennia' - postgresql user: 'evennia' - postgresql password: 'password' + - 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: 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 + - 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] - # wait for db to activate - - name: wait for db to activate - if: matrix.TESTING_DB == 'postgresql' || matrix.TESTING_DB == 'mysql' - run: | + - 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 - 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 + # 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.coverage-test + 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 \ + --timing \ + evennia + coverage xml + coverage --version + coverage report | grep TOTAL - - name: mysql privileges - if: matrix.TESTING_DB == 'mysql' - run: | - - cat < Date: Thu, 1 Dec 2022 05:10:59 -0800 Subject: [PATCH 3/6] Style updates and improved matrix include --- .github/actions/setup-database.yml | 18 ++++++++-------- .../workflows/github_action_test_suite.yml | 21 ++++++++++--------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/.github/actions/setup-database.yml b/.github/actions/setup-database.yml index b1afbc272b..2d98344961 100644 --- a/.github/actions/setup-database.yml +++ b/.github/actions/setup-database.yml @@ -4,9 +4,9 @@ # (such as with PostgreSQL and MySQL) before you initiate unit tests that will employ that # database service. -# NOTE: This action was written for use with the core Evennia workflows ONLY. +# NOTE: This action was intended for use with the core Evennia workflows ONLY. -name: Set up Database +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." @@ -24,7 +24,7 @@ runs: # if: inputs.database == "sqlite3" - name: Set up PostgreSQL server - if: inputs.database == "postgresql" + if: ${{ inputs.database == "postgresql" }} uses: harmon758/postgresql-action@v1 with: postgresql version: "11" @@ -33,7 +33,7 @@ runs: postgresql password: "password" - name: Wait for PostgreSQL to activate - if: inputs.database == "postgresql" && success() + if: ${{ inputs.database == "postgresql" }} run: | while ! pg_isready -h 127.0.0.1 -q >/dev/null 2>&1 do @@ -44,7 +44,7 @@ runs: shell: bash - name: Set up MySQL server - if: inputs.database == "mysql" + if: ${{ inputs.database == "mysql" }} uses: mirromutth/mysql-action@v1.1 with: host port: 3306 @@ -58,7 +58,7 @@ runs: mysql root password: root_password - name: Wait for MySQL to activate - if: inputs.database == "mysql" && success() + if: ${{ inputs.database == "mysql" }} run: | while ! mysqladmin ping -h 127.0.0.1 -u root -proot_password -s >/dev/null 2>&1 do @@ -69,7 +69,7 @@ runs: shell: bash - name: Set up MySQL Privileges - if: inputs.database == "mysql" && success() + if: ${{ inputs.database == "mysql" }} run: | cat < Date: Thu, 1 Dec 2022 06:43:20 -0800 Subject: [PATCH 4/6] grouped coverage testing steps together --- .../workflows/github_action_test_suite.yml | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/github_action_test_suite.yml b/.github/workflows/github_action_test_suite.yml index 8b38446fd6..b1343e8d2b 100644 --- a/.github/workflows/github_action_test_suite.yml +++ b/.github/workflows/github_action_test_suite.yml @@ -62,6 +62,18 @@ jobs: evennia migrate evennia collectstatic --noinput + # For non-coverage tests, run them in parallel. + - name: Run test suite + if: ! ${{ matrix.coverage-test }} + working-directory: testing_mygame + run: | + evennia test \ + --settings=settings \ + --keepdb \ + --parallel 4 \ + --timing \ + evennia + # OBS - it's important to not run the coverage tests with --parallel, it messes up the coverage # calculation! - name: Run test suite with coverage @@ -79,18 +91,6 @@ jobs: coverage --version coverage report | grep TOTAL - # For other runs, run tests in parallel - - name: Run test suite - if: ! ${{ matrix.coverage-test }} - working-directory: testing_mygame - run: | - evennia test \ - --settings=settings \ - --keepdb \ - --parallel 4 \ - --timing \ - evennia - # 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) From c3bea4aaec36726d01ccae9891df7d892793bf39 Mon Sep 17 00:00:00 2001 From: dvoraen <42825596+dvoraen@users.noreply.github.com> Date: Thu, 1 Dec 2022 06:58:17 -0800 Subject: [PATCH 5/6] standardized strings; deploy only from source repo --- .github/actions/setup-database.yml | 8 ++++---- .github/workflows/github_action_test_suite.yml | 9 +++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/actions/setup-database.yml b/.github/actions/setup-database.yml index 2d98344961..cb33aef0d5 100644 --- a/.github/actions/setup-database.yml +++ b/.github/actions/setup-database.yml @@ -48,8 +48,8 @@ runs: uses: mirromutth/mysql-action@v1.1 with: host port: 3306 - # character set server: 'utf8mb4' - # collation server: 'utf8mb4_unicode_ci' + # character set server: "utf8mb4" + # collation server: "utf8mb4_unicode_ci" character set server: "utf8" collation server: "utf8_general_ci" mysql database: "evennia" @@ -81,9 +81,9 @@ runs: # get logs from db start - name: Database container logs - if: ${{ inputs.database == 'postgresql' || inputs.database == 'mysql' }} + if: ${{ inputs.database == "postgresql" || inputs.database == "mysql" }} uses: jwalton/gh-docker-logs@v2 - name: Check running containers - if: ${{ inputs.database == 'postgresql' || inputs.database == 'mysql' }} + if: ${{ inputs.database == "postgresql" || inputs.database == "mysql" }} run: docker ps -a diff --git a/.github/workflows/github_action_test_suite.yml b/.github/workflows/github_action_test_suite.yml index b1343e8d2b..78154b302d 100644 --- a/.github/workflows/github_action_test_suite.yml +++ b/.github/workflows/github_action_test_suite.yml @@ -95,7 +95,7 @@ jobs: # 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/master' || github.ref == 'refs/heads/develop') }} + if: ${{ matrix.coverage-test && (github.ref == "refs/heads/master" || github.ref == "refs/heads/develop") }} continue-on-error: true env: COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} @@ -107,6 +107,7 @@ jobs: name: Deploy Docker Image needs: test runs-on: ubuntu-latest + if: ${{ github.repository == "evennia/evennia" }} steps: - uses: actions/checkout@v3 @@ -117,14 +118,14 @@ jobs: uses: docker/setup-buildx-action@v2 - name: Login to DockerHub - if: ${{ 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 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Build and push for master - if: ${{ github.ref == 'refs/heads/master' }} + if: ${{ github.ref == "refs/heads/master" }} id: docker_build_master uses: docker/build-push-action@v3 with: @@ -132,7 +133,7 @@ jobs: tags: evennia/evennia:latest - name: Build and push for develop - if: ${{ github.ref == 'refs/heads/develop' }} + if: ${{ github.ref == "refs/heads/develop" }} id: docker_build_develop uses: docker/build-push-action@v3 with: From c6882749bb5846988210aa46f2c1e19ba6653b09 Mon Sep 17 00:00:00 2001 From: dvoraen <42825596+dvoraen@users.noreply.github.com> Date: Thu, 1 Dec 2022 12:55:01 -0800 Subject: [PATCH 6/6] removed SQLite comments and fix if cond --- .github/actions/setup-database.yml | 3 --- .github/workflows/github_action_test_suite.yml | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/actions/setup-database.yml b/.github/actions/setup-database.yml index cb33aef0d5..3d38a3484a 100644 --- a/.github/actions/setup-database.yml +++ b/.github/actions/setup-database.yml @@ -20,9 +20,6 @@ runs: using: "composite" steps: - # - name: Set up SQLite - # if: inputs.database == "sqlite3" - - name: Set up PostgreSQL server if: ${{ inputs.database == "postgresql" }} uses: harmon758/postgresql-action@v1 diff --git a/.github/workflows/github_action_test_suite.yml b/.github/workflows/github_action_test_suite.yml index 78154b302d..8ef8d1c1d0 100644 --- a/.github/workflows/github_action_test_suite.yml +++ b/.github/workflows/github_action_test_suite.yml @@ -64,7 +64,7 @@ jobs: # For non-coverage tests, run them in parallel. - name: Run test suite - if: ! ${{ matrix.coverage-test }} + if: ${{ ! matrix.coverage-test }} working-directory: testing_mygame run: | evennia test \