-
Notifications
You must be signed in to change notification settings - Fork 6
75 lines (65 loc) · 2.6 KB
/
reusable-unit.yml
File metadata and controls
75 lines (65 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
name: Unit testing
on:
workflow_call:
inputs:
php:
type: string
required: true
coverage:
type: boolean
required: false
default: false
os:
type: string
required: false
default: 'ubuntu-22.04'
permissions:
contents: read
jobs:
unit:
name: Unit | PHP ${{ inputs.php }}${{ inputs.coverage && ' (with coverage)' || '' }}${{ startsWith( inputs.os, 'windows' ) && ' (Windows)' || '' }}${{ startsWith( inputs.os, 'macos' ) && ' (macOS)' || '' }}
runs-on: ${{ inputs.os || 'ubuntu-22.04' }}
continue-on-error: ${{ inputs.php == 'nightly' }}
steps:
- name: Check out source code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Set up PHP environment
uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # v2
with:
php-version: '${{ inputs.php }}'
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
extensions: zip
coverage: ${{ inputs.coverage && 'xdebug' || 'none' }}
tools: composer,cs2pr
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Install Composer dependencies & cache dependencies
uses: "ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda" # v3
env:
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
# PHPUnit 10+ may fail a test run when the "old" configuration format is used.
# Luckily, there is a built-in migration tool since PHPUnit 9.3.
- name: Migrate PHPUnit configuration for PHPUnit 10+
if: ${{ inputs.php >= 8.2 || inputs.php == 'nightly' }}
continue-on-error: true
run: composer phpunit -- --migrate-configuration
- name: Setup problem matcher to provide annotations for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Run PHPUnit with coverage
if: ${{ inputs.coverage }}
run: |
composer phpunit -- --coverage-clover build/logs/unit-coverage.xml
- name: Run PHPUnit
if: ${{ ! inputs.coverage }}
# For example TestBehatTags.php in wp-cli-tests depends on the db type.
env:
WP_CLI_TEST_DBTYPE: 'sqlite'
run: |
composer phpunit
- name: Upload code coverage report
if: ${{ inputs.coverage }}
uses: codecov/codecov-action@57e3a136b779b570ffcdbf80b3bdc90e7fab3de2 # v6.0.0
with:
directory: build/logs
flags: unit
token: ${{ secrets.CODECOV_TOKEN }}