-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #354 from GoogleChromeLabs/eliminate-travis
Eliminate Travis in favor of GitHub Actions for linting and testing
- Loading branch information
Showing
14 changed files
with
26,048 additions
and
8,604 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,233 @@ | ||
name: Build, test & measure | ||
|
||
on: | ||
push: | ||
branches: | ||
- develop | ||
# Include all release branches. | ||
- '[0-9]+.[0-9]+' | ||
pull_request: | ||
# Run workflow whenever a PR is opened, updated (synchronized), or marked ready for review. | ||
types: [opened, synchronize, ready_for_review] | ||
|
||
jobs: | ||
|
||
lint-js: | ||
name: 'Lint: JS' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Get npm cache directory | ||
id: npm-cache | ||
run: echo "::set-output name=dir::$(npm config get cache)" | ||
|
||
- name: Configure npm cache | ||
uses: actions/cache@v2 | ||
with: | ||
path: ${{ steps.npm-cache.outputs.dir }} | ||
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }} | ||
restore-keys: | | ||
${{ runner.os }}-npm- | ||
- name: Install Node dependencies | ||
run: npm ci | ||
env: | ||
CI: true | ||
|
||
- name: Validate package.json | ||
run: npm run lint:pkg-json | ||
|
||
- name: Detect coding standard violations (ESLint) | ||
run: npm run lint:js:report | ||
continue-on-error: true | ||
|
||
- name: Annotate code linting results | ||
# The action cannot annotate the PR diff when run from a PR fork | ||
if: github.event.pull_request.head.repo.fork == false | ||
uses: ataylorme/[email protected] | ||
with: | ||
repo-token: '${{ secrets.GITHUB_TOKEN }}' | ||
report-json: 'lint-js-report.json' | ||
|
||
#----------------------------------------------------------------------------------------------------------------------- | ||
|
||
lint-php: | ||
name: 'Lint: PHP' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: '7.4' | ||
coverage: none | ||
tools: cs2pr | ||
|
||
- name: Get Composer Cache Directory | ||
id: composer-cache | ||
run: echo "::set-output name=dir::$(composer config cache-files-dir)" | ||
|
||
- name: Configure Composer cache | ||
uses: actions/cache@v2 | ||
with: | ||
path: ${{ steps.composer-cache.outputs.dir }} | ||
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-composer- | ||
- name: Install Composer dependencies | ||
run: composer install --prefer-dist --optimize-autoloader --no-progress --no-interaction | ||
|
||
- name: Validate composer.json | ||
run: composer --no-interaction validate --no-check-all | ||
|
||
- name: Detect coding standard violations (PHPCS) | ||
run: vendor/bin/phpcs -q --report=checkstyle --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 | cs2pr --graceful-warnings | ||
|
||
- name: Normalize composer.json | ||
run: | | ||
composer require --no-interaction --dev ergebnis/composer-normalize --ignore-platform-reqs | ||
composer --no-interaction normalize --dry-run | ||
#----------------------------------------------------------------------------------------------------------------------- | ||
|
||
# Adapted from workflow for running PHP unit tests on google/web-stories-wp. | ||
# See https://github.com/google/web-stories-wp/blob/cb2ebada48039171e25c279bdb27d3712dd70b22/.github/workflows/continuous-integration-unit-php.yml | ||
unit-test-php: | ||
name: "Unit test${{ matrix.coverage && ' (with coverage)' || '' }}: PHP ${{ matrix.php }}, WP ${{ matrix.wp }}" | ||
runs-on: ubuntu-latest | ||
env: | ||
WP_CORE_DIR: /tmp/wordpress | ||
services: | ||
mysql: | ||
image: mariadb:latest | ||
env: | ||
MYSQL_ALLOW_EMPTY_PASSWORD: true | ||
MYSQL_ROOT_PASSWORD: | ||
MYSQL_DATABASE: wordpress_test | ||
ports: | ||
- 3306 | ||
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 | ||
continue-on-error: ${{ matrix.experimental == true }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
coverage: [false] | ||
php: ['7.3', '7.2', '7.1'] | ||
wp: ['latest'] | ||
include: | ||
- php: '8.0' | ||
wp: 'trunk' | ||
experimental: true | ||
coverage: false | ||
|
||
- php: '7.4' | ||
wp: 'latest' | ||
coverage: true | ||
|
||
- php: '7.3' | ||
wp: 'latest' | ||
coverage: false | ||
|
||
- php: '7.2' | ||
wp: 'latest' | ||
coverage: false | ||
|
||
- php: '5.6' | ||
wp: 'latest' | ||
coverage: false | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
extensions: curl, date, dom, gd, iconv, json, libxml, mysql, spl | ||
coverage: ${{ matrix.coverage && 'pcov' || 'none' }} | ||
ini-values: pcov.directory=. | ||
|
||
- name: Shutdown default MySQL service | ||
run: sudo service mysql stop | ||
|
||
- name: Verify MariaDB connection | ||
run: | | ||
while ! mysqladmin ping -h"127.0.0.1" -P"${{ job.services.mysql.ports[3306] }}" --silent; do | ||
sleep 1 | ||
done | ||
- name: Get Composer Cache Directory | ||
id: composer-cache | ||
run: echo "::set-output name=dir::$(composer config cache-files-dir)" | ||
|
||
- name: Configure Composer cache | ||
uses: actions/cache@v2 | ||
with: | ||
path: ${{ steps.composer-cache.outputs.dir }} | ||
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-composer- | ||
- name: Install Composer dependencies | ||
run: composer install --prefer-dist --ignore-platform-reqs --no-progress --no-interaction | ||
|
||
- name: Get npm cache directory | ||
id: npm-cache | ||
run: echo "::set-output name=dir::$(npm config get cache)" | ||
|
||
- name: Configure npm cache | ||
uses: actions/cache@v2 | ||
with: | ||
path: ${{ steps.npm-cache.outputs.dir }} | ||
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }} | ||
restore-keys: | | ||
${{ runner.os }}-npm- | ||
- name: Install Node dependencies | ||
run: npm ci | ||
env: | ||
CI: true | ||
|
||
- name: Build plugin | ||
run: npm run build | ||
|
||
# Scan the logs for failing tests and surface that information by creating annotations and log file decorations. | ||
- name: Setup problem matcher to provide annotations for PHPUnit | ||
# The JSON file is provided by the `shivammathur/setup-php` action. See https://github.com/shivammathur/setup-php#problem-matchers. | ||
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" | ||
|
||
- name: Install WP tests | ||
run: bash bin/ci/install-wp-tests.sh wordpress_test root '' 127.0.0.1:${{ job.services.mysql.ports['3306'] }} ${{ matrix.wp }} true | ||
|
||
- name: Post install of WP tests | ||
run: bash bin/ci/after-wp-install.sh ${{ matrix.wp }} /tmp/wordpress-tests | ||
|
||
- name: Setup PCOV | ||
if: ${{ matrix.coverage == true }} | ||
# phpdocumentor/reflection has to be removed as it makes use of an outdated dependency, making pcov/clobber | ||
# unable to be installed. | ||
run: | | ||
composer remove --dev phpdocumentor/reflection | ||
composer require --dev --ignore-platform-reqs pcov/clobber | ||
vendor/bin/pcov clobber | ||
- name: Copy plugin to WP plugins directory | ||
run: cp -r "$PWD" "$WP_CORE_DIR/src/wp-content/plugins/pwa" | ||
|
||
- name: Run tests | ||
if: ${{ matrix.coverage == false }} | ||
run: vendor/bin/phpunit | ||
working-directory: ${{ env.WP_CORE_DIR }}/src/wp-content/plugins/pwa | ||
|
||
- name: Run tests with coverage | ||
if: ${{ matrix.coverage == true }} | ||
run: | | ||
vendor/bin/phpunit --coverage-clover build/logs/clover.xml | ||
bash <(curl -s https://codecov.io/bash) -cF php -f "$PWD/build/logs/clover.xml" | ||
working-directory: ${{ env.WP_CORE_DIR }}/src/wp-content/plugins/pwa |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
WP_VERSION=$1 | ||
WP_TESTS_DIR=$2 | ||
|
||
if [[ -z $WP_VERSION ]]; then | ||
echo "usage: $0 <wp-version>" | ||
exit 1 | ||
fi | ||
|
||
if [[ $(php -r "echo PHP_VERSION;") == 8.0* ]]; then | ||
echo "Installing compatible PHPUnit for use with PHP 8..." | ||
|
||
DIFF=$( | ||
cat <<-EOF | ||
diff --git a/composer.json b/composer.json | ||
index 186b940..b06b129 100644 | ||
--- a/composer.json | ||
+++ b/composer.json | ||
@@ -20,6 +20,20 @@ | ||
}, | ||
"sort-packages": true | ||
}, | ||
+ "autoload-dev": { | ||
+ "files": [ | ||
+ "${WP_TESTS_DIR}/includes/phpunit7/MockObject/Builder/NamespaceMatch.php", | ||
+ "${WP_TESTS_DIR}/includes/phpunit7/MockObject/Builder/ParametersMatch.php", | ||
+ "${WP_TESTS_DIR}/includes/phpunit7/MockObject/InvocationMocker.php", | ||
+ "${WP_TESTS_DIR}/includes/phpunit7/MockObject/MockMethod.php" | ||
+ ], | ||
+ "exclude-from-classmap": [ | ||
+ "vendor/phpunit/phpunit/src/Framework/MockObject/Builder/NamespaceMatch.php", | ||
+ "vendor/phpunit/phpunit/src/Framework/MockObject/Builder/ParametersMatch.php", | ||
+ "vendor/phpunit/phpunit/src/Framework/MockObject/InvocationMocker.php", | ||
+ "vendor/phpunit/phpunit/src/Framework/MockObject/MockMethod.php" | ||
+ ] | ||
+ }, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true, | ||
"scripts": { | ||
EOF | ||
) | ||
|
||
echo "${DIFF}" | git apply - | ||
composer require --dev --ignore-platform-reqs --update-with-dependencies phpunit/phpunit:^7.5 | ||
|
||
PATH="$(composer config bin-dir --absolute):$PATH" | ||
echo "done" | ||
fi |
Oops, something went wrong.