Skip to content

Commit 94f687b

Browse files
swissspidyCopilot
andauthored
Split functional & unit tests into reusable workflows (#228)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 8af7842 commit 94f687b

6 files changed

Lines changed: 249 additions & 229 deletions

File tree

.github/workflows/copilot-setup-steps.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ jobs:
3636

3737
- name: Install Composer dependencies & cache dependencies
3838
if: steps.check_composer_file.outputs.files_exists == 'true'
39-
uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # v3
39+
uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # v4
4040
env:
4141
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
42-
with:
43-
# Bust the cache at least once a month - output format: YYYY-MM.
44-
custom-cache-suffix: $(date -u "+%Y-%m")

.github/workflows/reusable-code-quality.yml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ jobs:
6363
uses: "ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda" # v3
6464
env:
6565
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
66-
with:
67-
# Bust the cache at least once a month - output format: YYYY-MM.
68-
custom-cache-suffix: $(date -u "+%Y-%m")
6966

7067
- name: Check existence of vendor/bin/parallel-lint file
7168
id: check_linter_file
@@ -151,9 +148,6 @@ jobs:
151148
uses: "ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda" # v3
152149
env:
153150
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
154-
with:
155-
# Bust the cache at least once a month - output format: YYYY-MM.
156-
custom-cache-suffix: $(date -u "+%Y-%m")
157151

158152
- name: Check existence of vendor/bin/phpcs file
159153
id: check_phpcs_binary_file
@@ -196,9 +190,7 @@ jobs:
196190
uses: "ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda" # v3
197191
env:
198192
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
199-
with:
200-
# Bust the cache at least once a month - output format: YYYY-MM.
201-
custom-cache-suffix: $(date -u "+%Y-%m")
193+
202194

203195
- name: Check existence of vendor/bin/phpstan file
204196
id: check_phpstan_binary_file
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
name: Functional testing
2+
on:
3+
workflow_call:
4+
inputs:
5+
php:
6+
type: string
7+
required: true
8+
wp:
9+
type: string
10+
required: true
11+
dbtype:
12+
type: string
13+
required: false
14+
default: 'mysql'
15+
mysql:
16+
type: string
17+
required: false
18+
default: ''
19+
object_cache:
20+
type: string
21+
required: false
22+
default: 'none'
23+
coverage:
24+
type: boolean
25+
required: false
26+
default: false
27+
os:
28+
type: string
29+
required: false
30+
default: 'ubuntu-22.04'
31+
32+
permissions:
33+
contents: read
34+
35+
jobs:
36+
functional:
37+
name: PHP ${{ inputs.php }} | WP ${{ inputs.wp }} | ${{ inputs.dbtype == 'sqlite' && 'SQLite' || inputs.dbtype == 'mariadb' && 'MariaDB' || 'MySQL' }}${{ inputs.object_cache == 'sqlite' && ' (Obj Cache)' || '' }}${{ inputs.coverage && ' (with coverage)' || '' }}${{ startsWith( inputs.os, 'windows' ) && ' (Windows)' || '' }}${{ startsWith( inputs.os, 'macos' ) && ' (macOS)' || '' }}
38+
runs-on: ${{ inputs.os || 'ubuntu-22.04' }}
39+
40+
continue-on-error: ${{ inputs.dbtype == 'sqlite' || inputs.dbtype == 'mariadb' || inputs.php == 'nightly' }}
41+
42+
env:
43+
MYSQL_HOST: 127.0.0.1
44+
MYSQL_TCP_PORT: 3306
45+
WP_CLI_TEST_DBROOTUSER: root
46+
WP_CLI_TEST_DBROOTPASS: root
47+
WP_CLI_TEST_DBNAME: wp_cli_test
48+
WP_CLI_TEST_DBUSER: wp_cli_test
49+
WP_CLI_TEST_DBPASS: password1
50+
WP_CLI_TEST_DBHOST: 127.0.0.1:3306
51+
WP_CLI_TEST_OBJECT_CACHE: ${{ inputs.object_cache }}
52+
53+
steps:
54+
- name: Check out source code
55+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
56+
57+
- name: Install Ghostscript
58+
if: ${{ inputs.os == 'ubuntu-22.04' || inputs.os == '' }}
59+
run: |
60+
sudo apt-get update
61+
sudo apt-get install ghostscript -y
62+
63+
- name: Set up PHP environment
64+
uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # v2
65+
with:
66+
php-version: '${{ inputs.php }}'
67+
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
68+
extensions: gd, imagick, mysql, zip, pdo_sqlite
69+
coverage: ${{ inputs.coverage && 'xdebug' || 'none' }}
70+
tools: composer
71+
env:
72+
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
73+
74+
- name: Change ImageMagick policy to allow pdf->png conversion.
75+
if: ${{ inputs.os == 'ubuntu-22.04' || inputs.os == '' }}
76+
run: |
77+
sudo sed -i 's/^.*policy.*coder.*none.*PDF.*//' /etc/ImageMagick-6/policy.xml
78+
79+
- name: Install Composer dependencies & cache dependencies
80+
uses: "ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda" # v3
81+
env:
82+
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
83+
84+
# MySQL 8.4 requires explicit loading of mysql_native_password plugin
85+
- name: Determine MySQL authentication configuration
86+
id: mysql-config
87+
if: ${{ inputs.dbtype != 'sqlite' && inputs.mysql == 'mysql-8.4' }}
88+
run: |
89+
echo "auth-config<<EOF" >> $GITHUB_OUTPUT
90+
echo "mysql_native_password=ON" >> $GITHUB_OUTPUT
91+
echo "authentication_policy=mysql_native_password," >> $GITHUB_OUTPUT
92+
echo "EOF" >> $GITHUB_OUTPUT
93+
94+
- name: Setup MySQL Server
95+
id: setup-mysql
96+
if: ${{ inputs.dbtype != 'sqlite' }}
97+
uses: shogo82148/actions-setup-mysql@840178c12b07a58353c6312be784c23b63756eea # v1
98+
with:
99+
mysql-version: ${{ inputs.mysql }}
100+
auto-start: true
101+
root-password: ${{ env.WP_CLI_TEST_DBROOTPASS }}
102+
user: ${{ env.WP_CLI_TEST_DBUSER}}
103+
password: ${{ env.WP_CLI_TEST_DBPASS}}
104+
# Fall back to legacy configuration for MySQL 5.6, 5.7, 8.0 and MariaDB.
105+
my-cnf: |
106+
${{ steps.mysql-config.outputs.auth-config || 'default_authentication_plugin=mysql_native_password' }}
107+
${{ inputs.dbtype == 'mariadb' && '[client]' || '' }}
108+
${{ inputs.dbtype == 'mariadb' && 'disable-ssl-verify-server-cert' || '' }}
109+
110+
- name: Prepare test database
111+
if: ${{ inputs.dbtype != 'sqlite' }}
112+
run: composer prepare-tests
113+
114+
- name: Check Behat environment
115+
env:
116+
WP_VERSION: '${{ inputs.wp }}'
117+
WP_CLI_TEST_DBTYPE: ${{ inputs.dbtype || 'mysql' }}
118+
WP_CLI_TEST_DBSOCKET: '${{ steps.setup-mysql.outputs.base-dir }}/tmp/mysql.sock'
119+
WP_CLI_TEST_DEBUG_BEHAT_ENV: 1
120+
run: composer behat
121+
122+
- name: Run Behat
123+
env:
124+
WP_VERSION: '${{ inputs.wp }}'
125+
WP_CLI_TEST_DBTYPE: ${{ inputs.dbtype || 'mysql' }}
126+
WP_CLI_TEST_DBSOCKET: '${{ steps.setup-mysql.outputs.base-dir }}/tmp/mysql.sock'
127+
WP_CLI_TEST_COVERAGE: ${{ inputs.coverage }}
128+
BEHAT_ARGS: ${{ format( '{0}', runner.debug && '--format=pretty' ) }}
129+
run: |
130+
composer behat -- $BEHAT_ARGS || composer behat-rerun -- $BEHAT_ARGS
131+
132+
- name: Retrieve list of coverage files
133+
id: coverage_files
134+
if: ${{ inputs.coverage }}
135+
run: |
136+
FILES=$(find "$GITHUB_WORKSPACE/build/logs" -path '*.*' | paste -s -d "," -)
137+
echo "files=$FILES" >> $GITHUB_OUTPUT
138+
139+
- name: Upload code coverage report
140+
if: ${{ inputs.coverage }}
141+
uses: codecov/codecov-action@1af58845a975a7985b0beb0cbe6fbbb71a41dbad # v5.5.3
142+
with:
143+
# Because somehow providing `directory: build/logs` doesn't work for these files
144+
files: ${{ steps.coverage_files.outputs.files }}
145+
flags: feature
146+
token: ${{ secrets.CODECOV_TOKEN }}

.github/workflows/reusable-regenerate-readme.yml

Lines changed: 8 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -40,31 +40,6 @@ jobs:
4040
uses: "ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda" # v3
4141
env:
4242
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
43-
with:
44-
# Bust the cache at least once a month - output format: YYYY-MM.
45-
custom-cache-suffix: $(date -u "+%Y-%m")
46-
47-
- name: Configure git user
48-
run: |
49-
git config --global user.email "github-actions[bot]@users.noreply.github.com"
50-
git config --global user.name "github-actions[bot]"
51-
52-
- name: Check if remote branch exists
53-
id: check_remote_branch
54-
run: |
55-
echo "exists=$(git ls-remote --exit-code --heads origin regenerate-readme &>/dev/null && echo "true" || echo "false")" >>"${GITHUB_OUTPUT}"
56-
57-
- name: Create branch to base pull request on
58-
if: ${{ steps.check_remote_branch.outputs.exists == 'false' }}
59-
run: |
60-
git checkout -b regenerate-readme
61-
62-
- name: Fetch existing branch to add commits to
63-
if: ${{ steps.check_remote_branch.outputs.exists == 'true' }}
64-
run: |
65-
git fetch --all --prune
66-
git checkout regenerate-readme
67-
git pull --no-rebase
6843

6944
- name: Install WP-CLI
7045
run: |
@@ -77,28 +52,16 @@ jobs:
7752
wp package install "wp-cli/scaffold-package-command:^2"
7853
wp scaffold package-readme --branch=${{ github.event.repository.default_branch }} --force .
7954
80-
- name: Check if there are changes
81-
id: check_changes
82-
run: |
83-
echo "detected=$(test -n "$(git status --porcelain 2>/dev/null)" && echo "true" || echo "false")" >>"${GITHUB_OUTPUT}"
84-
85-
- name: Commit changes
86-
if: ${{ steps.check_changes.outputs.detected == 'true' }}
87-
run: |
88-
git add README.md
89-
git commit -m "Regenerate README file - $(date +'%Y-%m-%d')"
90-
git push origin regenerate-readme
91-
9255
- name: Create pull request
93-
if: ${{ steps.check_changes.outputs.detected == 'true' && steps.check_remote_branch.outputs.exists == 'false' }}
94-
uses: repo-sync/pull-request@7e79a9f5dc3ad0ce53138f01df2fad14a04831c5 # v2
56+
uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0 # v8
9557
with:
96-
source_branch: regenerate-readme
97-
destination_branch: ${{ github.event.repository.default_branch }}
98-
github_token: ${{ secrets.GITHUB_TOKEN }}
99-
pr_title: Regenerate README file
100-
pr_body: |
58+
branch: regenerate-readme
59+
base: ${{ github.event.repository.default_branch }}
60+
token: ${{ secrets.GITHUB_TOKEN }}
61+
title: Regenerate README file
62+
body: |
10163
**This is an automated pull-request**
10264
10365
Refreshes the `README.md` file with the latest changes to the docblocks in the source code.
104-
pr_label: scope:documentation
66+
labels: scope:documentation
67+
commit-message: "Regenerate README file"

0 commit comments

Comments
 (0)