Merge branch 'main' into update/cpt-scaffold

This commit is contained in:
Pascal Birchler 2025-03-31 10:18:54 +02:00 committed by GitHub
commit f1d7f04281
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 152 additions and 219 deletions

View file

@ -1,6 +1,7 @@
name: Testing

on:
workflow_dispatch:
pull_request:
push:
branches:

View file

@ -238,6 +238,7 @@ The following files are also included unless the `--skip-tests` is used:
options:
- circle
- gitlab
- bitbucket
- github
---


View file

@ -12,7 +12,7 @@
}
],
"require": {
"wp-cli/wp-cli": "^2.5"
"wp-cli/wp-cli": "^2.12"
},
"require-dev": {
"wp-cli/extension-command": "^1.2 || ^2",
@ -24,7 +24,8 @@
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"johnpbloch/wordpress-core-installer": true
}
},
"lock": false
},
"extra": {
"branch-alias": {

View file

@ -172,42 +172,29 @@ Feature: Scaffold plugin unit tests
And the {PLUGIN_DIR}/bitbucket-pipelines.yml file should contain:
"""
- step:
image: php:5.6
name: "PHP 5.6"
image: php:7.4
name: "PHP 7.4"
script:
# Install Dependencies
- docker-php-ext-install mysqli
- apt-get update && apt-get install -y subversion --no-install-recommends
- apt-get update && apt-get install -y subversion git zip libzip-dev --no-install-recommends
"""
And the {PLUGIN_DIR}/bitbucket-pipelines.yml file should contain:
"""
- step:
image: php:7.0
name: "PHP 7.0"
image: php:8.0
name: "PHP 8.0"
script:
# Install Dependencies
- docker-php-ext-install mysqli
- apt-get update && apt-get install -y subversion --no-install-recommends
- apt-get update && apt-get install -y subversion git zip libzip-dev --no-install-recommends
"""
And the {PLUGIN_DIR}/bitbucket-pipelines.yml file should contain:
"""
- step:
image: php:7.1
name: "PHP 7.1"
image: php:8.2
name: "PHP 8.2"
script:
# Install Dependencies
- docker-php-ext-install mysqli
- apt-get update && apt-get install -y subversion --no-install-recommends
"""
And the {PLUGIN_DIR}/bitbucket-pipelines.yml file should contain:
"""
- step:
image: php:7.2
name: "PHP 7.2"
script:
# Install Dependencies
- docker-php-ext-install mysqli
- apt-get update && apt-get install -y subversion --no-install-recommends
- apt-get update && apt-get install -y subversion git zip libzip-dev --no-install-recommends
"""
And the {PLUGIN_DIR}/bitbucket-pipelines.yml file should contain:
"""
@ -309,3 +296,16 @@ Feature: Scaffold plugin unit tests
"""
require dirname( dirname( __FILE__ ) ) . '/bar.php';
"""

Scenario: Accept bitbucket as valid CI in plugin scaffold
Given a WP install
When I run `wp plugin path`
Then save STDOUT as {PLUGIN_DIR}

When I run `wp scaffold plugin hello-world --ci=bitbucket`
Then STDOUT should not be empty
And the {PLUGIN_DIR}/hello-world/.editorconfig file should exist
And the {PLUGIN_DIR}/hello-world/hello-world.php file should exist
And the {PLUGIN_DIR}/hello-world/readme.txt file should exist
And the {PLUGIN_DIR}/hello-world/bitbucket-pipelines.yml file should exist
And the {PLUGIN_DIR}/hello-world/tests directory should exist

View file

@ -168,42 +168,29 @@ Feature: Scaffold theme unit tests
And the {THEME_DIR}/t12child/bitbucket-pipelines.yml file should contain:
"""
- step:
image: php:5.6
name: "PHP 5.6"
image: php:7.4
name: "PHP 7.4"
script:
# Install Dependencies
- docker-php-ext-install mysqli
- apt-get update && apt-get install -y subversion --no-install-recommends
- apt-get update && apt-get install -y subversion git zip libzip-dev --no-install-recommends
"""
And the {THEME_DIR}/t12child/bitbucket-pipelines.yml file should contain:
"""
- step:
image: php:7.0
name: "PHP 7.0"
image: php:8.0
name: "PHP 8.0"
script:
# Install Dependencies
- docker-php-ext-install mysqli
- apt-get update && apt-get install -y subversion --no-install-recommends
- apt-get update && apt-get install -y subversion git zip libzip-dev --no-install-recommends
"""
And the {THEME_DIR}/t12child/bitbucket-pipelines.yml file should contain:
"""
- step:
image: php:7.1
name: "PHP 7.1"
image: php:8.2
name: "PHP 8.2"
script:
# Install Dependencies
- docker-php-ext-install mysqli
- apt-get update && apt-get install -y subversion --no-install-recommends
"""
And the {THEME_DIR}/t12child/bitbucket-pipelines.yml file should contain:
"""
- step:
image: php:7.2
name: "PHP 7.2"
script:
# Install Dependencies
- docker-php-ext-install mysqli
- apt-get update && apt-get install -y subversion --no-install-recommends
- apt-get update && apt-get install -y subversion git zip libzip-dev --no-install-recommends
"""
And the {THEME_DIR}/t12child/bitbucket-pipelines.yml file should contain:
"""

View file

@ -209,8 +209,7 @@ Feature: WordPress code scaffolding
And the {PLUGIN_DIR}/hello-world/.editorconfig file should exist
And the {PLUGIN_DIR}/hello-world/hello-world.php file should exist
And the {PLUGIN_DIR}/hello-world/readme.txt file should exist
And the {PLUGIN_DIR}/hello-world/package.json file should exist
And the {PLUGIN_DIR}/hello-world/Gruntfile.js file should exist
And the {PLUGIN_DIR}/hello-world/composer.json file should exist
And the {PLUGIN_DIR}/hello-world/.gitignore file should contain:
"""
.DS_Store
@ -219,6 +218,7 @@ Feature: WordPress code scaffolding
Thumbs.db
wp-cli.local.yml
node_modules/
vendor/
"""
And the {PLUGIN_DIR}/hello-world/.distignore file should contain:
"""
@ -254,14 +254,10 @@ Feature: WordPress code scaffolding
Tested up to: {WP_VERSION}
"""

When I run `cat {PLUGIN_DIR}/hello-world/package.json`
Then STDOUT should be JSON containing:
When I run `cat {PLUGIN_DIR}/hello-world/composer.json`
Then STDOUT should contain:
"""
{"author":"Hello World Author"}
"""
And STDOUT should be JSON containing:
"""
{"version":"0.1.0"}
wp-cli/i18n-command
"""

Scenario: Scaffold a plugin by prompting

View file

@ -508,10 +508,10 @@ class Scaffold_Command extends WP_CLI_Command {
'theme_uri' => '',
];

$data = wp_parse_args( $assoc_args, $defaults );
$data['slug'] = $theme_slug;
$data['parent_theme_function_safe'] = str_replace( [ ' ', '-' ], '_', $data['parent_theme'] );
$data['description'] = ucfirst( $data['parent_theme'] ) . ' child theme.';
$data = wp_parse_args( $assoc_args, $defaults );
$data['slug'] = $theme_slug;
$data['prefix_safe'] = str_replace( [ ' ', '-' ], '_', $theme_slug );
$data['description'] = ucfirst( $data['parent_theme'] ) . ' child theme.';

$theme_dir = WP_CONTENT_DIR . "/themes/{$theme_slug}";

@ -624,6 +624,7 @@ class Scaffold_Command extends WP_CLI_Command {
* options:
* - circle
* - gitlab
* - bitbucket
* - github
* ---
*
@ -686,8 +687,7 @@ class Scaffold_Command extends WP_CLI_Command {
$files_to_create = [
$plugin_path => self::mustache_render( 'plugin.mustache', $data ),
$plugin_readme_path => self::mustache_render( 'plugin-readme.mustache', $data ),
"{$plugin_dir}/package.json" => self::mustache_render( 'plugin-packages.mustache', $data ),
"{$plugin_dir}/Gruntfile.js" => self::mustache_render( 'plugin-gruntfile.mustache', $data ),
"{$plugin_dir}/composer.json" => self::mustache_render( 'plugin-composer.mustache', $data ),
"{$plugin_dir}/.gitignore" => self::mustache_render( 'plugin-gitignore.mustache', $data ),
"{$plugin_dir}/.distignore" => self::mustache_render( 'plugin-distignore.mustache', $data ),
"{$plugin_dir}/.editorconfig" => file_get_contents( self::get_template_path( '.editorconfig' ) ),

View file

@ -7,15 +7,17 @@
* @package {{slug}}
*/

add_action( 'wp_enqueue_scripts', '{{parent_theme_function_safe}}_parent_theme_enqueue_styles' );
add_action( 'wp_enqueue_scripts', '{{prefix_safe}}_parent_theme_enqueue_styles' );

/**
* Enqueue scripts and styles.
*/
function {{parent_theme_function_safe}}_parent_theme_enqueue_styles() {
wp_enqueue_style( '{{parent_theme}}-style', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( '{{slug}}-style',
function {{prefix_safe}}_parent_theme_enqueue_styles() {
wp_enqueue_style( '{{parent_theme}}-style', get_template_directory_uri() . '/style.css', array(), '0.1.0' );
wp_enqueue_style(
'{{slug}}-style',
get_stylesheet_directory_uri() . '/style.css',
[ '{{parent_theme}}-style' ]
array( '{{parent_theme}}-style' ),
'0.1.0'
);
}

View file

@ -22,6 +22,17 @@ download() {
curl -s "$1" > "$2";
elif [ `which wget` ]; then
wget -nv -O "$2" "$1"
else
echo "Error: Neither curl nor wget is installed."
exit 1
fi
}

# Check if svn is installed
check_svn_installed() {
if ! command -v svn > /dev/null; then
echo "Error: svn is not installed. Please install svn and try again."
exit 1
fi
}

@ -64,6 +75,7 @@ install_wp() {
if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
mkdir -p $TMPDIR/wordpress-trunk
rm -rf $TMPDIR/wordpress-trunk/*
check_svn_installed
svn export --quiet https://core.svn.wordpress.org/trunk $TMPDIR/wordpress-trunk/wordpress
mv $TMPDIR/wordpress-trunk/wordpress/* $WP_CORE_DIR
else
@ -108,6 +120,7 @@ install_test_suite() {
# set up testing suite
mkdir -p $WP_TESTS_DIR
rm -rf $WP_TESTS_DIR/{includes,data}
check_svn_installed
svn export --quiet --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
svn export --quiet --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data
fi

View file

@ -4,8 +4,9 @@
backupGlobals="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
convertNoticesToExceptions="true"
convertDeprecationsToExceptions="true"
>
<testsuites>
<testsuite name="testing">

View file

@ -1,129 +1,124 @@
pipelines:
default:
- step:
image: php:5.6
name: "PHP 5.6"
image: php:7.4
name: "PHP 7.4"
script:
# Install Dependencies
- docker-php-ext-install mysqli
- apt-get update && apt-get install -y subversion --no-install-recommends
- apt-get update && apt-get install -y subversion git zip libzip-dev --no-install-recommends

# Install PHPCS
- curl -o /usr/local/bin/phpcs -fSL https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar && chmod +x /usr/local/bin/phpcs
- phpcs --version
# PHP extensions
- docker-php-ext-install -j$(nproc) mysqli pdo_mysql zip

# Install WordPress Coding Standards
- WPCS_VERSION=0.14.1
- curl -o wpcs.tar.gz -fSL "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/archive/${WPCS_VERSION}.tar.gz"
- mkdir -p /var/wpcs && tar -xzf wpcs.tar.gz --directory /var/wpcs --strip-components 1 && rm wpcs.tar.gz
- phpcs --config-set show_progress 1 && phpcs --config-set colors 1 && phpcs --config-set installed_paths /var/wpcs
# Setup WordPress tests
- bash bin/install-wp-tests.sh wordpress_tests root root 127.0.0.1 latest true

## Run PHPCS
- phpcs
# Install Composer
- php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
- php composer-setup.php --install-dir=/usr/local/bin --filename=composer
- php -r "unlink('composer-setup.php');"
- export PATH="$PATH:$HOME/.composer/vendor/bin"
- export COMPOSER_ALLOW_SUPERUSER=1

# Install PHPUnit
- PHPUNIT_VERSION=5.7.27
- PHPUNIT_VERSION=9.6.19
- curl -o /usr/local/bin/phpunit "https://phar.phpunit.de/phpunit-${PHPUNIT_VERSION}.phar" && chmod +x /usr/local/bin/phpunit
- composer global require yoast/phpunit-polyfills
- export WP_TESTS_PHPUNIT_POLYFILLS_PATH="$HOME/.composer/vendor/yoast/phpunit-polyfills"
- phpunit --version

## Run PHPUnit
- bash bin/install-wp-tests.sh wordpress_tests root root 127.0.0.1 latest true
# Install PHPCS and WPCS
- composer global config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
- composer global require "wp-coding-standards/wpcs"
- composer global require "phpcompatibility/phpcompatibility-wp"
- phpcs --version

# Run PHPCS
- phpcs

# Run PHPUnit
- phpunit
services:
- database

- step:
image: php:7.0
name: "PHP 7.0"
image: php:8.0
name: "PHP 8.0"
script:
# Install Dependencies
- docker-php-ext-install mysqli
- apt-get update && apt-get install -y subversion --no-install-recommends
- apt-get update && apt-get install -y subversion git zip libzip-dev --no-install-recommends

# Install PHPCS
- curl -o /usr/local/bin/phpcs -fSL https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar && chmod +x /usr/local/bin/phpcs
- phpcs --version
# PHP extensions
- docker-php-ext-install -j$(nproc) mysqli pdo_mysql zip

# Install WordPress Coding Standards
- WPCS_VERSION=0.14.1
- curl -o wpcs.tar.gz -fSL "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/archive/${WPCS_VERSION}.tar.gz"
- mkdir -p /var/wpcs && tar -xzf wpcs.tar.gz --directory /var/wpcs --strip-components 1 && rm wpcs.tar.gz
- phpcs --config-set show_progress 1 && phpcs --config-set colors 1 && phpcs --config-set installed_paths /var/wpcs
# Setup WordPress tests
- bash bin/install-wp-tests.sh wordpress_tests root root 127.0.0.1 latest true

## Run PHPCS
- phpcs
# Install Composer
- php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
- php composer-setup.php --install-dir=/usr/local/bin --filename=composer
- php -r "unlink('composer-setup.php');"
- export PATH="$PATH:$HOME/.composer/vendor/bin"
- export COMPOSER_ALLOW_SUPERUSER=1

# Install PHPUnit
- PHPUNIT_VERSION=6.5.6
- PHPUNIT_VERSION=9.6.19
- curl -o /usr/local/bin/phpunit "https://phar.phpunit.de/phpunit-${PHPUNIT_VERSION}.phar" && chmod +x /usr/local/bin/phpunit
- composer global require yoast/phpunit-polyfills
- export WP_TESTS_PHPUNIT_POLYFILLS_PATH="$HOME/.composer/vendor/yoast/phpunit-polyfills"
- phpunit --version

## Run PHPUnit
- bash bin/install-wp-tests.sh wordpress_tests root root 127.0.0.1 latest true
# Install PHPCS and WPCS
- composer global config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
- composer global require "wp-coding-standards/wpcs"
- composer global require "phpcompatibility/phpcompatibility-wp"
- phpcs --version

# Run PHPCS
- phpcs

# Run PHPUnit
- phpunit
services:
- database

- step:
image: php:7.1
name: "PHP 7.1"
image: php:8.2
name: "PHP 8.2"
script:
# Install Dependencies
- docker-php-ext-install mysqli
- apt-get update && apt-get install -y subversion --no-install-recommends
- apt-get update && apt-get install -y subversion git zip libzip-dev --no-install-recommends

# Install PHPCS
- curl -o /usr/local/bin/phpcs -fSL https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar && chmod +x /usr/local/bin/phpcs
- phpcs --version
# PHP extensions
- docker-php-ext-install -j$(nproc) mysqli pdo_mysql zip

# Install WordPress Coding Standards
- WPCS_VERSION=0.14.1
- curl -o wpcs.tar.gz -fSL "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/archive/${WPCS_VERSION}.tar.gz"
- mkdir -p /var/wpcs && tar -xzf wpcs.tar.gz --directory /var/wpcs --strip-components 1 && rm wpcs.tar.gz
- phpcs --config-set show_progress 1 && phpcs --config-set colors 1 && phpcs --config-set installed_paths /var/wpcs
# Setup WordPress tests
- bash bin/install-wp-tests.sh wordpress_tests root root 127.0.0.1 latest true

## Run PHPCS
- phpcs
# Install Composer
- php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
- php composer-setup.php --install-dir=/usr/local/bin --filename=composer
- php -r "unlink('composer-setup.php');"
- export PATH="$PATH:$HOME/.composer/vendor/bin"
- export COMPOSER_ALLOW_SUPERUSER=1

# Install PHPUnit
- PHPUNIT_VERSION=6.5.6
- PHPUNIT_VERSION=9.6.19
- curl -o /usr/local/bin/phpunit "https://phar.phpunit.de/phpunit-${PHPUNIT_VERSION}.phar" && chmod +x /usr/local/bin/phpunit
- composer global require yoast/phpunit-polyfills
- export WP_TESTS_PHPUNIT_POLYFILLS_PATH="$HOME/.composer/vendor/yoast/phpunit-polyfills"
- phpunit --version

## Run PHPUnit
- bash bin/install-wp-tests.sh wordpress_tests root root 127.0.0.1 latest true
- phpunit
services:
- database

- step:
image: php:7.2
name: "PHP 7.2"
script:
# Install Dependencies
- docker-php-ext-install mysqli
- apt-get update && apt-get install -y subversion --no-install-recommends

# Install PHPCS
- curl -o /usr/local/bin/phpcs -fSL https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar && chmod +x /usr/local/bin/phpcs
# Install PHPCS and WPCS
- composer global config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
- composer global require "wp-coding-standards/wpcs"
- composer global require "phpcompatibility/phpcompatibility-wp"
- phpcs --version

# Install WordPress Coding Standards
- WPCS_VERSION=0.14.1
- curl -o wpcs.tar.gz -fSL "https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/archive/${WPCS_VERSION}.tar.gz"
- mkdir -p /var/wpcs && tar -xzf wpcs.tar.gz --directory /var/wpcs --strip-components 1 && rm wpcs.tar.gz
- phpcs --config-set show_progress 1 && phpcs --config-set colors 1 && phpcs --config-set installed_paths /var/wpcs

## Run PHPCS
# Run PHPCS
- phpcs

# Install PHPUnit
- PHPUNIT_VERSION=6.5.6
- curl -o /usr/local/bin/phpunit "https://phar.phpunit.de/phpunit-${PHPUNIT_VERSION}.phar" && chmod +x /usr/local/bin/phpunit
- phpunit --version

## Run PHPUnit
- bash bin/install-wp-tests.sh wordpress_tests root root 127.0.0.1 latest true
# Run PHPUnit
- phpunit
services:
- database

View file

@ -0,0 +1,8 @@
{
"require-dev": {
"wp-cli/i18n-command": "^2"
},
"scripts": {
"makepot": "wp i18n make-pot ."
}
}

View file

@ -4,6 +4,7 @@ phpunit.xml
Thumbs.db
wp-cli.local.yml
node_modules/
vendor/
*.sql
*.tar.gz
*.zip

View file

@ -1,56 +0,0 @@
module.exports = function( grunt ) {

'use strict';

// Project configuration
grunt.initConfig( {

pkg: grunt.file.readJSON( 'package.json' ),

addtextdomain: {
options: {
textdomain: '{{textdomain}}',
},
update_all_domains: {
options: {
updateDomains: true
},
src: [ '*.php', '**/*.php', '!\.git/**/*', '!bin/**/*', '!node_modules/**/*', '!tests/**/*' ]
}
},

wp_readme_to_markdown: {
your_target: {
files: {
'README.md': 'readme.txt'
}
},
},

makepot: {
target: {
options: {
domainPath: '/languages',
exclude: [ '\.git/*', 'bin/*', 'node_modules/*', 'tests/*' ],
mainFile: '{{plugin_slug}}.php',
potFilename: '{{plugin_slug}}.pot',
potHeaders: {
poedit: true,
'x-poedit-keywordslist': true
},
type: 'wp-plugin',
updateTimestamp: true
}
}
},
} );

grunt.loadNpmTasks( 'grunt-wp-i18n' );
grunt.loadNpmTasks( 'grunt-wp-readme-to-markdown' );
grunt.registerTask( 'default', [ 'i18n','readme' ] );
grunt.registerTask( 'i18n', ['addtextdomain', 'makepot'] );
grunt.registerTask( 'readme', ['wp_readme_to_markdown'] );

grunt.util.linefeed = '\n';

};

View file

@ -1,17 +0,0 @@

{
"name": "{{plugin_slug}}",
"version": "0.1.0",
"main": "Gruntfile.js",
"author": "{{plugin_author}}",
"scripts" : {
"start" : "grunt default" ,
"readme" : "grunt readme",
"i18n" : "grunt i18n"
},
"devDependencies": {
"grunt": "~0.4.5",
"grunt-wp-i18n": "~0.5.0",
"grunt-wp-readme-to-markdown": "~1.0.0"
}
}