From b786c43259fb3d4ea38e2059d4dd6c51cf376177 Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Thu, 28 Mar 2024 10:25:33 +0545 Subject: [PATCH 1/2] Add support for GitHub as CI in plugin scaffold --- src/Scaffold_Command.php | 6 +++++ templates/plugin-github.mustache | 38 ++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 templates/plugin-github.mustache diff --git a/src/Scaffold_Command.php b/src/Scaffold_Command.php index f5bcbcef..023ddb9f 100644 --- a/src/Scaffold_Command.php +++ b/src/Scaffold_Command.php @@ -607,7 +607,9 @@ private function get_output_path( $assoc_args, $subdir ) { * default: circle * options: * - circle + * - bitbucket * - gitlab + * - github * --- * * [--activate] @@ -733,6 +735,7 @@ public function plugin( $args, $assoc_args ) { * - circle * - gitlab * - bitbucket + * - github * --- * * [--force] @@ -785,6 +788,7 @@ public function plugin_tests( $args, $assoc_args ) { * - circle * - gitlab * - bitbucket + * - github * --- * * [--force] @@ -882,6 +886,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 ); diff --git a/templates/plugin-github.mustache b/templates/plugin-github.mustache new file mode 100644 index 00000000..db99fa76 --- /dev/null +++ b/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 From 9290dc111c552ffb6db5296e80edf6ac45404581 Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Mon, 1 Apr 2024 10:39:00 +0545 Subject: [PATCH 2/2] Create multilevel folders --- src/Scaffold_Command.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Scaffold_Command.php b/src/Scaffold_Command.php index 023ddb9f..c418a011 100644 --- a/src/Scaffold_Command.php +++ b/src/Scaffold_Command.php @@ -607,7 +607,6 @@ private function get_output_path( $assoc_args, $subdir ) { * default: circle * options: * - circle - * - bitbucket * - gitlab * - github * --- @@ -955,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 ) {