Skip to content

Commit

Permalink
[TASK] Add GitHub action for testing and coverage reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Adler committed Apr 27, 2023
1 parent c4ced96 commit 4991709
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 3 deletions.
82 changes: 82 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Tests
on:
push:
branches:
- main
- develop
pull_request:
branches:
- '**'

jobs:
tests:
name: Tests (PHP ${{ matrix.php-version }}, Composer ${{ matrix.composer-version }} & ${{ matrix.dependencies }} dependencies)
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-version: ["8.1", "8.2"]
composer-version: ["2.1", "2.2", "2.3", "2.4", "2.5"]
dependencies: ["highest", "lowest"]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

# Prepare environment
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
tools: composer:v${{ matrix.composer-version }}
coverage: none

# Install dependencies
- name: Install Composer dependencies
uses: ramsey/composer-install@v2
with:
dependency-versions: ${{ matrix.dependencies }}

# Run tests
- name: Run tests
run: composer test:unit

coverage:
name: Test coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

# Prepare environment
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
tools: composer:v2
coverage: pcov

# Install dependencies
- name: Install Composer dependencies
uses: ramsey/composer-install@v2
with:
dependency-versions: highest

# Run Unit tests
- name: Build coverage directory
run: mkdir -p .build/coverage
- name: Run Unit tests with coverage
run: composer test:coverage

# Report coverage
- name: Fix coverage path
working-directory: .Build/coverage
run: sed -i 's#/home/runner/work/project-builder/project-builder#${{ github.workspace }}#g' clover.xml
- name: codecov report
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
directory: .build/coverage
fail_ci_if_error: true
verbose: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
/Resources/Private/Libs/Build/vendor
/Resources/Private/Libs/vendors.phar
/.php-cs-fixer.cache
/.phpunit.result.cache
10 changes: 8 additions & 2 deletions phpunit.unit.coverage.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="true" bootstrap=".Build/vendor/typo3/testing-framework/Resources/Core/Build/UnitTestsBootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd">
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="true"
bootstrap=".Build/vendor/typo3/testing-framework/Resources/Core/Build/UnitTestsBootstrap.php"
colors="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd
">
<testsuites>
<testsuite name="unit">
<directory>Tests/Unit</directory>
</testsuite>
</testsuites>
<coverage>
<report>
<php outputFile=".Build/coverage/php/unit.cov"/>
<clover outputFile=".Build/coverage/clover.xml"/>
<html outputDirectory=".Build/coverage/html/unit/"/>
<text outputFile="php://stdout" showOnlySummary="true"/>
</report>
Expand Down
8 changes: 7 additions & 1 deletion phpunit.unit.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="true" bootstrap=".build/vendor/typo3/testing-framework/Resources/Core/Build/UnitTestsBootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd">
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="true"
bootstrap=".Build/vendor/typo3/testing-framework/Resources/Core/Build/UnitTestsBootstrap.php"
colors="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
>
<coverage/>
<testsuites>
<testsuite name="unit">
Expand Down

0 comments on commit 4991709

Please sign in to comment.