Skip to content

Commit

Permalink
Tools: Move from Travis CI to GitHub Actions for PR tests (#674)
Browse files Browse the repository at this point in the history
The WordPress project is moving away from Travis CI, so this migrates our CI checks to GitHub Actions. This only applies to automated linters and unit tests run on github PRs, nothing should change for local development.
  • Loading branch information
ryelle authored Dec 8, 2020
1 parent c90e1bc commit 997776a
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 56 deletions.
10 changes: 7 additions & 3 deletions .github/bin/phpcs-branch.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function run_phpcs( $file, $bin_dir ) {

function run_phpcs_changed( $file, $git, $base_branch, $bin_dir ) {
$name = basename( $file );
exec( "$git diff $base_branch HEAD $file > $name.diff" );
exec( "$git diff $base_branch $file > $name.diff" );
exec( "$git show $base_branch:$file | $bin_dir/phpcs --standard=./phpcs.xml.dist --report=json -nq > $name.orig.phpcs" );
exec( "cat $file | $bin_dir/phpcs --standard=./phpcs.xml.dist --report=json -nq > $name.phpcs" );

Expand All @@ -33,7 +33,7 @@ function run_phpcs_changed( $file, $git, $base_branch, $bin_dir ) {
}

function main() {
$base_branch = getenv( 'TRAVIS_BRANCH' );
$base_branch = 'remotes/origin/' . getenv( 'BASE_REF' );
$git_dir = dirname( dirname( __DIR__ ) );
$bin_dir = dirname( dirname( __DIR__ ) ) . '/public_html/wp-content/mu-plugins/vendor/bin';
$git = "git -C $git_dir";
Expand All @@ -42,10 +42,14 @@ function main() {
echo "\nScanning changed files...\n";
$status = 0;

$affected_files = shell_exec( "$git diff $base_branch...HEAD --name-status --diff-filter=AM 2>&1 | grep .php$" );
$affected_files = shell_exec( "$git diff $base_branch --name-status --diff-filter=AM 2>&1 | grep .php$" );
$affected_files = explode( "\n", trim( $affected_files ) );

foreach ( $affected_files as $record ) {
if ( ! $record ) {
continue;
}

list( $change, $file ) = explode( "\t", trim( $record ) );
$cmd_status = 0;

Expand Down
50 changes: 50 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Static Analysis (Linting)

# Run on any changes in public_html
on:
pull_request:
paths:
- public_html/**
push:
branches: [production]
paths:
- public_html/**

jobs:
check:
name: All

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- uses: actions/cache@v2
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}

- name: Use Node.js 12.x
uses: actions/setup-node@v2-beta
with:
node-version: 12.x

- name: composer install
run: |
composer install
- name: yarn install and build
run: |
yarn
yarn workspaces run build
- name: Lint JavaScript and Styles
run: |
yarn workspaces run lint:js
yarn workspaces run lint:css
- name: Lint PHP
run: |
BASE_REF=${{ github.base_ref }} php .github/bin/phpcs-branch.php
86 changes: 86 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Unit Tests

# Run on any changes in public_html
on:
pull_request:
paths:
- public_html/**
push:
branches: [production]
paths:
- public_html/**

jobs:
unit-js:
name: JavaScript

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- uses: actions/cache@v2
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}

- name: Use Node.js 12.x
uses: actions/setup-node@v2-beta
with:
node-version: 12.x

- name: Install dependencies
# We don't need to build, since jest can interpret the source files.
run: yarn

# Run the Blocks unit tests. If/when other workspaces get tests, those would be added here.
- name: Running the tests
run: yarn workspace wordcamp-blocks run test

unit-php:
name: PHP Tests

runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
php-version: ['7.4'] # 8.0 -- Add back to matrix when 8.0 is supported.

services:
mysql:
image: mysql:5.7
env:
MYSQL_ALLOW_EMPTY_PASSWORD: false
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: wcorg_test
ports:
- 3306/tcp
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

steps:
- uses: actions/checkout@v2

- name: Set PHP version
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
coverage: none
tools: composer:v1

- name: Start mysql service
run: sudo /etc/init.d/mysql start

- name: Install dependencies
run: composer install

- name: Install WordPress
run: |
bash .docker/bin/install-wp-tests.sh wcorg_test root root 127.0.0.1 trunk
- name: Install required plugins
run: |
svn export https://plugins.svn.wordpress.org/jetpack/trunk public_html/wp-content/plugins/jetpack
- name: Running unit tests
run: ./public_html/wp-content/mu-plugins/vendor/bin/phpunit -c phpunit.xml.dist
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
lts/*
12
52 changes: 0 additions & 52 deletions .travis.yml

This file was deleted.

0 comments on commit 997776a

Please sign in to comment.