Skip to content

Migrate to PHP 8.4 (Ouzo 4.0.0) (#334) #258

Migrate to PHP 8.4 (Ouzo 4.0.0) (#334)

Migrate to PHP 8.4 (Ouzo 4.0.0) (#334) #258

Workflow file for this run

name: build
on:
push:
pull_request:
jobs:
tests:
name: Unit tests on PHP ${{ matrix.php }} and ${{ matrix.db }}
runs-on: ubuntu-latest
strategy:
matrix:
php: [ '8.4' ]
db: [ 'MySQL', 'PostgreSQL', 'SQLite' ]
include:
- db: MySQL
phpunitArgs: "--exclude-group postgres --exclude-group sqlite3"
phpunitEnv: db=mysql
- db: PostgreSQL
phpunitArgs: "--exclude-group mysql --exclude-group sqlite3"
phpunitEnv: db=postgres
coverage: pcov
- db: SQLite
phpunitArgs: "--exclude-group mysql --exclude-group postgres --exclude-group non-sqlite3"
phpunitEnv: db=sqlite3
services:
mysql:
image: mysql:8
env:
MYSQL_DATABASE: ouzo_test
MYSQL_ROOT_PASSWORD: password
options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 5
ports:
- 3306:3306
postgres:
image: postgres:18
env:
POSTGRES_DB: ouzo_test
POSTGRES_USER: ouzo_user
POSTGRES_PASSWORD: password
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
ports:
- 5432:5432
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Use PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer:v2
coverage: ${{ matrix.coverage || 'none' }}
- name: Seed database (PostgreSQL)
if: matrix.db == 'PostgreSQL'
run: PGPASSWORD=password psql -h 127.0.0.1 -U ouzo_user -v ON_ERROR_STOP=1 -e -f test/test-db/recreate_schema.sql ouzo_test
- name: Seed database (MySQL)
if: matrix.db == 'MySQL'
run: |
mysql -h 127.0.0.1 -u root -ppassword -e "CREATE USER travis; GRANT ALL ON *.* TO travis;"
cat test/test-db/recreate_schema_mysql.sql | mysql -h 127.0.0.1 -u root -ppassword ouzo_test
- name: Seed database (SQLite)
if: matrix.db == 'SQLite'
run: echo | sqlite3 ouzo_test -init test/test-db/recreate_schema_sqlite3.sql
- name: Cache dependencies installed with Composer
uses: actions/cache@v4
with:
path: ~/.cache/composer
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: php${{ matrix.php }}-composer-
- name: Install dependencies
run: composer install --no-progress
- name: Run tests
if: matrix.coverage == ''
run: ${{ matrix.phpunitEnv }} ./vendor/bin/phpunit ${{ matrix.phpunitArgs }}
- name: Run tests with coverage
if: matrix.coverage != ''
run: ${{ matrix.phpunitEnv }} ./vendor/bin/phpunit ${{ matrix.phpunitArgs }} --coverage-clover build/logs/clover.xml --coverage-html build/coverage-html
- name: Coverage summary
if: matrix.coverage != ''
run: |
php -r '
$xml = simplexml_load_file("build/logs/clover.xml");
$metrics = $xml->project->metrics;
$stmts = (int)$metrics["statements"];
$covered = (int)$metrics["coveredstatements"];
$pct = $stmts > 0 ? round($covered / $stmts * 100, 2) : 0;
file_put_contents(getenv("GITHUB_STEP_SUMMARY"), "## Code Coverage\n\n**{$pct}%** ({$covered}/{$stmts} statements)\n");
'
- name: Upload coverage report
if: matrix.coverage != ''
uses: actions/upload-artifact@v7
with:
name: coverage-report
path: build/coverage-html
retention-days: 14