Skip to content

Commit 0086fd4

Browse files
committed
Rework reusable-testing
1 parent 782d5ef commit 0086fd4

File tree

2 files changed

+58
-41
lines changed

2 files changed

+58
-41
lines changed

.github/workflows/reusable-testing.yml

Lines changed: 56 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,7 @@ concurrency:
1111

1212
jobs:
1313

14-
unit: #-----------------------------------------------------------------------
15-
name: Unit test / PHP ${{ matrix.php }}
16-
strategy:
17-
fail-fast: false
18-
matrix:
19-
php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2']
14+
has_unit_tests:
2015
runs-on: ubuntu-20.04
2116

2217
steps:
@@ -29,8 +24,26 @@ jobs:
2924
with:
3025
files: "composer.json, phpunit.xml.dist"
3126

27+
outputs:
28+
exists: ${{ steps.check_files.outputs.files_exists }}
29+
30+
unit:
31+
name: Unit tests on PHP ${{ matrix.php }}
32+
needs:
33+
- has_unit_tests
34+
if: ${{ needs.has_unit_tests.outputs.exists == 'true' }}
35+
strategy:
36+
fail-fast: false
37+
matrix:
38+
php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2']
39+
runs-on: ubuntu-20.04
40+
41+
steps:
42+
- name: Check out source code
43+
uses: actions/checkout@v3
44+
3245
- name: Set up PHP environment (PHP 5.6 - 7.1)
33-
if: ${{ matrix.php < '7.2' && steps.check_files.outputs.files_exists == 'true'}}
46+
if: ${{ matrix.php < '7.2' }}
3447
uses: shivammathur/setup-php@v2
3548
with:
3649
php-version: '${{ matrix.php }}'
@@ -41,35 +54,52 @@ jobs:
4154
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4255

4356
- name: Set up PHP environment (PHP 7.2+)
44-
if: ${{ matrix.php >= '7.2' && steps.check_files.outputs.files_exists == 'true'}}
57+
if: ${{ matrix.php >= '7.2' }}
58+
env:
59+
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4560
uses: shivammathur/setup-php@v2
4661
with:
4762
php-version: '${{ matrix.php }}'
4863
coverage: none
4964
tools: composer,cs2pr
50-
env:
51-
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5265

5366
- name: Install Composer dependencies & cache dependencies
54-
if: steps.check_files.outputs.files_exists == 'true'
55-
uses: "ramsey/composer-install@v2"
5667
env:
5768
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
69+
uses: "ramsey/composer-install@v2"
5870
with:
5971
# Bust the cache at least once a month - output format: YYYY-MM.
60-
custom-cache-suffix: $(date -u "+%Y-%m")
72+
custom-cache-suffix: |
73+
$(date -u "+%Y-%m")
6174
6275
- name: Setup problem matcher to provide annotations for PHPUnit
63-
if: steps.check_files.outputs.files_exists == 'true'
6476
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
6577

6678
- name: Run PHPUnit
67-
if: steps.check_files.outputs.files_exists == 'true'
68-
continue-on-error: ${{ matrix.php == '8.2' }}
6979
run: composer phpunit
80+
continue-on-error: ${{ matrix.php == '8.2' }}
81+
82+
has_functional_tests:
83+
runs-on: ubuntu-20.04
7084

71-
functional: #----------------------------------------------------------------------
85+
steps:
86+
- name: Check out source code
87+
uses: actions/checkout@v3
88+
89+
- name: Check existence of composer.json & behat.yml files
90+
id: check_files
91+
uses: andstor/file-existence-action@v2
92+
with:
93+
files: "composer.json, behat.yml"
94+
95+
outputs:
96+
exists: ${{ steps.check_files.outputs.files_exists }}
97+
98+
functional:
7299
name: Functional - WP ${{ matrix.wp }} on PHP ${{ matrix.php }} with MySQL ${{ matrix.mysql }}
100+
needs:
101+
- has_functional_tests
102+
if: ${{ needs.has_functional_tests.outputs.exists == 'true' }}
73103
strategy:
74104
fail-fast: false
75105
matrix:
@@ -114,55 +144,45 @@ jobs:
114144
image: mysql:${{ matrix.mysql }}
115145
ports:
116146
- 3306
117-
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=wp_cli_test --entrypoint sh mysql:${{ matrix.mysql }} -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password"
147+
options: |
148+
--health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=wp_cli_test --entrypoint sh mysql:${{ matrix.mysql }} -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password"
118149
119150
steps:
120151
- name: Check out source code
121152
uses: actions/checkout@v3
122153

123-
- name: Check existence of composer.json & behat.yml files
124-
id: check_files
125-
uses: andstor/file-existence-action@v2
126-
with:
127-
files: "composer.json, behat.yml"
128-
129154
- name: Install Ghostscript
130-
if: steps.check_files.outputs.files_exists == 'true'
131155
run: |
132156
sudo apt-get update
133-
sudo apt-get install ghostscript -y
157+
sudo apt-get install -y ghostscript
134158
135159
- name: Set up PHP environment
136-
if: steps.check_files.outputs.files_exists == 'true'
160+
env:
161+
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
137162
uses: shivammathur/setup-php@v2
138163
with:
139164
php-version: '${{ matrix.php }}'
140165
extensions: gd, imagick, mysql, zip
141166
coverage: none
142167
tools: composer
143-
env:
144-
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
145168

146169
- name: Change ImageMagick policy to allow pdf->png conversion.
147-
if: steps.check_files.outputs.files_exists == 'true'
148170
run: |
149171
sudo sed -i 's/^.*policy.*coder.*none.*PDF.*//' /etc/ImageMagick-6/policy.xml
150172
151173
- name: Install Composer dependencies & cache dependencies
152-
if: steps.check_files.outputs.files_exists == 'true'
153-
uses: "ramsey/composer-install@v2"
154174
env:
155175
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
176+
uses: "ramsey/composer-install@v2"
156177
with:
157178
# Bust the cache at least once a month - output format: YYYY-MM.
158-
custom-cache-suffix: $(date -u "+%Y-%m")
179+
custom-cache-suffix: |
180+
$(date -u "+%Y-%m")
159181
160182
- name: Start MySQL server
161-
if: steps.check_files.outputs.files_exists == 'true'
162183
run: sudo systemctl start mysql
163184

164185
- name: Configure DB environment
165-
if: steps.check_files.outputs.files_exists == 'true'
166186
run: |
167187
echo "MYSQL_HOST=127.0.0.1" >> $GITHUB_ENV
168188
echo "MYSQL_TCP_PORT=${{ job.services.mysql.ports['3306'] }}" >> $GITHUB_ENV
@@ -174,18 +194,15 @@ jobs:
174194
echo "WP_CLI_TEST_DBHOST=127.0.0.1:${{ job.services.mysql.ports['3306'] }}" >> $GITHUB_ENV
175195
176196
- name: Prepare test database
177-
if: steps.check_files.outputs.files_exists == 'true'
178197
run: composer prepare-tests
179198

180199
- name: Check Behat environment
181-
if: steps.check_files.outputs.files_exists == 'true'
182200
env:
183201
WP_VERSION: '${{ matrix.wp }}'
184202
run: WP_CLI_TEST_DEBUG_BEHAT_ENV=1 composer behat
185203

186204
- name: Run Behat
187-
if: steps.check_files.outputs.files_exists == 'true'
188-
continue-on-error: ${{ matrix.php == '8.2' }}
189205
env:
190206
WP_VERSION: '${{ matrix.wp }}'
191207
run: composer behat || composer behat-rerun
208+
continue-on-error: ${{ matrix.php == '8.2' }}

.github/workflows/sync-workflows.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111

1212
jobs:
1313

14-
sync-workflows: #-------------------------------------------------------------
14+
sync-workflows:
1515
name: Sync GitHub Actions workflows
1616
runs-on: ubuntu-latest
1717
if: ${{ github.repository_owner == 'wp-cli' }}
@@ -68,7 +68,7 @@ jobs:
6868
wp-cli/wp-super-cache-cli
6969
GITHUB_TOKEN: ${{ secrets.ACTIONS_BOT }}
7070

71-
sync-dependabot: #------------------------------------------------------------
71+
sync-dependabot:
7272
name: Sync Dependabot configuration
7373
runs-on: ubuntu-latest
7474
if: ${{ github.repository_owner == 'wp-cli' }}

0 commit comments

Comments
 (0)