-
-
Notifications
You must be signed in to change notification settings - Fork 4
153 lines (137 loc) · 5.57 KB
/
reusable-phpunit-tests.yml
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
##
# A reusable workflow that runs the PHPUnit test suite with the specified configuration.
#
# This workflow is used by `master` and `dev`.
##
name: Run PHPUnit tests
on:
workflow_call:
inputs:
php:
description: 'The version of PHP to use, in the format of X.Y. Defaults to 7.4'
required: false
type: 'string'
default: '7.4'
wp:
description: 'The version of WordPress to use, in the format of X.Y. Defaults to latest'
required: false
type: 'string'
default: 'latest'
db-type:
description: 'Database type. Valid types are mysql and mariadb.'
required: false
type: 'string'
default: 'mysql'
#db-version:
# description: 'Database version.'
# required: false
# type: 'string'
# default: '8.0'
multisite:
description: 'Whether to run tests as multisite.'
required: false
type: 'boolean'
default: false
allow-errors:
description: 'Whether to continue when test errors occur.'
required: false
type: 'boolean'
default: false
coverage:
description: 'Whether to check coverage.'
required: false
type: 'boolean'
default: false
wordpress-translate-api-tests:
description: 'Whether to test Translating WordPress API related functions.'
required: false
type: 'boolean'
default: false
secrets:
codecov-token:
description: 'The token for codecov passed from the caller workflow'
required: true
codacy-project-token:
description: 'The token for Codacy passed from the caller workflow'
required: true
jobs:
# Runs the PHPUnit tests.
#
# Performs the following steps:
# - Checks out the repository.
# - Sets up the Database.
# - Sets up PHP.
# - Logs debug information.
# - Validate composer.
# - Installs Composer dependencies (use cache if possible).
# - Installs appropriate PHPUnit for the PHP version.
# - Installs WordPress tests.
# - Runs PHPUnit on the full codebase.
phpunit-tests:
# name: PHP ${{ inputs.php }} / ${{ 'mariadb' == inputs.db-type && 'MariaDB' || 'MySQL' }} ${{ inputs.db-version }}${{ inputs.multisite && ' multisite' || '' }}
name: WP ${{ inputs.wp }}${{ inputs.multisite && ' multisite' || '' }} ${{ inputs.wordpress-translate-api-tests && ', translate API' || '' }}${{ inputs.coverage && ', with coverage' || '' }}
runs-on: ubuntu-latest
continue-on-error: ${{ inputs.allow-errors }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up ${{ 'mariadb' == inputs.db-type && 'MariaDB' || 'MySQL' }}
uses: shogo82148/actions-setup-mysql@v1
with:
distribution: ${{ inputs.db-type }}
root-password: password
- name: Set up PHP ${{ inputs.php }}
uses: shivammathur/setup-php@2.31.1
with:
php-version: ${{ inputs.php }}
coverage: ${{ inputs.coverage && 'xdebug' || 'none' }}
env:
fail-fast: false
- name: Log debug information
run: |
php --version
composer --version
- name: Validate composer.json and composer.lock
run: composer validate --strict
- name: Install Composer dependencies
uses: ramsey/composer-install@v3
- name: Install appropriate PHPUnit
run: |
if [[ "${{ inputs.wp }}" == "4.9" || "${{ inputs.wp }}" == "5.0" ]]; then
composer require --dev phpunit/phpunit:^6 --with-dependencies
elif [[ "${{ inputs.wp }}" == "5.1" || "${{ inputs.wp }}" == "5.2" || "${{ inputs.wp }}" == "5.3" || "${{ inputs.wp }}" == "5.4" || "${{ inputs.wp }}" == "5.5" || "${{ inputs.wp }}" == "5.6" || "${{ inputs.wp }}" == "5.7" || "${{ inputs.wp }}" == "5.8" ]]; then
composer require --dev phpunit/phpunit:^7 --with-dependencies
else
composer require --dev phpunit/phpunit:^9 --with-dependencies
fi
- name: Install WordPress test setup
run: bash bin/install-wp-tests.sh wordpress root password 127.0.0.1:${{ job.services.mysql.ports[3306] }} ${{ inputs.wp }}
- name: Run PHPUnit tests (PHP ${{ inputs.php }} | WP ${{ inputs.wp }})
if: ${{ ! inputs.coverage }}
run: |
if [[ "${{ inputs.wordpress-translate-api-tests }}" == "true" ]]; then
composer exec -- phpunit --colors=always
else
composer exec -- phpunit --colors=always --exclude-group wordpress-translate-api
fi
- name: Run PHPUnit tests (PHP ${{ inputs.php }} | WP ${{ inputs.wp }})${{ inputs.wordpress-translate-api-tests && ' including Translate WordPress API' || '' }} with coverage
if: ${{ inputs.coverage }}
run: |
if [[ "${{ inputs.wordpress-translate-api-tests }}" == "true" ]]; then
composer exec -- phpunit --colors=always --coverage-clover coverage.xml
else
composer exec -- phpunit --colors=always --exclude-group wordpress-translate-api --coverage-clover coverage.xml
fi
- name: Upload coverage reports to Codecov
if: ${{ inputs.coverage }}
uses: codecov/codecov-action@v5.0.7
with:
file: coverage.xml
verbose: true
token: ${{ secrets.codecov-token }}
- name: Run codacy-coverage-reporter
if: ${{ inputs.coverage }}
uses: codacy/codacy-coverage-reporter-action@v1.3.0
with:
project-token: ${{ secrets.codacy-project-token }}
coverage-reports: coverage.xml