Skip to content

Commit 47cb9fc

Browse files
feat: add re-usable GitHub action
Define a re-usable GitHub action based on the existing workflow file. This action can be used in other repositories (running schedules pipelines) to repeatedly and regularly run the WordPress test suite on remote hosts.
1 parent 653f965 commit 47cb9fc

File tree

1 file changed

+136
-0
lines changed

1 file changed

+136
-0
lines changed
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
name: WordPress Host Test
2+
description: >
3+
Run the WordPress Host Test on a remote system reachable via SSH
4+
5+
inputs:
6+
report-api-key:
7+
description: >
8+
API key for reporting test results back to wordpress.org; if omitted,
9+
test result reporting will be skipped.
10+
required: false
11+
remote-test-dir:
12+
description: >
13+
Remote directory in which tests will be run
14+
required: true
15+
database-host:
16+
description: >
17+
Database host for running the unit tests
18+
required: true
19+
database-user:
20+
description: >
21+
Database user for running the unit tests
22+
required: true
23+
database-password:
24+
description: >
25+
Database password for running the unit tests
26+
required: true
27+
database-name:
28+
description: >
29+
Database name for running the unit tests
30+
required: true
31+
ssh-connect:
32+
description: >
33+
SSH connection string (in the format username@host) for connecting to the
34+
hosting environment under test.
35+
required: true
36+
ssh-private-key:
37+
description: >
38+
A base64-encoded SSH private key.
39+
required: true
40+
test-filter:
41+
description: A regular expression to filter tests that should be run.
42+
default: '.*'
43+
runs:
44+
using: "composite"
45+
steps:
46+
- name: Checkout repository
47+
uses: actions/checkout@v4
48+
with:
49+
repository: WordPress/phpunit-test-runner
50+
path: runner
51+
52+
- name: Set up PHP
53+
uses: shivammathur/setup-php@cf4cade2721270509d5b1c766ab3549210a39a2a # v2.33.0
54+
with:
55+
php-version: '8.4'
56+
coverage: none
57+
58+
- name: Install NodeJS
59+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
60+
with:
61+
node-version: 20
62+
63+
- name: Prepare SSH private key
64+
shell: bash
65+
if: ${{ inputs.ssh-private-key }}
66+
run: |
67+
mkdir -p ~/.ssh
68+
echo '${{ inputs.ssh-private-key }}' | base64 -d > ~/.ssh/id_rsa
69+
chmod 600 ~/.ssh/id_rsa
70+
71+
- name: Test SSH connectivity
72+
shell: bash
73+
run: |
74+
ssh -o StrictHostKeyChecking=no ${{ inputs.ssh-connect }} whoami
75+
76+
- name: Prepare environment
77+
env:
78+
WPT_PREPARE_DIR: /tmp/wp-tests
79+
WPT_TEST_DIR: ${{ inputs.remote-test-dir }}
80+
WPT_DB_NAME: ${{ inputs.database-name }}
81+
WPT_DB_USER: ${{ inputs.database-user }}
82+
WPT_DB_PASSWORD: ${{ inputs.database-password }}
83+
WPT_DB_HOST: ${{ inputs.database-host }}
84+
WPT_SSH_CONNECT: ${{ inputs.ssh-connect }}
85+
run: php prepare.php
86+
shell: bash
87+
working-directory: ./runner
88+
89+
- name: Run unit tests
90+
run: php test.php
91+
continue-on-error: true
92+
shell: bash
93+
working-directory: ./runner
94+
env:
95+
WPT_PREPARE_DIR: /tmp/wp-tests
96+
WPT_TEST_DIR: ${{ inputs.remote-test-dir }}
97+
WPT_DB_NAME: ${{ inputs.database-name }}
98+
WPT_DB_USER: ${{ inputs.database-user }}
99+
WPT_DB_PASSWORD: ${{ inputs.database-password }}
100+
WPT_DB_HOST: ${{ inputs.database-host }}
101+
WPT_SSH_CONNECT: ${{ inputs.ssh-connect }}
102+
WPT_PHPUNIT_CMD: >
103+
cd ${{ inputs.remote-test-dir }} &&
104+
./vendor/phpunit/phpunit/phpunit
105+
--dont-report-useless-tests
106+
-c tests/phpunit/multisite.xml
107+
--filter '${{ inputs.test-filter }}'
108+
109+
- name: Report the results
110+
run: php report.php
111+
continue-on-error: true
112+
if: ${{ inputs.report-api-key }}
113+
shell: bash
114+
working-directory: ./runner
115+
env:
116+
WPT_REPORT_API_KEY: ${{ inputs.report-api-key }}
117+
WPT_PREPARE_DIR: /tmp/wp-tests
118+
WPT_TEST_DIR: ${{ inputs.remote-test-dir }}
119+
WPT_DB_NAME: ${{ inputs.database-name }}
120+
WPT_DB_USER: ${{ inputs.database-user }}
121+
WPT_DB_PASSWORD: ${{ inputs.database-password }}
122+
WPT_DB_HOST: ${{ inputs.database-host }}
123+
WPT_SSH_CONNECT: ${{ inputs.ssh-connect }}
124+
125+
- name: Cleanup
126+
run: php cleanup.php
127+
shell: bash
128+
working-directory: ./runner
129+
env:
130+
WPT_PREPARE_DIR: /tmp/wp-tests
131+
WPT_TEST_DIR: ${{ inputs.remote-test-dir }}
132+
WPT_DB_NAME: ${{ inputs.database-name }}
133+
WPT_DB_USER: ${{ inputs.database-user }}
134+
WPT_DB_PASSWORD: ${{ inputs.database-password }}
135+
WPT_DB_HOST: ${{ inputs.database-host }}
136+
WPT_SSH_CONNECT: ${{ inputs.ssh-connect }}

0 commit comments

Comments
 (0)