diff --git a/src/Scaffold_Command.php b/src/Scaffold_Command.php index f5bcbcef..c418a011 100644 --- a/src/Scaffold_Command.php +++ b/src/Scaffold_Command.php @@ -608,6 +608,7 @@ private function get_output_path( $assoc_args, $subdir ) { * options: * - circle * - gitlab + * - github * --- * * [--activate] @@ -733,6 +734,7 @@ public function plugin( $args, $assoc_args ) { * - circle * - gitlab * - bitbucket + * - github * --- * * [--force] @@ -785,6 +787,7 @@ public function plugin_tests( $args, $assoc_args ) { * - circle * - gitlab * - bitbucket + * - github * --- * * [--force] @@ -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 ); @@ -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 ) { 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