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

Add GitHub Actions testing workflow #195

Merged
merged 9 commits into from
May 10, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 172 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
name: Testing

on: pull_request

jobs:

unit: #-----------------------------------------------------------------------
name: Unit test / PHP ${{ matrix.php }}
strategy:
fail-fast: false
matrix:
php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0']
runs-on: ubuntu-20.04

steps:
- name: Check out source code
uses: actions/checkout@v2

- name: Check existence of composer.json file
id: check_files
uses: andstor/file-existence-action@v1
with:
files: "composer.json, phpunit.xml.dist"

- name: Set up PHP environment
if: steps.check_files.outputs.files_exists == 'true'
uses: shivammathur/setup-php@v2
with:
php-version: '${{ matrix.php }}'
coverage: none
tools: composer,cs2pr

- name: Get Composer cache Directory
if: steps.check_files.outputs.files_exists == 'true'
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Use Composer cache
if: steps.check_files.outputs.files_exists == 'true'
uses: actions/cache@master
with:
path: ${{ steps['composer-cache'].outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-

- name: Install dependencies
if: steps.check_files.outputs.files_exists == 'true'
run: COMPOSER_ROOT_VERSION=dev-master composer install --prefer-dist --no-progress --no-suggest

- name: Setup problem matcher to provide annotations for PHPUnit
if: steps.check_files.outputs.files_exists == 'true'
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Run PHPUnit
if: steps.check_files.outputs.files_exists == 'true'
run: composer phpunit

functional: #----------------------------------------------------------------------
name: Functional - WP ${{ matrix.wp }} on PHP ${{ matrix.php }} with MySQL ${{ matrix.mysql }}
strategy:
fail-fast: false
matrix:
php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0']
wp: ['latest']
mysql: ['8.0']
test: ["composer behat || composer behat-rerun"]
include:
- php: '5.6'
wp: 'trunk'
mysql: '8.0'
test: "composer behat || composer behat-rerun"
- php: '5.6'
wp: 'trunk'
mysql: '5.7'
test: "composer behat || composer behat-rerun"
- php: '5.6'
wp: 'trunk'
mysql: '5.6'
test: "composer behat || composer behat-rerun"
- php: '7.4'
wp: 'trunk'
mysql: '8.0'
test: "composer behat || composer behat-rerun"
- php: '8.0'
wp: 'trunk'
mysql: '8.0'
test: "composer behat || composer behat-rerun"
- php: '8.0'
wp: 'trunk'
mysql: '5.7'
test: "composer behat || composer behat-rerun"
- php: '8.0'
wp: 'trunk'
mysql: '5.6'
test: "composer behat || composer behat-rerun"
- php: '5.6'
wp: '3.7'
mysql: '5.6'
test: "composer behat || composer behat-rerun"
runs-on: ubuntu-20.04

services:
mysql:
image: mysql:${{ matrix.mysql }}
ports:
- 3306
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"

steps:
- name: Check out source code
uses: actions/checkout@v2

- name: Check existence of composer.json & behat.yml files
id: check_files
uses: andstor/file-existence-action@v1
with:
files: "composer.json, behat.yml"

- name: Set up PHP envirnoment
if: steps.check_files.outputs.files_exists == 'true'
uses: shivammathur/setup-php@v2
with:
php-version: '${{ matrix.php }}'
extensions: mysql, zip
coverage: none
tools: composer

- name: Get Composer cache Directory
if: steps.check_files.outputs.files_exists == 'true'
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Use Composer cache
if: steps.check_files.outputs.files_exists == 'true'
uses: actions/cache@master
with:
path: ${{ steps['composer-cache'].outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-

- name: Install dependencies
if: steps.check_files.outputs.files_exists == 'true'
run: COMPOSER_ROOT_VERSION=dev-master composer install --prefer-dist --no-progress --no-suggest

- name: Start MySQL server
if: steps.check_files.outputs.files_exists == 'true'
run: sudo systemctl start mysql

- name: Configure DB environment
if: steps.check_files.outputs.files_exists == 'true'
run: |
echo "MYSQL_HOST=127.0.0.1" >> $GITHUB_ENV
echo "MYSQL_TCP_PORT=${{ job.services.mysql.ports['3306'] }}" >> $GITHUB_ENV
echo "WP_CLI_TEST_DBROOTUSER=root" >> $GITHUB_ENV
echo "WP_CLI_TEST_DBROOTPASS=root" >> $GITHUB_ENV
echo "WP_CLI_TEST_DBUSER=wp_cli_test" >> $GITHUB_ENV
echo "WP_CLI_TEST_DBPASS=password1" >> $GITHUB_ENV
echo "WP_CLI_TEST_DBHOST=127.0.0.1:${{ job.services.mysql.ports['3306'] }}" >> $GITHUB_ENV

- name: Prepare test database
if: steps.check_files.outputs.files_exists == 'true'
run: composer prepare-tests

- name: Run Behat
if: steps.check_files.outputs.files_exists == 'true'
env:
WP_VERSION: '${{ matrix.wp }}'
run: ${{ matrix.test }}
7 changes: 7 additions & 0 deletions behat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
default:
suites:
default:
contexts:
- WP_CLI\Tests\Context\FeatureContext
paths:
- features
22 changes: 17 additions & 5 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,37 @@ jobs:
parallelism: 1
docker:
- image: circleci/php:7.1
- image: circleci/mysql:5.6
environment:
WP_CLI_TEST_DBHOST: 127.0.0.1:3306
WP_CLI_TEST_DBROOTPASS: root
WP_CLI_TEST_DBUSER: wp_cli_test
WP_CLI_TEST_DBPASS: password1
- image: circleci/mariadb:10.5
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: wp_cli_test
MYSQL_USER: wp_cli_test
MYSQL_PASSWORD: password1
steps:
- checkout
- run: |
sudo sh -c "printf '\ndeb http://ftp.us.debian.org/debian sid main\n' >> /etc/apt/sources.list"
sudo apt-get update
sudo docker-php-ext-install mysqli
sudo apt-get install mysql-client-5.7
sudo apt-get install mariadb-client-10.5
- run: |
echo -e "memory_limit = 1024M" | sudo tee /usr/local/etc/php/php.ini > /dev/null
- run: |
dockerize -wait tcp://127.0.0.1:3306 -timeout 1m
- run: |
composer require wp-cli/wp-cli:dev-master
composer install
bash bin/install-package-tests.sh
composer prepare-tests
- run: |
echo 'export PATH=$HOME/wp-cli/package-tests/vendor/bin:$PATH' >> $BASH_ENV
source $BASH_ENV
- run: |
composer validate
WP_VERSION=latest bash bin/test.sh
WP_VERSION=latest composer test
rm -rf '/tmp/wp-cli-test core-download-cache'
WP_VERSION=trunk bash bin/test.sh
WP_VERSION=trunk composer test
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
"files": [ "scaffold-package-command.php" ]
},
"require": {
"php": "^5.6 || ^7.0",
"wp-cli/wp-cli": "^2",
"php": "^5.6 || ^7 || ^8",
"wp-cli/wp-cli": "^2.5",
"wp-cli/package-command": "^2",
"wp-cli/scaffold-command": "^2"
},
"require-dev": {
"wp-cli/wp-cli-tests": "^2.1"
"wp-cli/wp-cli-tests": "^3.0.11"
},
"config": {
"process-timeout": 7200,
Expand Down
8 changes: 4 additions & 4 deletions features/scaffold-package-readme.feature
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Feature: Scaffold a README.md file for an existing package
And the {PACKAGE_PATH}/local/wp-cli/default-readme/README.md file should exist
And the {PACKAGE_PATH}/local/wp-cli/default-readme/README.md file should contain:
"""
Installing this package requires WP-CLI v1.1.0 or greater. Update to the latest stable release with `wp cli update`.
Installing this package requires WP-CLI v2.5 or greater. Update to the latest stable release with `wp cli update`.
"""
And the {PACKAGE_PATH}/local/wp-cli/default-readme/README.md file should contain:
"""
Expand Down Expand Up @@ -121,10 +121,10 @@ Feature: Scaffold a README.md file for an existing package
"files": [ "command.php" ]
},
"require": {
"wp-cli/wp-cli": "~1.1.0"
"wp-cli/wp-cli": "^2.5"
},
"require-dev": {
"behat/behat": "~2.5"
"wp-cli/wp-cli-tests": "^3.0.11"
},
"extra": {
"readme": {
Expand Down Expand Up @@ -268,7 +268,7 @@ Feature: Scaffold a README.md file for an existing package
},
"require-dev": {
"wp-cli/wp-cli": "*",
"behat/behat": "~2.5"
"wp-cli/wp-cli-tests": "^3.0.11"
},
"extra": {
"bundled": true
Expand Down
42 changes: 5 additions & 37 deletions features/scaffold-package-tests.feature
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ Feature: Scaffold the test suite for an existing package
},
"autoload": {
"files": [ "dictator.php" ]
},
"require-dev": {
"behat/behat": "~2.5"
}
}
"""
Expand Down Expand Up @@ -59,42 +56,12 @@ Feature: Scaffold the test suite for an existing package
When I run `wp scaffold package-tests community-command`
Then STDOUT should not be empty
And the community-command/.travis.yml file should exist
And the community-command/bin/install-package-tests.sh file should exist
And the community-command/bin/test.sh file should exist
And the community-command/utils/behat-tags.php file should contain:
"""
require-wp
"""
And the community-command/features directory should contain:
"""
bootstrap
extra
load-wp-cli.feature
steps
"""
And the community-command/features/bootstrap directory should contain:
"""
FeatureContext.php
Process.php
ProcessRun.php
support.php
utils.php
"""
And the community-command/features/steps directory should contain:
"""
given.php
then.php
when.php
"""
And the community-command/features/extra directory should contain:
"""
no-mail.php
"""

When I run `wp eval "if ( is_executable( 'community-command/bin/install-package-tests.sh' ) ) { echo 'executable'; } else { exit( 1 ); }"`
Then STDOUT should be:
"""
executable
"""

When I try `wp scaffold package-tests invalid-command`
Expand All @@ -110,11 +77,11 @@ Feature: Scaffold the test suite for an existing package
And the community-command/.travis.yml file should exist
And the community-command/.travis.yml file should contain:
"""
bash bin/install-package-tests.sh
- composer prepare-tests
"""
And the community-command/.travis.yml file should contain:
"""
bash bin/test.sh
- composer behat
"""
And the community-command/circle.yml file should not exist

Expand All @@ -124,11 +91,11 @@ Feature: Scaffold the test suite for an existing package
And the community-command/circle.yml file should exist
And the community-command/circle.yml file should contain:
"""
bash bin/install-package-tests.sh
composer prepare-tests
"""
And the community-command/circle.yml file should contain:
"""
bash bin/test.sh
composer test
"""
And the community-command/.travis.yml file should not exist

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

@broken
Scenario: Scaffolds .travis.yml configuration file with travis[-<tag>[-append]].yml append/override files.
Given a community-command/travis-cache-append.yml file:
"""
Expand Down
4 changes: 1 addition & 3 deletions features/scaffold-package.feature
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Feature: Scaffold WP-CLI commands
And the {PACKAGE_PATH}/local/wp-cli/foo/composer.json file should contain:
"""
"require": {
"wp-cli/wp-cli": "^1.1.0"
"wp-cli/wp-cli": "^2.5"
},
"""
And the {PACKAGE_PATH}/local/wp-cli/foo/command.php file should exist
Expand Down Expand Up @@ -190,8 +190,6 @@ Feature: Scaffold WP-CLI commands
And the {PACKAGE_PATH}/local/wp-cli/with-tests/command.php file should exist
And the {PACKAGE_PATH}/local/wp-cli/with-tests/wp-cli.yml file should exist
And the {PACKAGE_PATH}/local/wp-cli/with-tests/.travis.yml file should exist
And the {PACKAGE_PATH}/local/wp-cli/with-tests/features/bootstrap/Process.php file should exist
And the {PACKAGE_PATH}/local/wp-cli/with-tests/features/bootstrap/ProcessRun.php file should exist

When I run `wp --require={PACKAGE_PATH}/local/wp-cli/with-tests/command.php hello-world`
Then STDOUT should be:
Expand Down
Loading