From f73d47a030e1fc115c6d45683d88aed24be71e01 Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Wed, 20 Mar 2024 14:41:44 +0545 Subject: [PATCH 1/4] Add GH actions in scaffold package test --- README.md | 1 + dot-github/workflows/testing.yml | 52 ++++++++++++++++++++++++++++++++ src/ScaffoldPackageCommand.php | 6 +++- 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 dot-github/workflows/testing.yml diff --git a/README.md b/README.md index 64ce747..656ecfd 100644 --- a/README.md +++ b/README.md @@ -174,6 +174,7 @@ WP-CLI Behat framework uses Behat ~2.5, which is installed with Composer. options: - travis - circle + - github --- [--force] diff --git a/dot-github/workflows/testing.yml b/dot-github/workflows/testing.yml new file mode 100644 index 0000000..912df4a --- /dev/null +++ b/dot-github/workflows/testing.yml @@ -0,0 +1,52 @@ +name: Testing + +on: + pull_request: + branches: + - main + - master + workflow_dispatch: + workflow_call: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + behat: + strategy: + matrix: + php-version: ['8.0', '7.4'] + runs-on: ubuntu-latest + services: + mysql: + image: mysql:8 + env: + MYSQL_ALLOW_EMPTY_PASSWORD: yes + MYSQL_DATABASE: wp_cli_test + MYSQL_USER: wp_cli_test + MYSQL_PASSWORD: password1 + MYSQL_HOST: 127.0.0.1 + ports: + - 3306 + options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3 + 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: composer + + - name: Install composer packages + run: composer install + + - name: Run Behat + run: composer run behat + env: + WP_CLI_TEST_DBUSER: wp_cli_test + WP_CLI_TEST_DBPASS: password1 + WP_CLI_TEST_DBNAME: wp_cli_test + WP_CLI_TEST_DBHOST: 127.0.0.1:${{ job.services.mysql.ports[3306] }} diff --git a/src/ScaffoldPackageCommand.php b/src/ScaffoldPackageCommand.php index 0ab3be4..fc4f45f 100644 --- a/src/ScaffoldPackageCommand.php +++ b/src/ScaffoldPackageCommand.php @@ -635,6 +635,7 @@ public function package_github( $args, $assoc_args ) { * options: * - travis * - circle + * - github * --- * * [--force] @@ -695,6 +696,9 @@ public function package_tests( $args, $assoc_args ) { } } elseif ( 'circle' === $assoc_args['ci'] ) { $copy_source[ $package_root ]['.circleci/config.yml'] = $package_dir . '.circleci/'; + } elseif ( 'github' === $assoc_args['ci'] ) { + $copy_source[ $package_root ]['dot-github/workflows/testing.yml'] = $package_dir . '.github/workflows/'; + $copy_source[ $package_root ]['behat.yml'] = $package_dir; } $files_written = []; @@ -729,7 +733,7 @@ public function package_tests( $args, $assoc_args ) { $files_written[] = $file_path; if ( ! is_dir( dirname( $file_path ) ) ) { - Process::create( Utils\esc_cmd( 'mkdir %s', dirname( $file_path ) ) )->run(); + Process::create( Utils\esc_cmd( 'mkdir -p %s', dirname( $file_path ) ) )->run(); } Process::create( Utils\esc_cmd( 'touch %s', $file_path ) )->run(); From d675e908a63f1263f92ecd858f91baccf8b9a3d1 Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Thu, 21 Mar 2024 14:36:37 +0545 Subject: [PATCH 2/4] Move testing file to templates --- features/scaffold-package-tests.feature | 14 ++++++++++++++ src/ScaffoldPackageCommand.php | 4 ++-- {dot-github/workflows => templates}/testing.yml | 4 ++-- 3 files changed, 18 insertions(+), 4 deletions(-) rename {dot-github/workflows => templates}/testing.yml (94%) diff --git a/features/scaffold-package-tests.feature b/features/scaffold-package-tests.feature index cfc4597..a1f2167 100644 --- a/features/scaffold-package-tests.feature +++ b/features/scaffold-package-tests.feature @@ -96,6 +96,20 @@ Feature: Scaffold the test suite for an existing package """ And the community-command/.travis.yml file should not exist + Scenario: Scaffolds Github Actions configuration file with argument + When I run `wp scaffold package-tests community-command --ci=github` + Then STDOUT should not be empty + And the community-command/.github/workflows/testing.yml file should exist + And the community-command/.github/workflows/testing.yml file should contain: + """ + composer behat + """ + And the community-command/.github/workflows/testing.yml file should contain: + """ + actions/checkout + """ + And the community-command/.travis.yml file should not exist + Scenario: Don't scaffold features/load-wp-cli.feature when a feature file already exists When I run `wp scaffold package-tests community-command` And I run `mv community-command/features/load-wp-cli.feature community-command/features/command.feature` diff --git a/src/ScaffoldPackageCommand.php b/src/ScaffoldPackageCommand.php index fc4f45f..306a438 100644 --- a/src/ScaffoldPackageCommand.php +++ b/src/ScaffoldPackageCommand.php @@ -697,8 +697,8 @@ public function package_tests( $args, $assoc_args ) { } elseif ( 'circle' === $assoc_args['ci'] ) { $copy_source[ $package_root ]['.circleci/config.yml'] = $package_dir . '.circleci/'; } elseif ( 'github' === $assoc_args['ci'] ) { - $copy_source[ $package_root ]['dot-github/workflows/testing.yml'] = $package_dir . '.github/workflows/'; - $copy_source[ $package_root ]['behat.yml'] = $package_dir; + $copy_source[ $package_root ]['templates/testing.yml'] = $package_dir . '.github/workflows/'; + $copy_source[ $package_root ]['behat.yml'] = $package_dir; } $files_written = []; diff --git a/dot-github/workflows/testing.yml b/templates/testing.yml similarity index 94% rename from dot-github/workflows/testing.yml rename to templates/testing.yml index 912df4a..972fe43 100644 --- a/dot-github/workflows/testing.yml +++ b/templates/testing.yml @@ -16,7 +16,7 @@ jobs: behat: strategy: matrix: - php-version: ['8.0', '7.4'] + php-version: ['8.2', '8.0', '7.4'] runs-on: ubuntu-latest services: mysql: @@ -44,7 +44,7 @@ jobs: run: composer install - name: Run Behat - run: composer run behat + run: composer behat env: WP_CLI_TEST_DBUSER: wp_cli_test WP_CLI_TEST_DBPASS: password1 From ddbf77319dbc3833dbc30a1e7ed85ec8b3099eda Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Sat, 23 Mar 2024 03:34:13 -0700 Subject: [PATCH 3/4] Use a more specific name --- src/ScaffoldPackageCommand.php | 4 ++-- templates/{testing.yml => github-testing.yml} | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename templates/{testing.yml => github-testing.yml} (100%) diff --git a/src/ScaffoldPackageCommand.php b/src/ScaffoldPackageCommand.php index 306a438..48ef52e 100644 --- a/src/ScaffoldPackageCommand.php +++ b/src/ScaffoldPackageCommand.php @@ -697,8 +697,8 @@ public function package_tests( $args, $assoc_args ) { } elseif ( 'circle' === $assoc_args['ci'] ) { $copy_source[ $package_root ]['.circleci/config.yml'] = $package_dir . '.circleci/'; } elseif ( 'github' === $assoc_args['ci'] ) { - $copy_source[ $package_root ]['templates/testing.yml'] = $package_dir . '.github/workflows/'; - $copy_source[ $package_root ]['behat.yml'] = $package_dir; + $copy_source[ $package_root ]['templates/github-testing.yml'] = $package_dir . '.github/workflows/'; + $copy_source[ $package_root ]['behat.yml'] = $package_dir; } $files_written = []; diff --git a/templates/testing.yml b/templates/github-testing.yml similarity index 100% rename from templates/testing.yml rename to templates/github-testing.yml From 06b4cb8eafbdf6b6a18208f2652dff22bd7b0f44 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Sat, 23 Mar 2024 03:38:23 -0700 Subject: [PATCH 4/4] Revert "Use a more specific name" This reverts commit ddbf77319dbc3833dbc30a1e7ed85ec8b3099eda. --- src/ScaffoldPackageCommand.php | 4 ++-- templates/{github-testing.yml => testing.yml} | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename templates/{github-testing.yml => testing.yml} (100%) diff --git a/src/ScaffoldPackageCommand.php b/src/ScaffoldPackageCommand.php index 48ef52e..306a438 100644 --- a/src/ScaffoldPackageCommand.php +++ b/src/ScaffoldPackageCommand.php @@ -697,8 +697,8 @@ public function package_tests( $args, $assoc_args ) { } elseif ( 'circle' === $assoc_args['ci'] ) { $copy_source[ $package_root ]['.circleci/config.yml'] = $package_dir . '.circleci/'; } elseif ( 'github' === $assoc_args['ci'] ) { - $copy_source[ $package_root ]['templates/github-testing.yml'] = $package_dir . '.github/workflows/'; - $copy_source[ $package_root ]['behat.yml'] = $package_dir; + $copy_source[ $package_root ]['templates/testing.yml'] = $package_dir . '.github/workflows/'; + $copy_source[ $package_root ]['behat.yml'] = $package_dir; } $files_written = []; diff --git a/templates/github-testing.yml b/templates/testing.yml similarity index 100% rename from templates/github-testing.yml rename to templates/testing.yml