Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to GitHub Actions #143

Merged
merged 19 commits into from
Sep 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
91 changes: 91 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: WordPress PHPUnit tests

on:
# The workflow should be run on a schedule using the 'schedule' event trigger.
#
# For more details on how to configure the schedule event, see https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#onschedule.
#
# Below are some options for different schedules. Running the tests every hour is recommended,
# but every 3-6 hours is also helpful. Times are in UTC.
schedule:
# By default, the workflow will run every hour.
- cron: '0 * * * *'
# Every 3 hours.
# - cron: '0 0/3 * * *'
# Every 6 hours.
# - cron: '0 0/6 * * *'
# Every 12 hours.
# - cron: '0 0/12 * * *'
# Once per day at 00:00.
# - cron: '0 0 * * *'
# Every 30 minutes.
# - cron: '0/30 * * * *'

# Cancels all previous workflow runs for pull requests that have not completed.
concurrency:
# The concurrency group contains the workflow name and the branch name for pull requests
# or the commit hash for any other events.
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
cancel-in-progress: true

jobs:
# Tests the PHPUnit test runner.
#
# Performs the following steps:
# - Checks out the repository.
# - Installs PHP.
# - Installs NodeJS 14 with caching configured.
# - Prepares the environment for tests.
# - Runs the tests.
# - Reports the results.
# - Cleans up.
test:
name: Run Core PHPUnit tests
runs-on: ubuntu-latest

# Remove this line if Github Actions is your preferred means of running the tests.
if: never()

env:
# This is only a subset/example of env vars available. See the `.env.default` file for a full list.
WPT_PREPARE_DIR: ${{ secrets.WPT_PREPARE_DIR }}
WPT_TEST_DIR: ${{ secrets.WPT_TEST_DIR }}
WPT_REPORT_API_KEY: ${{ secrets.WPT_REPORT_API_KEY }}
WPT_PHP_EXECUTABLE: ${{ secrets.WPT_PHP_EXECUTABLE }}
# Database settings
WPT_DB_NAME: ${{ secrets.WPT_DB_NAME }}
WPT_DB_USER: ${{ secrets.WPT_DB_USER }}
WPT_DB_PASSWORD: ${{ secrets.WPT_DB_PASSWORD }}
WPT_DB_HOST: ${{ secrets.WPT_DB_HOST }}
# SSH settings for connecting to the test environment.
WPT_SSH_CONNECT: ${{ secrets.WPT_SSH_CONNECT }}
WPT_SSH_PRIVATE_KEY_BASE64: ${{ secrets.WPT_SSH_PRIVATE_KEY_BASE64 }}

steps:
- name: Checkout repository
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # v2.3.4

- name: Set up PHP
uses: shivammathur/setup-php@947009a71769c25ab5292f073f5343624b7c879d # v2.12.0
with:
php-version: '7.4'
coverage: none

- name: Install NodeJS
uses: actions/setup-node@25316bbc1f10ac9d8798711f44914b1cf3c4e954 # v2.4.0
with:
node-version: 14

pfefferle marked this conversation as resolved.
Show resolved Hide resolved
- name: Prepare environment
run: php prepare.php

- name: Run unit tests
run: php test.php
# Prevent the workflow from stopping if there are test failures.
continue-on-error: true

- name: Report the results
run: php report.php

- name: Cleanup
run: php cleanup.php
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ At a high level, the test suite runner:

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

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

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.
Expand Down
3 changes: 3 additions & 0 deletions prepare.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
$WPT_SSH_PRIVATE_KEY_BASE64 = getenv( 'WPT_SSH_PRIVATE_KEY_BASE64' );
if ( ! empty( $WPT_SSH_PRIVATE_KEY_BASE64 ) ) {
log_message( 'Securely extracting WPT_SSH_PRIVATE_KEY_BASE64 into ~/.ssh/id_rsa' );
if ( ! is_dir( getenv( 'HOME' ) . '/.ssh' ) ) {
mkdir( getenv( 'HOME' ) . '/.ssh', 0777, true );
}
file_put_contents( getenv( 'HOME' ) . '/.ssh/id_rsa', base64_decode( $WPT_SSH_PRIVATE_KEY_BASE64 ) );
perform_operations( array(
'chmod 600 ~/.ssh/id_rsa',
Expand Down