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 as valid CI for plugin and theme scaffold #331

Merged
merged 2 commits into from Apr 12, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Scaffold_Command.php
Expand Up @@ -608,6 +608,7 @@ private function get_output_path( $assoc_args, $subdir ) {
* options:
* - circle
* - gitlab
* - github
* ---
*
* [--activate]
Expand Down Expand Up @@ -733,6 +734,7 @@ public function plugin( $args, $assoc_args ) {
* - circle
* - gitlab
* - bitbucket
* - github
* ---
*
* [--force]
Expand Down Expand Up @@ -785,6 +787,7 @@ public function plugin_tests( $args, $assoc_args ) {
* - circle
* - gitlab
* - bitbucket
* - github
* ---
*
* [--force]
Expand Down Expand Up @@ -882,6 +885,8 @@ private function scaffold_plugin_theme_tests( $args, $assoc_args, $type ) {
$files_to_create[ "{$target_dir}/.gitlab-ci.yml" ] = self::mustache_render( 'plugin-gitlab.mustache' );
} elseif ( 'bitbucket' === $assoc_args['ci'] ) {
$files_to_create[ "{$target_dir}/bitbucket-pipelines.yml" ] = self::mustache_render( 'plugin-bitbucket.mustache' );
} elseif ( 'github' === $assoc_args['ci'] ) {
$files_to_create[ "{$target_dir}/.github/workflows/testing.yml" ] = self::mustache_render( 'plugin-github.mustache' );
}

$files_written = $this->create_files( $files_to_create, $force );
Expand Down Expand Up @@ -949,6 +954,12 @@ protected function create_files( $files_and_contents, $force ) {

$wp_filesystem->mkdir( dirname( $filename ) );

// Create multi-level folders.
if ( false === $wp_filesystem->exists( dirname( $filename ) ) ) {
$wp_filesystem->mkdir( dirname( dirname( $filename ) ) );
$wp_filesystem->mkdir( dirname( $filename ) );
}

if ( ! $wp_filesystem->put_contents( $filename, $contents ) ) {
WP_CLI::error( "Error creating file: {$filename}" );
} elseif ( $should_write_file ) {
Expand Down
38 changes: 38 additions & 0 deletions templates/plugin-github.mustache
@@ -0,0 +1,38 @@
name: Testing

on:
pull_request:
branches:
- main
- master

jobs:
phpunit:
name: Run tests
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ['8.2', '8.0', '7.4']
services:
database:
image: mysql:latest
env:
MYSQL_DATABASE: wordpress_tests
MYSQL_ROOT_PASSWORD: root
ports:
- 3306:3306
steps:
- name: Check out source code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
tools: phpunit-polyfills:1.1

- name: Setup tests
run: bash bin/install-wp-tests.sh wordpress_tests root root 127.0.0.1 latest true

- name: Run tests
run: phpunit