Skip to content

Commit 6aff834

Browse files
authored
Merge pull request #9 from spacedmonkey/fix/workspace
Add workflow
2 parents 88023d8 + 7064be1 commit 6aff834

File tree

9 files changed

+609
-255
lines changed

9 files changed

+609
-255
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: PHP Lints
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- release/*
8+
pull_request:
9+
10+
jobs:
11+
lint-php:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v2
16+
17+
- name: Setup PHP
18+
uses: shivammathur/setup-php@v2
19+
with:
20+
php-version: '7.4'
21+
coverage: none
22+
tools: composer:v1, cs2pr
23+
24+
- name: Get Composer cache directory
25+
id: composer-cache
26+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
27+
28+
- name: Setup Composer cache
29+
uses: pat-s/[email protected]
30+
with:
31+
path: ${{ steps.composer-cache.outputs.dir }}
32+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
33+
restore-keys: |
34+
${{ runner.os }}-composer-
35+
${{ runner.os }}-
36+
37+
- name: Validate composer.json
38+
run: composer --no-interaction validate --no-check-all
39+
40+
- name: Install dependencies
41+
run: composer install --prefer-dist --no-suggest --no-progress --no-interaction
42+
43+
- name: Detect coding standard violations (PHPCS)
44+
run: vendor/bin/phpcs -q --report=checkstyle --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 | cs2pr --graceful-warnings
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
name: PHP Unit Tests
2+
3+
on:
4+
push:
5+
# Only run if PHP-related files changed.
6+
paths:
7+
- '**.php'
8+
- 'phpunit.xml.dist'
9+
- 'phpunit-multisite.xml.dist'
10+
- 'composer.json'
11+
- 'composer.lock'
12+
- 'tests/**'
13+
branches:
14+
- master
15+
- release/*
16+
pull_request:
17+
# Only run if PHP-related files changed.
18+
paths:
19+
- '**.php'
20+
- 'phpunit.xml.dist'
21+
- 'phpunit-multisite.xml.dist'
22+
- 'composer.json'
23+
- 'composer.lock'
24+
- 'tests/**'
25+
- '.github/workflows/tests-unit-php.yml'
26+
27+
jobs:
28+
unit-php:
29+
name: 'PHP ${{ matrix.php }} - WP ${{ matrix.wp }}'
30+
runs-on: ubuntu-latest
31+
timeout-minutes: 60
32+
services:
33+
mysql:
34+
image: mariadb:latest
35+
env:
36+
MYSQL_ALLOW_EMPTY_PASSWORD: true
37+
MYSQL_ROOT_PASSWORD:
38+
MYSQL_DATABASE: wordpress_test
39+
ports:
40+
- 3306
41+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
42+
continue-on-error: ${{ matrix.experimental == true }}
43+
strategy:
44+
matrix:
45+
php: ['7.0', '7.4']
46+
wp: ['latest']
47+
include:
48+
- php: '7.4'
49+
wp: 'trunk'
50+
experimental: true
51+
52+
steps:
53+
- name: Checkout
54+
uses: actions/checkout@v2
55+
56+
- name: Get Composer cache directory
57+
id: composer-cache
58+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
59+
60+
- name: Setup Composer cache
61+
uses: pat-s/[email protected]
62+
with:
63+
path: ${{ steps.composer-cache.outputs.dir }}
64+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
65+
restore-keys: |
66+
${{ runner.os }}-composer-
67+
${{ runner.os }}-
68+
69+
# PHP-Scoper only works on PHP 7.2+ and we need to prefix our dependencies to accurately test them.
70+
# So we temporarily switch PHP versions, do a full install and then remove the package.
71+
# Then switch back to the PHP version we want to test and delete the vendor directory.
72+
73+
- name: Setup PHP 7.4
74+
uses: shivammathur/setup-php@v2
75+
with:
76+
php-version: 7.4
77+
tools: composer
78+
79+
- name: Install prefixed dependencies
80+
run: |
81+
composer install --prefer-dist --no-suggest --no-progress --no-interaction
82+
rm -rf vendor/*
83+
84+
- name: Setup PHP
85+
uses: shivammathur/setup-php@v2
86+
with:
87+
php-version: ${{ matrix.php }}
88+
extensions: mysql
89+
tools: composer, cs2pr
90+
91+
- name: Install dependencies
92+
run: |
93+
composer install --prefer-dist --no-suggest --no-progress --no-interaction --no-scripts
94+
composer dump-autoload --no-interaction
95+
96+
- name: Shutdown default MySQL service
97+
run: sudo service mysql stop
98+
99+
- name: Verify MariaDB connection
100+
run: |
101+
while ! mysqladmin ping -h"127.0.0.1" -P"${{ job.services.mysql.ports[3306] }}" --silent; do
102+
sleep 1
103+
done
104+
105+
- name: Set up tests
106+
run: bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1:${{ job.services.mysql.ports['3306'] }} ${{ matrix.wp }} true
107+
108+
# 1. Installs PHPUnit 7.5 and patches it to run on PHP 8.
109+
# 2. Dumps autoloader so mcaskill/composer-plugin-exclude-files is triggered.
110+
- name: Update PHPUnit
111+
run: |
112+
composer require --dev --ignore-platform-reqs --no-interaction --no-scripts --update-with-all-dependencies phpunit/phpunit:^7.5
113+
git apply patches/composer.patch
114+
composer dump-autoload --no-interaction
115+
if: ${{ matrix.php == '8.0' }}
116+
117+
- name: Run tests
118+
run: |
119+
npm run test:php
120+
npm run test:php:multisite

.phpcs.xml.dist

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
<exclude-pattern>test</exclude-pattern>
2929
</rule>
3030

31+
<rule ref="WordPress-Core">
32+
<exclude name="Generic.Arrays.DisallowShortArraySyntax" />
33+
<exclude name="WordPress.PHP.DisallowShortTernary" />
34+
</rule>
35+
3136
<rule ref="WordPress.Files.FileName.InvalidClassFileName">
3237
<exclude-pattern>test</exclude-pattern>
3338
</rule>

.travis.yml

Lines changed: 0 additions & 58 deletions
This file was deleted.

composer.json

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"type": "wordpress-plugin",
44
"description": "Add gutenberg blocks data into the post / page endpoints api.",
55
"homepage": "http://wp-api.org/",
6-
"license": "GPL2+",
6+
"license": "GPL-2.0-or-later",
77
"authors": [
88
{
99
"name": "Jonny Harris",
@@ -14,18 +14,25 @@
1414
"issues": "https://github.com/spacedmonkey/wp-user-roles/issues"
1515
},
1616
"require": {
17-
"composer/installers": "~1.0",
18-
"php": "^7.0"
17+
"composer/installers": "^1.10",
18+
"php": "^7.0 || ^8.0"
19+
},
20+
"config": {
21+
"discard-changes": true,
22+
"platform": {
23+
"php": "7.0"
24+
},
25+
"sort-packages": true
1926
},
2027
"require-dev": {
2128
"squizlabs/php_codesniffer": "^3.3.1",
2229
"wp-coding-standards/wpcs": "^2.1.1",
23-
"dealerdirect/phpcodesniffer-composer-installer": "^0.5.0",
24-
"phpcompatibility/phpcompatibility-wp": "^2.0",
30+
"dealerdirect/phpcodesniffer-composer-installer": "^0.7",
31+
"phpcompatibility/phpcompatibility-wp": "^2.1",
2532
"phpunit/phpunit": "^4.0 || ^5.0 || ^6.0"
2633
},
2734
"scripts": {
28-
"post-install-cmd": "\"vendor/bin/phpcs\" --config-set installed_paths vendor/wp-coding-standards/wpcs",
29-
"post-update-cmd" : "\"vendor/bin/phpcs\" --config-set installed_paths vendor/wp-coding-standards/wpcs"
35+
"phpcbf": "phpcbf",
36+
"phpcs": "phpcs"
3037
}
3138
}

0 commit comments

Comments
 (0)