Skip to content

Commit 9957fe4

Browse files
authored
Merge pull request #143 from WordPress/switch-to-github-actions
Switch to GitHub Actions
2 parents 4507c9a + bc5bd6d commit 9957fe4

File tree

3 files changed

+95
-1
lines changed

3 files changed

+95
-1
lines changed

.github/workflows/tests.yml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: WordPress PHPUnit tests
2+
3+
on:
4+
# The workflow should be run on a schedule using the 'schedule' event trigger.
5+
#
6+
# For more details on how to configure the schedule event, see https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#onschedule.
7+
#
8+
# Below are some options for different schedules. Running the tests every hour is recommended,
9+
# but every 3-6 hours is also helpful. Times are in UTC.
10+
schedule:
11+
# By default, the workflow will run every hour.
12+
- cron: '0 * * * *'
13+
# Every 3 hours.
14+
# - cron: '0 0/3 * * *'
15+
# Every 6 hours.
16+
# - cron: '0 0/6 * * *'
17+
# Every 12 hours.
18+
# - cron: '0 0/12 * * *'
19+
# Once per day at 00:00.
20+
# - cron: '0 0 * * *'
21+
# Every 30 minutes.
22+
# - cron: '0/30 * * * *'
23+
24+
# Cancels all previous workflow runs for pull requests that have not completed.
25+
concurrency:
26+
# The concurrency group contains the workflow name and the branch name for pull requests
27+
# or the commit hash for any other events.
28+
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
29+
cancel-in-progress: true
30+
31+
jobs:
32+
# Tests the PHPUnit test runner.
33+
#
34+
# Performs the following steps:
35+
# - Checks out the repository.
36+
# - Installs PHP.
37+
# - Installs NodeJS 14 with caching configured.
38+
# - Prepares the environment for tests.
39+
# - Runs the tests.
40+
# - Reports the results.
41+
# - Cleans up.
42+
test:
43+
name: Run Core PHPUnit tests
44+
runs-on: ubuntu-latest
45+
46+
# Remove this line if Github Actions is your preferred means of running the tests.
47+
if: never()
48+
49+
env:
50+
# This is only a subset/example of env vars available. See the `.env.default` file for a full list.
51+
WPT_PREPARE_DIR: ${{ secrets.WPT_PREPARE_DIR }}
52+
WPT_TEST_DIR: ${{ secrets.WPT_TEST_DIR }}
53+
WPT_REPORT_API_KEY: ${{ secrets.WPT_REPORT_API_KEY }}
54+
WPT_PHP_EXECUTABLE: ${{ secrets.WPT_PHP_EXECUTABLE }}
55+
# Database settings
56+
WPT_DB_NAME: ${{ secrets.WPT_DB_NAME }}
57+
WPT_DB_USER: ${{ secrets.WPT_DB_USER }}
58+
WPT_DB_PASSWORD: ${{ secrets.WPT_DB_PASSWORD }}
59+
WPT_DB_HOST: ${{ secrets.WPT_DB_HOST }}
60+
# SSH settings for connecting to the test environment.
61+
WPT_SSH_CONNECT: ${{ secrets.WPT_SSH_CONNECT }}
62+
WPT_SSH_PRIVATE_KEY_BASE64: ${{ secrets.WPT_SSH_PRIVATE_KEY_BASE64 }}
63+
64+
steps:
65+
- name: Checkout repository
66+
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # v2.3.4
67+
68+
- name: Set up PHP
69+
uses: shivammathur/setup-php@947009a71769c25ab5292f073f5343624b7c879d # v2.12.0
70+
with:
71+
php-version: '7.4'
72+
coverage: none
73+
74+
- name: Install NodeJS
75+
uses: actions/setup-node@25316bbc1f10ac9d8798711f44914b1cf3c4e954 # v2.4.0
76+
with:
77+
node-version: 14
78+
79+
- name: Prepare environment
80+
run: php prepare.php
81+
82+
- name: Run unit tests
83+
run: php test.php
84+
# Prevent the workflow from stopping if there are test failures.
85+
continue-on-error: true
86+
87+
- name: Report the results
88+
run: php report.php
89+
90+
- name: Cleanup
91+
run: php cleanup.php

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ At a high level, the test suite runner:
1717

1818
The test suite runner can be used in one of two ways:
1919

20-
1. With Travis (or Circle or some other CI service) as the controller that connects to the remote test environment.
20+
1. With GitHub Actions, (or Travis, Circle, or another CI service) as the controller that connects to the remote test environment.
2121
2. With the runner cloned to and run directly within the test environment.
2222

2323
The test runner is configured through environment variables, documented in [`.env.default`](.env.default). It shouldn't need any code modifications; in fact, please refrain from editing the scripts entirely, as it will make it easier to stay up to date.

prepare.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
$WPT_SSH_PRIVATE_KEY_BASE64 = getenv( 'WPT_SSH_PRIVATE_KEY_BASE64' );
2222
if ( ! empty( $WPT_SSH_PRIVATE_KEY_BASE64 ) ) {
2323
log_message( 'Securely extracting WPT_SSH_PRIVATE_KEY_BASE64 into ~/.ssh/id_rsa' );
24+
if ( ! is_dir( getenv( 'HOME' ) . '/.ssh' ) ) {
25+
mkdir( getenv( 'HOME' ) . '/.ssh', 0777, true );
26+
}
2427
file_put_contents( getenv( 'HOME' ) . '/.ssh/id_rsa', base64_decode( $WPT_SSH_PRIVATE_KEY_BASE64 ) );
2528
perform_operations( array(
2629
'chmod 600 ~/.ssh/id_rsa',

0 commit comments

Comments
 (0)