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 option for --ci in scaffold package tests #237

Merged
merged 4 commits into from
Mar 23, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ WP-CLI Behat framework uses Behat ~2.5, which is installed with Composer.
options:
- travis
- circle
- github
---

[--force]
Expand Down
14 changes: 14 additions & 0 deletions features/scaffold-package-tests.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
6 changes: 5 additions & 1 deletion src/ScaffoldPackageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,7 @@ public function package_github( $args, $assoc_args ) {
* options:
* - travis
* - circle
* - github
* ---
*
* [--force]
Expand Down Expand Up @@ -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 ]['templates/testing.yml'] = $package_dir . '.github/workflows/';
$copy_source[ $package_root ]['behat.yml'] = $package_dir;
}

$files_written = [];
Expand Down Expand Up @@ -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();
Expand Down
52 changes: 52 additions & 0 deletions templates/testing.yml
Original file line number Diff line number Diff line change
@@ -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.2', '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 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] }}