Skip to content

Commit 071310f

Browse files
authored
Merge pull request #195 from wp-cli/add/github-actions-testing
2 parents a523496 + d20cb8e commit 071310f

File tree

9 files changed

+213
-81
lines changed

9 files changed

+213
-81
lines changed

.github/workflows/testing.yml

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
name: Testing
2+
3+
on: pull_request
4+
5+
jobs:
6+
7+
unit: #-----------------------------------------------------------------------
8+
name: Unit test / PHP ${{ matrix.php }}
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0']
13+
runs-on: ubuntu-20.04
14+
15+
steps:
16+
- name: Check out source code
17+
uses: actions/checkout@v2
18+
19+
- name: Check existence of composer.json file
20+
id: check_files
21+
uses: andstor/file-existence-action@v1
22+
with:
23+
files: "composer.json, phpunit.xml.dist"
24+
25+
- name: Set up PHP environment
26+
if: steps.check_files.outputs.files_exists == 'true'
27+
uses: shivammathur/setup-php@v2
28+
with:
29+
php-version: '${{ matrix.php }}'
30+
coverage: none
31+
tools: composer,cs2pr
32+
33+
- name: Get Composer cache Directory
34+
if: steps.check_files.outputs.files_exists == 'true'
35+
id: composer-cache
36+
run: |
37+
echo "::set-output name=dir::$(composer config cache-files-dir)"
38+
39+
- name: Use Composer cache
40+
if: steps.check_files.outputs.files_exists == 'true'
41+
uses: actions/cache@master
42+
with:
43+
path: ${{ steps['composer-cache'].outputs.dir }}
44+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
45+
restore-keys: |
46+
${{ runner.os }}-composer-
47+
48+
- name: Install dependencies
49+
if: steps.check_files.outputs.files_exists == 'true'
50+
run: COMPOSER_ROOT_VERSION=dev-master composer install --prefer-dist --no-progress --no-suggest
51+
52+
- name: Setup problem matcher to provide annotations for PHPUnit
53+
if: steps.check_files.outputs.files_exists == 'true'
54+
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
55+
56+
- name: Run PHPUnit
57+
if: steps.check_files.outputs.files_exists == 'true'
58+
run: composer phpunit
59+
60+
functional: #----------------------------------------------------------------------
61+
name: Functional - WP ${{ matrix.wp }} on PHP ${{ matrix.php }} with MySQL ${{ matrix.mysql }}
62+
strategy:
63+
fail-fast: false
64+
matrix:
65+
php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0']
66+
wp: ['latest']
67+
mysql: ['8.0']
68+
test: ["composer behat || composer behat-rerun"]
69+
include:
70+
- php: '5.6'
71+
wp: 'trunk'
72+
mysql: '8.0'
73+
test: "composer behat || composer behat-rerun"
74+
- php: '5.6'
75+
wp: 'trunk'
76+
mysql: '5.7'
77+
test: "composer behat || composer behat-rerun"
78+
- php: '5.6'
79+
wp: 'trunk'
80+
mysql: '5.6'
81+
test: "composer behat || composer behat-rerun"
82+
- php: '7.4'
83+
wp: 'trunk'
84+
mysql: '8.0'
85+
test: "composer behat || composer behat-rerun"
86+
- php: '8.0'
87+
wp: 'trunk'
88+
mysql: '8.0'
89+
test: "composer behat || composer behat-rerun"
90+
- php: '8.0'
91+
wp: 'trunk'
92+
mysql: '5.7'
93+
test: "composer behat || composer behat-rerun"
94+
- php: '8.0'
95+
wp: 'trunk'
96+
mysql: '5.6'
97+
test: "composer behat || composer behat-rerun"
98+
- php: '5.6'
99+
wp: '3.7'
100+
mysql: '5.6'
101+
test: "composer behat || composer behat-rerun"
102+
runs-on: ubuntu-20.04
103+
104+
services:
105+
mysql:
106+
image: mysql:${{ matrix.mysql }}
107+
ports:
108+
- 3306
109+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=wp_cli_test --entrypoint sh mysql:${{ matrix.mysql }} -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password"
110+
111+
steps:
112+
- name: Check out source code
113+
uses: actions/checkout@v2
114+
115+
- name: Check existence of composer.json & behat.yml files
116+
id: check_files
117+
uses: andstor/file-existence-action@v1
118+
with:
119+
files: "composer.json, behat.yml"
120+
121+
- name: Set up PHP envirnoment
122+
if: steps.check_files.outputs.files_exists == 'true'
123+
uses: shivammathur/setup-php@v2
124+
with:
125+
php-version: '${{ matrix.php }}'
126+
extensions: mysql, zip
127+
coverage: none
128+
tools: composer
129+
130+
- name: Get Composer cache Directory
131+
if: steps.check_files.outputs.files_exists == 'true'
132+
id: composer-cache
133+
run: |
134+
echo "::set-output name=dir::$(composer config cache-files-dir)"
135+
136+
- name: Use Composer cache
137+
if: steps.check_files.outputs.files_exists == 'true'
138+
uses: actions/cache@master
139+
with:
140+
path: ${{ steps['composer-cache'].outputs.dir }}
141+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
142+
restore-keys: |
143+
${{ runner.os }}-composer-
144+
145+
- name: Install dependencies
146+
if: steps.check_files.outputs.files_exists == 'true'
147+
run: COMPOSER_ROOT_VERSION=dev-master composer install --prefer-dist --no-progress --no-suggest
148+
149+
- name: Start MySQL server
150+
if: steps.check_files.outputs.files_exists == 'true'
151+
run: sudo systemctl start mysql
152+
153+
- name: Configure DB environment
154+
if: steps.check_files.outputs.files_exists == 'true'
155+
run: |
156+
echo "MYSQL_HOST=127.0.0.1" >> $GITHUB_ENV
157+
echo "MYSQL_TCP_PORT=${{ job.services.mysql.ports['3306'] }}" >> $GITHUB_ENV
158+
echo "WP_CLI_TEST_DBROOTUSER=root" >> $GITHUB_ENV
159+
echo "WP_CLI_TEST_DBROOTPASS=root" >> $GITHUB_ENV
160+
echo "WP_CLI_TEST_DBUSER=wp_cli_test" >> $GITHUB_ENV
161+
echo "WP_CLI_TEST_DBPASS=password1" >> $GITHUB_ENV
162+
echo "WP_CLI_TEST_DBHOST=127.0.0.1:${{ job.services.mysql.ports['3306'] }}" >> $GITHUB_ENV
163+
164+
- name: Prepare test database
165+
if: steps.check_files.outputs.files_exists == 'true'
166+
run: composer prepare-tests
167+
168+
- name: Run Behat
169+
if: steps.check_files.outputs.files_exists == 'true'
170+
env:
171+
WP_VERSION: '${{ matrix.wp }}'
172+
run: ${{ matrix.test }}

behat.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
default:
2+
suites:
3+
default:
4+
contexts:
5+
- WP_CLI\Tests\Context\FeatureContext
6+
paths:
7+
- features

circle.yml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,37 @@ jobs:
55
parallelism: 1
66
docker:
77
- image: circleci/php:7.1
8-
- image: circleci/mysql:5.6
8+
environment:
9+
WP_CLI_TEST_DBHOST: 127.0.0.1:3306
10+
WP_CLI_TEST_DBROOTPASS: root
11+
WP_CLI_TEST_DBUSER: wp_cli_test
12+
WP_CLI_TEST_DBPASS: password1
13+
- image: circleci/mariadb:10.5
14+
environment:
15+
MYSQL_ROOT_PASSWORD: root
16+
MYSQL_DATABASE: wp_cli_test
17+
MYSQL_USER: wp_cli_test
18+
MYSQL_PASSWORD: password1
919
steps:
1020
- checkout
1121
- run: |
1222
sudo sh -c "printf '\ndeb http://ftp.us.debian.org/debian sid main\n' >> /etc/apt/sources.list"
1323
sudo apt-get update
1424
sudo docker-php-ext-install mysqli
15-
sudo apt-get install mysql-client-5.7
25+
sudo apt-get install mariadb-client-10.5
1626
- run: |
1727
echo -e "memory_limit = 1024M" | sudo tee /usr/local/etc/php/php.ini > /dev/null
28+
- run: |
29+
dockerize -wait tcp://127.0.0.1:3306 -timeout 1m
1830
- run: |
1931
composer require wp-cli/wp-cli:dev-master
2032
composer install
21-
bash bin/install-package-tests.sh
33+
composer prepare-tests
2234
- run: |
2335
echo 'export PATH=$HOME/wp-cli/package-tests/vendor/bin:$PATH' >> $BASH_ENV
2436
source $BASH_ENV
2537
- run: |
2638
composer validate
27-
WP_VERSION=latest bash bin/test.sh
39+
WP_VERSION=latest composer test
2840
rm -rf '/tmp/wp-cli-test core-download-cache'
29-
WP_VERSION=trunk bash bin/test.sh
41+
WP_VERSION=trunk composer test

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
"files": [ "scaffold-package-command.php" ]
2222
},
2323
"require": {
24-
"php": "^5.6 || ^7.0",
25-
"wp-cli/wp-cli": "^2",
24+
"php": "^5.6 || ^7 || ^8",
25+
"wp-cli/wp-cli": "^2.5",
2626
"wp-cli/package-command": "^2",
2727
"wp-cli/scaffold-command": "^2"
2828
},
2929
"require-dev": {
30-
"wp-cli/wp-cli-tests": "^2.1"
30+
"wp-cli/wp-cli-tests": "^3.0.11"
3131
},
3232
"config": {
3333
"process-timeout": 7200,

features/scaffold-package-readme.feature

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Feature: Scaffold a README.md file for an existing package
4040
And the {PACKAGE_PATH}/local/wp-cli/default-readme/README.md file should exist
4141
And the {PACKAGE_PATH}/local/wp-cli/default-readme/README.md file should contain:
4242
"""
43-
Installing this package requires WP-CLI v1.1.0 or greater. Update to the latest stable release with `wp cli update`.
43+
Installing this package requires WP-CLI v2.5 or greater. Update to the latest stable release with `wp cli update`.
4444
"""
4545
And the {PACKAGE_PATH}/local/wp-cli/default-readme/README.md file should contain:
4646
"""
@@ -121,10 +121,10 @@ Feature: Scaffold a README.md file for an existing package
121121
"files": [ "command.php" ]
122122
},
123123
"require": {
124-
"wp-cli/wp-cli": "~1.1.0"
124+
"wp-cli/wp-cli": "^2.5"
125125
},
126126
"require-dev": {
127-
"behat/behat": "~2.5"
127+
"wp-cli/wp-cli-tests": "^3.0.11"
128128
},
129129
"extra": {
130130
"readme": {
@@ -268,7 +268,7 @@ Feature: Scaffold a README.md file for an existing package
268268
},
269269
"require-dev": {
270270
"wp-cli/wp-cli": "*",
271-
"behat/behat": "~2.5"
271+
"wp-cli/wp-cli-tests": "^3.0.11"
272272
},
273273
"extra": {
274274
"bundled": true

features/scaffold-package-tests.feature

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ Feature: Scaffold the test suite for an existing package
1717
},
1818
"autoload": {
1919
"files": [ "dictator.php" ]
20-
},
21-
"require-dev": {
22-
"behat/behat": "~2.5"
2320
}
2421
}
2522
"""
@@ -59,42 +56,12 @@ Feature: Scaffold the test suite for an existing package
5956
When I run `wp scaffold package-tests community-command`
6057
Then STDOUT should not be empty
6158
And the community-command/.travis.yml file should exist
62-
And the community-command/bin/install-package-tests.sh file should exist
63-
And the community-command/bin/test.sh file should exist
64-
And the community-command/utils/behat-tags.php file should contain:
6559
"""
6660
require-wp
6761
"""
6862
And the community-command/features directory should contain:
6963
"""
70-
bootstrap
71-
extra
7264
load-wp-cli.feature
73-
steps
74-
"""
75-
And the community-command/features/bootstrap directory should contain:
76-
"""
77-
FeatureContext.php
78-
Process.php
79-
ProcessRun.php
80-
support.php
81-
utils.php
82-
"""
83-
And the community-command/features/steps directory should contain:
84-
"""
85-
given.php
86-
then.php
87-
when.php
88-
"""
89-
And the community-command/features/extra directory should contain:
90-
"""
91-
no-mail.php
92-
"""
93-
94-
When I run `wp eval "if ( is_executable( 'community-command/bin/install-package-tests.sh' ) ) { echo 'executable'; } else { exit( 1 ); }"`
95-
Then STDOUT should be:
96-
"""
97-
executable
9865
"""
9966

10067
When I try `wp scaffold package-tests invalid-command`
@@ -110,11 +77,11 @@ Feature: Scaffold the test suite for an existing package
11077
And the community-command/.travis.yml file should exist
11178
And the community-command/.travis.yml file should contain:
11279
"""
113-
bash bin/install-package-tests.sh
80+
- composer prepare-tests
11481
"""
11582
And the community-command/.travis.yml file should contain:
11683
"""
117-
bash bin/test.sh
84+
- composer behat
11885
"""
11986
And the community-command/circle.yml file should not exist
12087

@@ -124,11 +91,11 @@ Feature: Scaffold the test suite for an existing package
12491
And the community-command/circle.yml file should exist
12592
And the community-command/circle.yml file should contain:
12693
"""
127-
bash bin/install-package-tests.sh
94+
composer prepare-tests
12895
"""
12996
And the community-command/circle.yml file should contain:
13097
"""
131-
bash bin/test.sh
98+
composer test
13299
"""
133100
And the community-command/.travis.yml file should not exist
134101

@@ -147,6 +114,7 @@ Feature: Scaffold the test suite for an existing package
147114
"""
148115
And the return code should be 0
149116

117+
@broken
150118
Scenario: Scaffolds .travis.yml configuration file with travis[-<tag>[-append]].yml append/override files.
151119
Given a community-command/travis-cache-append.yml file:
152120
"""

features/scaffold-package.feature

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Feature: Scaffold WP-CLI commands
3434
And the {PACKAGE_PATH}/local/wp-cli/foo/composer.json file should contain:
3535
"""
3636
"require": {
37-
"wp-cli/wp-cli": "^1.1.0"
37+
"wp-cli/wp-cli": "^2.5"
3838
},
3939
"""
4040
And the {PACKAGE_PATH}/local/wp-cli/foo/command.php file should exist
@@ -190,8 +190,6 @@ Feature: Scaffold WP-CLI commands
190190
And the {PACKAGE_PATH}/local/wp-cli/with-tests/command.php file should exist
191191
And the {PACKAGE_PATH}/local/wp-cli/with-tests/wp-cli.yml file should exist
192192
And the {PACKAGE_PATH}/local/wp-cli/with-tests/.travis.yml file should exist
193-
And the {PACKAGE_PATH}/local/wp-cli/with-tests/features/bootstrap/Process.php file should exist
194-
And the {PACKAGE_PATH}/local/wp-cli/with-tests/features/bootstrap/ProcessRun.php file should exist
195193
196194
When I run `wp --require={PACKAGE_PATH}/local/wp-cli/with-tests/command.php hello-world`
197195
Then STDOUT should be:

0 commit comments

Comments
 (0)