Skip to content

Commit

Permalink
[#83] Add codecept.yml Github workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuapease committed May 8, 2024
1 parent b151f3f commit 8d15c9f
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 0 deletions.
104 changes: 104 additions & 0 deletions .github/workflows/codecept.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: Codeception
on:
workflow_call:
inputs:
php_versions:
required: true
type: string
jobs:
# Run tests in the matrix
tests:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: ["ubuntu-latest"]
php-versions: ${{ fromJSON(inputs.php_versions) }}
db: ["mysql", "pgsql"]
name: PHP ${{ matrix.php-versions }} on ${{ matrix.db }}
env:
PHP_EXTENSIONS: ctype,curl,dom,iconv,imagick,intl,json,mbstring,openssl,pcre,pdo,reflection,spl,zip
services:
# Install Postgres
pgsql:
image: postgres:latest
env:
POSTGRES_USER: root
POSTGRES_PASSWORD: mysecretpassword
POSTGRES_DB: craft_test
ports:
- 5432:5432
# Set health checks to wait until Postgres has started
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3
# Install MySQL
mysql:
image: bitnami/mysql:latest
env:
MYSQL_ROOT_PASSWORD: mysecretpassword
MYSQL_DATABASE: craft_test
MYSQL_AUTHENTICATION_PLUGIN: mysql_native_password
# Set health checks to wait until mysql has started
options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 5
ports:
- 3306:3306
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set default test command environment variable
run: |
echo "TEST_COMMAND=./vendor/bin/codecept run unit,functional --fail-fast" >> $GITHUB_ENV
# - name: Set test command for the code coverage environment
# run: |
# echo "TEST_COMMAND=./vendor/bin/codecept run unit,functional --fail-fast --coverage-xml coverage.xml;" >> $GITHUB_ENV
# if: ${{ (matrix.php-versions == '8.1' || matrix.php-versions == '8.2') && matrix.db == 'mysql' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop') }}
- name: Setup cache environment
id: extcache
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ matrix.php-versions }}
extensions: ${{ env.PHP_EXTENSIONS }}
key: extension-cache-v4 # change to clear the extension cache.
- name: Cache extensions
uses: actions/cache@v3
with:
path: ${{ steps.extcache.outputs.dir }}
key: ${{ steps.extcache.outputs.key }}
restore-keys: ${{ steps.extcache.outputs.key }}
- name: Setup PHP
id: setup-php
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: ${{ env.PHP_EXTENSIONS }}
ini-values: post_max_size=256M, max_execution_time=180, memory_limit=512M
ini-file: development
tools: composer:v2
# env:
# COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Print PHP version
run: echo ${{ steps.setup-php.outputs.php-version }}
- name: Setup problem matchers for PHP
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
- name: Copy tests .env
run: cp ./tests/.env.example.${{ matrix.db }} ./tests/.env
- name: Update .env creds
run: sed -i 's/DB_PASSWORD=/DB_PASSWORD=mysecretpassword/' tests/.env
- name: Cache Composer dependencies
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Composer dependencies
run: composer install --no-interaction --no-ansi --no-progress
- name: MySQL import timezones
if: ${{ matrix.db == 'mysql' }}
run: |
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql --host=127.0.0.1 --port=3306 --user=root --password=mysecretpassword mysql
- name: Run tests
run: ${{ env.TEST_COMMAND }}
# Only upload code coverage in specific scenarios
# - name: Upload coverage to Codecov
# if: ${{ (matrix.php-versions == '8.1' || matrix.php-versions == '8.2') && matrix.db == 'mysql' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop') }}}}
# uses: codecov/codecov-action@v2
15 changes: 15 additions & 0 deletions tests/env.example.mysql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
APP_ID=CraftCMS
SECURITY_KEY=UPzGqJJMCTM4n07jkqaFNaVoof6j_Xgo

DB_DRIVER=mysql
DB_SERVER=127.0.0.1
DB_PORT=3306
DB_DATABASE=craft_test
DB_USER=root
DB_PASSWORD=
DB_SCHEMA="public"

# Set this to the `entryUrl` param in the `codeception.yml` file.
DEFAULT_SITE_URL="https://test.craftcms.test/index.php"
FROM_EMAIL_NAME="Craft CMS"
FROM_EMAIL_ADDRESS="info@craftcms.com"
15 changes: 15 additions & 0 deletions tests/env.example.pgsql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
APP_ID=CraftCMS
SECURITY_KEY=UPzGqJJMCTM4n07jkqaFNaVoof6j_Xgo

DB_DRIVER=pgsql
DB_SERVER=127.0.0.1
DB_PORT=5432
DB_DATABASE=craft_test
DB_USER=root
DB_PASSWORD=
DB_SCHEMA="public"

# Set this to the `entryUrl` param in the `codeception.yml` file.
DEFAULT_SITE_URL="https://test.craftcms.test/index.php"
FROM_EMAIL_NAME="Craft CMS"
FROM_EMAIL_ADDRESS="info@craftcms.com"

0 comments on commit 8d15c9f

Please sign in to comment.