Skip to content

Commit 8819088

Browse files
Add github option for --ci in scaffold package tests (#237)
* Add GH actions in scaffold package test * Move testing file to templates * Use a more specific name * Revert "Use a more specific name" This reverts commit ddbf773. --------- Co-authored-by: Daniel Bachhuber <daniel.bachhuber@automattic.com>
1 parent 195ccb1 commit 8819088

File tree

4 files changed

+72
-1
lines changed

4 files changed

+72
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ WP-CLI Behat framework uses Behat ~2.5, which is installed with Composer.
174174
options:
175175
- travis
176176
- circle
177+
- github
177178
---
178179

179180
[--force]

features/scaffold-package-tests.feature

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,20 @@ Feature: Scaffold the test suite for an existing package
9696
"""
9797
And the community-command/.travis.yml file should not exist
9898

99+
Scenario: Scaffolds Github Actions configuration file with argument
100+
When I run `wp scaffold package-tests community-command --ci=github`
101+
Then STDOUT should not be empty
102+
And the community-command/.github/workflows/testing.yml file should exist
103+
And the community-command/.github/workflows/testing.yml file should contain:
104+
"""
105+
composer behat
106+
"""
107+
And the community-command/.github/workflows/testing.yml file should contain:
108+
"""
109+
actions/checkout
110+
"""
111+
And the community-command/.travis.yml file should not exist
112+
99113
Scenario: Don't scaffold features/load-wp-cli.feature when a feature file already exists
100114
When I run `wp scaffold package-tests community-command`
101115
And I run `mv community-command/features/load-wp-cli.feature community-command/features/command.feature`

src/ScaffoldPackageCommand.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ public function package_github( $args, $assoc_args ) {
635635
* options:
636636
* - travis
637637
* - circle
638+
* - github
638639
* ---
639640
*
640641
* [--force]
@@ -695,6 +696,9 @@ public function package_tests( $args, $assoc_args ) {
695696
}
696697
} elseif ( 'circle' === $assoc_args['ci'] ) {
697698
$copy_source[ $package_root ]['.circleci/config.yml'] = $package_dir . '.circleci/';
699+
} elseif ( 'github' === $assoc_args['ci'] ) {
700+
$copy_source[ $package_root ]['templates/testing.yml'] = $package_dir . '.github/workflows/';
701+
$copy_source[ $package_root ]['behat.yml'] = $package_dir;
698702
}
699703

700704
$files_written = [];
@@ -729,7 +733,7 @@ public function package_tests( $args, $assoc_args ) {
729733
$files_written[] = $file_path;
730734

731735
if ( ! is_dir( dirname( $file_path ) ) ) {
732-
Process::create( Utils\esc_cmd( 'mkdir %s', dirname( $file_path ) ) )->run();
736+
Process::create( Utils\esc_cmd( 'mkdir -p %s', dirname( $file_path ) ) )->run();
733737
}
734738

735739
Process::create( Utils\esc_cmd( 'touch %s', $file_path ) )->run();

templates/testing.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Testing
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
- master
8+
workflow_dispatch:
9+
workflow_call:
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
behat:
17+
strategy:
18+
matrix:
19+
php-version: ['8.2', '8.0', '7.4']
20+
runs-on: ubuntu-latest
21+
services:
22+
mysql:
23+
image: mysql:8
24+
env:
25+
MYSQL_ALLOW_EMPTY_PASSWORD: yes
26+
MYSQL_DATABASE: wp_cli_test
27+
MYSQL_USER: wp_cli_test
28+
MYSQL_PASSWORD: password1
29+
MYSQL_HOST: 127.0.0.1
30+
ports:
31+
- 3306
32+
options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3
33+
steps:
34+
- name: Check out source code
35+
uses: actions/checkout@v4
36+
37+
- name: Setup PHP
38+
uses: shivammathur/setup-php@v2
39+
with:
40+
php-version: ${{ matrix.php-version }}
41+
tools: composer
42+
43+
- name: Install composer packages
44+
run: composer install
45+
46+
- name: Run Behat
47+
run: composer behat
48+
env:
49+
WP_CLI_TEST_DBUSER: wp_cli_test
50+
WP_CLI_TEST_DBPASS: password1
51+
WP_CLI_TEST_DBNAME: wp_cli_test
52+
WP_CLI_TEST_DBHOST: 127.0.0.1:${{ job.services.mysql.ports[3306] }}

0 commit comments

Comments
 (0)