Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
Normalize Unit Testing workflow across repos
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Apr 24, 2020
1 parent 5a2c4ba commit 16e9b6a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 24 deletions.
64 changes: 45 additions & 19 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,28 @@ name: Unit Testing

on:
pull_request:
branches: '*'
branches: '**'
push:
branches:
- master
- develop
branches: '**'
schedule:
- cron: '0 */6 * * *'

jobs:
unit-test:
name: Unit Testing
name: Unit
runs-on: ubuntu-latest
container:
image: atk4/image:${{ matrix.php }} # https://github.com/atk4/image
strategy:
fail-fast: false
matrix:
php: ['7.2', '7.3', 'latest']
type: ['Phpunit']
include:
- php: 'latest'
type: 'CodingStyle'
env:
LOG_COVERAGE: "${{ fromJSON('{true: \"1\", false: \"\"}')[matrix.php == 'latest' && matrix.type == 'Phpunit' && (github.event_name == 'pull_request' || (github.event_name == 'push' && (github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/master')))] }}"
services:
mysql:
image: mysql:5.7
Expand All @@ -26,35 +32,55 @@ jobs:
DB_DATABASE: dsql_test
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=5
steps:
- uses: actions/checkout@v2
- run: php --version
- name: Get Composer Cache Directory
- name: Checkout
uses: actions/checkout@v2

- name: Configure PHP
run: |
if [ -z "$LOG_COVERAGE" ]; then rm /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini ; fi
php --version
- name: Setup cache 1/2
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v1
- name: Setup cache 2/2
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('composer.json') }}
key: ${{ runner.os }}-composer-${{ matrix.php }}-${{ matrix.type }}-${{ hashFiles('composer.json') }}
restore-keys: |
${{ runner.os }}-composer-
- run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
- name: Install PHP dependencies
run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader

- name: Run Tests
- name: Init
run: |
mkdir -p build/logs
mysql -uroot -ppassword -h mysql -e 'CREATE DATABASE dsql_test;'
- name: SQLite Testing
run: vendor/bin/phpunit --configuration phpunit.xml --coverage-text --exclude-group dns
- name: MySQL Testing
run: vendor/bin/phpunit --configuration phpunit-mysql-workflow.xml --exclude-group dns
- name: "Run tests: SQLite (only for Phpunit)"
if: matrix.type == 'Phpunit'
run: "vendor/bin/phpunit --configuration phpunit.xml \"$(if [ -n \"$LOG_COVERAGE\" ]; then echo '--coverage-text'; else echo '--no-coverage'; fi)\""

- name: "Run tests: MySQL (only for Phpunit)"
if: matrix.type == 'Phpunit'
run: "vendor/bin/phpunit --configuration phpunit-mysql-workflow.xml \"$(if [ -n \"$LOG_COVERAGE\" ]; then echo '--coverage-text'; else echo '--no-coverage'; fi)\""

- name: "Run tests: Check Coding Style (only for CodingStyle)"
if: matrix.type == 'CodingStyle'
continue-on-error: true # remove once CS is fully fixer
run: vendor/bin/php-cs-fixer fix --dry-run --using-cache=yes --cache-file="${{ steps.composer-cache.outputs.dir }}/.php_cs.cache" --diff --diff-format=udiff --verbose --show-progress=dots

- name: Merge coverage logs
run: vendor/bin/phpcov merge build/logs/ --clover build/logs/cc.xml;
- name: Merge coverage logs (only for "latest" Phpunit)
if: env.LOG_COVERAGE
run: vendor/bin/phpcov merge build/logs/ --clover build/logs/cc.xml

- uses: codecov/codecov-action@v1
- name: Upload coverage logs (only for "latest" Phpunit)
if: env.LOG_COVERAGE
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: build/logs/cc.xml
12 changes: 7 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
"minimum-stability": "dev",
"prefer-stable": true,
"authors": [
{
"name": "Romans Malinovskis",
"email": "romans@agiletoolkit.org",
"homepage": "https://nearly.guru/"
}
{"name": "Romans Malinovskis", "email": "romans@agiletoolkit.org", "homepage": "https://nearly.guru/" },
{"name": "Michael Voříšek", "homepage": "https://mvorisek.cz/"}
],
"config": {
"sort-packages": true
},
"require": {
"php": ">=7.2.0",
"atk4/data": "dev-develop"
Expand All @@ -33,11 +33,13 @@
"require-dev": {
"atk4/ui": "dev-develop",
"phpunit/phpunit": "*",
"friendsofphp/php-cs-fixer": "^2.16",
"phpunit/phpcov": "*"
},
"require-dev-release": {
"atk4/ui": "^2.0",
"phpunit/phpunit": "*",
"friendsofphp/php-cs-fixer": "^2.16",
"phpunit/phpcov": "*"
},
"suggest": {
Expand Down

0 comments on commit 16e9b6a

Please sign in to comment.