Merge pull request #163 from wp-cli/add/gha-workflows

This commit is contained in:
Alain Schlesser 2021-04-19 17:55:54 +01:00 committed by GitHub
commit 8117b98e70
15 changed files with 253 additions and 38 deletions

178
.github/workflows/testing.yml vendored Normal file
View file

@ -0,0 +1,178 @@
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']
include:
- php: '5.6'
wp: 'trunk'
mysql: '8.0'
- php: '5.6'
wp: 'trunk'
mysql: '5.7'
- php: '5.6'
wp: 'trunk'
mysql: '5.6'
- php: '7.4'
wp: 'trunk'
mysql: '8.0'
- php: '8.0'
wp: 'trunk'
mysql: '8.0'
- php: '8.0'
wp: 'trunk'
mysql: '5.7'
- php: '8.0'
wp: 'trunk'
mysql: '5.6'
- php: '5.6'
wp: '3.7'
mysql: '5.6'
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: Install Ghostscript
if: steps.check_files.outputs.files_exists == 'true'
run: |
sudo apt-get update
sudo apt-get install ghostscript -y
- name: Set up PHP envirnoment
if: steps.check_files.outputs.files_exists == 'true'
uses: shivammathur/setup-php@v2
with:
php-version: '${{ matrix.php }}'
extensions: imagick, 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: Change ImageMagick policy to allow pdf->png conversion.
if: steps.check_files.outputs.files_exists == 'true'
run: |
sudo sed -i 's/^.*policy.*coder.*none.*PDF.*//' /etc/ImageMagick-6/policy.xml
- 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: |
export MYSQL_HOST=127.0.0.1
export MYSQL_TCP_PORT=${{ job.services.mysql.ports['3306'] }}
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=$MYSQL_HOST:$MYSQL_TCP_PORT" >> $GITHUB_ENV
- name: Prepare test database
if: steps.check_files.outputs.files_exists == 'true'
run: composer prepare-tests
- name: Check Behat environment
if: steps.check_files.outputs.files_exists == 'true'
run: WP_CLI_TEST_DEBUG_BEHAT_ENV=1 composer behat
- name: Run Behat
if: steps.check_files.outputs.files_exists == 'true'
env:
WP_VERSION: '${{ matrix.wp }}'
run: composer behat || composer behat-rerun

7
behat.yml Normal file
View file

@ -0,0 +1,7 @@
default:
suites:
default:
contexts:
- WP_CLI\Tests\Context\FeatureContext
paths:
- features

View file

@ -2,15 +2,15 @@
"name": "wp-cli/profile-command",
"type": "wp-cli-package",
"description": "Quickly identify what's slow with WordPress.",
"homepage": "https://runcommand.io/wp/profile/",
"homepage": "https://github.com/wp-cli/profile-command/",
"license": "MIT",
"authors": [],
"require": {
"php": ">=5.4",
"wp-cli/wp-cli": "^2"
"php": ">=5.6",
"wp-cli/wp-cli": "dev-master"
},
"require-dev": {
"wp-cli/wp-cli-tests": "^2.1"
"wp-cli/wp-cli-tests": "^3"
},
"config": {
"process-timeout": 7200,
@ -39,8 +39,11 @@
}
},
"autoload": {
"psr-4": {
"WP_CLI\\Profile\\": "src/"
},
"files": [
"command.php"
"profile-command.php"
]
},
"minimum-stability": "dev",

View file

@ -5,10 +5,10 @@ Feature: Profile arbitary file execution
And a lame-function.php file:
"""
<?php
function runcommand_do_nothing() {
function wp_cli_do_nothing() {
}
runcommand_do_nothing();
wp_cli_do_nothing();
"""
When I run `wp profile eval-file lame-function.php --fields=query_time,query_count,cache_ratio,cache_hits,cache_misses,request_time,request_count`
@ -21,7 +21,7 @@ Feature: Profile arbitary file execution
And a http-request.php file:
"""
<?php
wp_remote_get( "http://apple.com" );
wp_remote_get( "https://www.apple.com/" );
"""
When I run `wp profile eval-file http-request.php --fields=request_count`

View file

@ -5,12 +5,12 @@ Feature: Profile arbitary code execution
And a wp-content/mu-plugins/lame-function.php file:
"""
<?php
function runcommand_do_nothing() {
function wp_cli_do_nothing() {
}
"""
When I run `wp profile eval 'runcommand_do_nothing();' --fields=query_time,query_count,cache_ratio,cache_hits,cache_misses,request_time,request_count`
When I run `wp profile eval 'wp_cli_do_nothing();' --fields=query_time,query_count,cache_ratio,cache_hits,cache_misses,request_time,request_count`
Then STDOUT should be a table containing rows:
| query_time | query_count | cache_ratio | cache_hits | cache_misses | request_time | request_count |
| 0s | 0 | | 0 | 0 | 0s | 0 |
@ -18,7 +18,7 @@ Feature: Profile arbitary code execution
Scenario: Profile a function that makes one HTTP request
Given a WP install
When I run `wp profile eval 'wp_remote_get( "http://apple.com" );' --fields=request_count`
When I run `wp profile eval 'wp_remote_get( "https://www.apple.com/" );' --fields=request_count`
Then STDOUT should be a table containing rows:
| request_count |
| 1 |

View file

@ -1,5 +1,6 @@
Feature: Profile a specific hook
@require-wp-4.0
Scenario: Profile all hooks when a specific hook isn't specified
Given a WP install
@ -11,6 +12,7 @@ Feature: Profile a specific hook
| template_redirect |
And STDERR should be empty
@require-wp-4.4
Scenario: Profile all callbacks when --all flag is used
Given a WP install
@ -21,7 +23,7 @@ Feature: Profile a specific hook
| smilies_init() | 2 | 0 |
| feed_links() | 8 | 0 |
@less-than-php-7
@less-than-php-7 @require-wp-4.0
Scenario: Profile an intermediate stage hook
Given a WP install
@ -32,9 +34,10 @@ Feature: Profile a specific hook
| load_template() | 0 | 0 |
And STDOUT should not contain:
"""
runcommand\Profile\Profiler->wp_tick_profile_begin()
WP_CLI\Profile\Profiler->wp_tick_profile_begin()
"""
@require-wp-4.0
Scenario: Profile a hook before the template is loaded
Given a WP install
@ -43,6 +46,7 @@ Feature: Profile a specific hook
| callback |
And STDERR should be empty
@require-wp-4.0
Scenario: Profile a hook without any callbacks
Given a WP install
@ -52,6 +56,7 @@ Feature: Profile a specific hook
| total (0) |
And STDERR should be empty
@require-wp-4.0
Scenario: Profile a hook that has actions with output
Given a WP install
@ -63,44 +68,47 @@ Feature: Profile a specific hook
<meta name="generator"
"""
@require-wp-4.0
Scenario: Profile the shutdown hook
Given a WP install
And a wp-content/mu-plugins/shutdown.php file:
"""
<?php
function runcommand_shutdown_hook() {
function wp_cli_shutdown_hook() {
wp_cache_get( 'foo' );
}
add_action( 'shutdown', 'runcommand_shutdown_hook' );
add_action( 'shutdown', 'wp_cli_shutdown_hook' );
"""
When I run `wp profile hook shutdown --fields=callback,cache_hits,cache_misses`
Then STDOUT should be a table containing rows:
| callback | cache_hits | cache_misses |
| runcommand_shutdown_hook() | 0 | 1 |
| wp_ob_end_flush_all() | 0 | 0 |
| total (2) | 0 | 1 |
| callback | cache_hits | cache_misses |
| wp_cli_shutdown_hook() | 0 | 1 |
| wp_ob_end_flush_all() | 0 | 0 |
| total (2) | 0 | 1 |
And STDERR should be empty
@require-wp-4.0
Scenario: Indicate where a callback is defined with profiling a hook
Given a WP install
And a wp-content/mu-plugins/custom-action.php file:
"""
<?php
function runcommand_custom_action_hook() {
function wp_cli_custom_action_hook() {
wp_cache_get( 'foo' );
}
add_action( 'runcommand_custom_action', 'runcommand_custom_action_hook' );
do_action( 'runcommand_custom_action' );
add_action( 'wp_cli_custom_action', 'wp_cli_custom_action_hook' );
do_action( 'wp_cli_custom_action' );
"""
When I run `wp profile hook runcommand_custom_action --fields=callback,location,cache_hits,cache_misses`
When I run `wp profile hook wp_cli_custom_action --fields=callback,location,cache_hits,cache_misses`
Then STDOUT should be a table containing rows:
| callback | location | cache_hits | cache_misses |
| runcommand_custom_action_hook() | mu-plugins/custom-action.php:2 | 0 | 1 |
| total (1) | | 0 | 1 |
| callback | location | cache_hits | cache_misses |
| wp_cli_custom_action_hook() | mu-plugins/custom-action.php:2 | 0 | 1 |
| total (1) | | 0 | 1 |
And STDERR should be empty
@require-wp-4.4
Scenario: Hooks should only be called once
Given a WP install
And a wp-content/mu-plugins/action-test.php file:
@ -122,7 +130,7 @@ Feature: Profile a specific hook
Warning: Called 1
"""
@less-than-php-7
@less-than-php-7 @require-wp-4.0
Scenario: Profile the mu_plugins:before hook
Given a WP install
And a wp-content/mu-plugins/awesome-file.php file:
@ -140,7 +148,7 @@ Feature: Profile a specific hook
wp-content/mu-plugins/awesome-file.php
"""
@less-than-php-7
@less-than-php-7 @require-wp-4.0
Scenario: Profile the :after hooks
Given a WP install

View file

@ -1,5 +1,6 @@
Feature: Profile the template render stage
@require-wp-4.0
Scenario: Profiler loads a summary table
Given a WP install
@ -10,6 +11,7 @@ Feature: Profile the template render stage
| main_query |
| template |
@require-wp-4.0
Scenario: Profiler loads a table with the correct hooks
Given a WP install
@ -79,6 +81,7 @@ Feature: Profile the template render stage
| loop_end:before |
| loop_end |
@require-wp-4.0
Scenario: Use --all flag to profile all stages
Given a WP install
@ -131,6 +134,7 @@ Feature: Profile the template render stage
Error: Invalid stage. Must be one of bootstrap, main_query, template, or use --all.
"""
@require-wp-4.0
Scenario: Identify callback_count for each hook
Given a WP install
@ -139,6 +143,7 @@ Feature: Profile the template render stage
| hook | callback_count |
| muplugins_loaded | 2 |
@require-wp-4.0
Scenario: Use spotlight mode to filter out the zero-ish values
Given a WP install

View file

@ -33,6 +33,7 @@ Feature: Basic profile usage
Error: 'SAVEQUERIES' is defined as false, and must be true. Please check your wp-config.php
"""
@require-wp-4.0
Scenario: Profile a hook without any callbacks
Given a WP install
@ -42,6 +43,7 @@ Feature: Basic profile usage
| total (0) | |
And STDERR should be empty
@require-wp-4.0
Scenario: Trailingslash provided URL to avoid canonical redirect
Given a WP install

View file

@ -1,5 +1,5 @@
<?xml version="1.0"?>
<ruleset name="WP-CLI-find">
<ruleset name="WP-CLI-profile">
<description>Custom ruleset for WP-CLI profile-command</description>
<!--
@ -38,7 +38,7 @@
<!-- For help understanding the `testVersion` configuration setting:
https://github.com/PHPCompatibility/PHPCompatibility#sniffing-your-code-for-compatibility-with-specific-php-versions -->
<config name="testVersion" value="5.4-"/>
<config name="testVersion" value="5.6-"/>
<!-- Verify that everything in the global namespace is either namespaced or prefixed.
See: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#naming-conventions-prefix-everything-in-the-global-namespace -->
@ -51,11 +51,11 @@
</property>
</properties>
<exclude name="WordPress.Files.FileName.NotHyphenatedLowercase" />
<exclude-pattern>*/inc/*.php$</exclude-pattern>
<exclude-pattern>*/src/*.php$</exclude-pattern>
</rule>
<rule ref="WordPress.PHP.NoSilencedErrors.Discouraged">
<exclude-pattern>*/inc/class-profiler.php$</exclude-pattern>
<exclude-pattern>*/src/class-profiler.php$</exclude-pattern>
</rule>
</ruleset>

12
profile-command.php Normal file
View file

@ -0,0 +1,12 @@
<?php
if ( ! class_exists( 'WP_CLI' ) ) {
return;
}
$wpcli_profile_autoloader = dirname( __FILE__ ) . '/vendor/autoload.php';
if ( file_exists( $wpcli_profile_autoloader ) ) {
require_once $wpcli_profile_autoloader;
}
WP_CLI::add_command( 'profile', 'WP_CLI\Profile\Command' );

View file

@ -1,6 +1,6 @@
<?php
namespace runcommand\Profile;
namespace WP_CLI\Profile;
use WP_CLI;
use WP_CLI\Utils;

View file

@ -1,6 +1,6 @@
<?php
namespace runcommand\Profile;
namespace WP_CLI\Profile;
class Formatter {

View file

@ -1,6 +1,6 @@
<?php
namespace runcommand\Profile;
namespace WP_CLI\Profile;
class Logger {

View file

@ -1,6 +1,6 @@
<?php
namespace runcommand\Profile;
namespace WP_CLI\Profile;
use WP_CLI;
@ -352,7 +352,7 @@ class Profiler {
$callback = 'function(){}';
}
if ( 'runcommand\Profile\Profiler->wp_tick_profile_begin()' === $callback ) {
if ( 'WP_CLI\Profile\Profiler->wp_tick_profile_begin()' === $callback ) {
$this->tick_callback = null;
return;
}

View file

@ -1,2 +1,2 @@
require:
- command.php
- profile-command.php