Skip to content

Commit 934cfde

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 934cfde

File tree

1 file changed

+137
-0
lines changed

1 file changed

+137
-0
lines changed
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
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+
ls -al ~/.ssh/id_rsa
71+
72+
- name: Test SSH connectivity
73+
shell: bash
74+
run: |
75+
ssh -o StrictHostKeyChecking=no ${{ inputs.ssh-connect }} whoami
76+
77+
- name: Prepare environment
78+
env:
79+
WPT_PREPARE_DIR: /tmp/wp-tests
80+
WPT_TEST_DIR: ${{ inputs.remote-test-dir }}
81+
WPT_DB_NAME: ${{ inputs.database-name }}
82+
WPT_DB_USER: ${{ inputs.database-user }}
83+
WPT_DB_PASSWORD: ${{ inputs.database-password }}
84+
WPT_DB_HOST: ${{ inputs.database-host }}
85+
WPT_SSH_CONNECT: ${{ inputs.ssh-connect }}
86+
run: php prepare.php
87+
shell: bash
88+
working-directory: ./runner
89+
90+
- name: Run unit tests
91+
run: php test.php
92+
continue-on-error: true
93+
shell: bash
94+
working-directory: ./runner
95+
env:
96+
WPT_PREPARE_DIR: /tmp/wp-tests
97+
WPT_TEST_DIR: ${{ inputs.remote-test-dir }}
98+
WPT_DB_NAME: ${{ inputs.database-name }}
99+
WPT_DB_USER: ${{ inputs.database-user }}
100+
WPT_DB_PASSWORD: ${{ inputs.database-password }}
101+
WPT_DB_HOST: ${{ inputs.database-host }}
102+
WPT_SSH_CONNECT: ${{ inputs.ssh-connect }}
103+
WPT_PHPUNIT_CMD: >
104+
cd ${{ inputs.remote-test-dir }} &&
105+
./vendor/phpunit/phpunit/phpunit
106+
--dont-report-useless-tests
107+
-c tests/phpunit/multisite.xml
108+
--filter '${{ inputs.test-filter }}'
109+
110+
- name: Report the results
111+
run: php report.php
112+
continue-on-error: true
113+
if: ${{ inputs.report-api-key }}
114+
shell: bash
115+
working-directory: ./runner
116+
env:
117+
WPT_REPORT_API_KEY: ${{ inputs.report-api-key }}
118+
WPT_PREPARE_DIR: /tmp/wp-tests
119+
WPT_TEST_DIR: ${{ inputs.remote-test-dir }}
120+
WPT_DB_NAME: ${{ inputs.database-name }}
121+
WPT_DB_USER: ${{ inputs.database-user }}
122+
WPT_DB_PASSWORD: ${{ inputs.database-password }}
123+
WPT_DB_HOST: ${{ inputs.database-host }}
124+
WPT_SSH_CONNECT: ${{ inputs.ssh-connect }}
125+
126+
- name: Cleanup
127+
run: php cleanup.php
128+
shell: bash
129+
working-directory: ./runner
130+
env:
131+
WPT_PREPARE_DIR: /tmp/wp-tests
132+
WPT_TEST_DIR: ${{ inputs.remote-test-dir }}
133+
WPT_DB_NAME: ${{ inputs.database-name }}
134+
WPT_DB_USER: ${{ inputs.database-user }}
135+
WPT_DB_PASSWORD: ${{ inputs.database-password }}
136+
WPT_DB_HOST: ${{ inputs.database-host }}
137+
WPT_SSH_CONNECT: ${{ inputs.ssh-connect }}

0 commit comments

Comments
 (0)