Skip to content

Commit e27f110

Browse files
authored
Add GitHub as valid CI for plugin and theme scaffold (#331)
* Add support for GitHub as CI in plugin scaffold * Create multilevel folders
1 parent 36ba2e6 commit e27f110

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

src/Scaffold_Command.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,7 @@ private function get_output_path( $assoc_args, $subdir ) {
608608
* options:
609609
* - circle
610610
* - gitlab
611+
* - github
611612
* ---
612613
*
613614
* [--activate]
@@ -733,6 +734,7 @@ public function plugin( $args, $assoc_args ) {
733734
* - circle
734735
* - gitlab
735736
* - bitbucket
737+
* - github
736738
* ---
737739
*
738740
* [--force]
@@ -785,6 +787,7 @@ public function plugin_tests( $args, $assoc_args ) {
785787
* - circle
786788
* - gitlab
787789
* - bitbucket
790+
* - github
788791
* ---
789792
*
790793
* [--force]
@@ -882,6 +885,8 @@ private function scaffold_plugin_theme_tests( $args, $assoc_args, $type ) {
882885
$files_to_create[ "{$target_dir}/.gitlab-ci.yml" ] = self::mustache_render( 'plugin-gitlab.mustache' );
883886
} elseif ( 'bitbucket' === $assoc_args['ci'] ) {
884887
$files_to_create[ "{$target_dir}/bitbucket-pipelines.yml" ] = self::mustache_render( 'plugin-bitbucket.mustache' );
888+
} elseif ( 'github' === $assoc_args['ci'] ) {
889+
$files_to_create[ "{$target_dir}/.github/workflows/testing.yml" ] = self::mustache_render( 'plugin-github.mustache' );
885890
}
886891

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

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

957+
// Create multi-level folders.
958+
if ( false === $wp_filesystem->exists( dirname( $filename ) ) ) {
959+
$wp_filesystem->mkdir( dirname( dirname( $filename ) ) );
960+
$wp_filesystem->mkdir( dirname( $filename ) );
961+
}
962+
952963
if ( ! $wp_filesystem->put_contents( $filename, $contents ) ) {
953964
WP_CLI::error( "Error creating file: {$filename}" );
954965
} elseif ( $should_write_file ) {

templates/plugin-github.mustache

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Testing
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
- master
8+
9+
jobs:
10+
phpunit:
11+
name: Run tests
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
php-version: ['8.2', '8.0', '7.4']
16+
services:
17+
database:
18+
image: mysql:latest
19+
env:
20+
MYSQL_DATABASE: wordpress_tests
21+
MYSQL_ROOT_PASSWORD: root
22+
ports:
23+
- 3306:3306
24+
steps:
25+
- name: Check out source code
26+
uses: actions/checkout@v4
27+
28+
- name: Setup PHP
29+
uses: shivammathur/setup-php@v2
30+
with:
31+
php-version: ${{ matrix.php-version }}
32+
tools: phpunit-polyfills:1.1
33+
34+
- name: Setup tests
35+
run: bash bin/install-wp-tests.sh wordpress_tests root root 127.0.0.1 latest true
36+
37+
- name: Run tests
38+
run: phpunit

0 commit comments

Comments
 (0)