-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement pup workflows and add docs
- Loading branch information
test
committed
Apr 25, 2024
1 parent
9094b4a
commit 1032be0
Showing
25 changed files
with
379 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"build": [], | ||
"build_dev": [], | ||
"workflows": {}, | ||
"checks": { | ||
"tbd": { | ||
"fail_method": "error", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Workflows | ||
|
||
Workflows are a way to declare a series of commands that you want to run in a specific order. This allows you to specify | ||
workflows that differ from the `build` and `build_dev` commands. | ||
|
||
* [Defining workflows](#defining-workflows) | ||
* [Calling workflows](#calling-workflows) | ||
* [Pseudo-workflows](#pseudo-workflows) | ||
|
||
## Defining workflows | ||
|
||
Workflows are defined in the `workflows` property of your `.puprc` file. | ||
|
||
```json | ||
{ | ||
"workflows": { | ||
"my-workflow": [ | ||
"npm ci", | ||
"npm run build", | ||
"@composer run some-script" | ||
], | ||
"my-other-workflow": [ | ||
"@composer run some-other-script", | ||
"@composer run make-pot" | ||
] | ||
} | ||
} | ||
``` | ||
|
||
## Calling workflows | ||
|
||
You can call a workflow by running the `workflow` command (or its alias `do`) with the name of the workflow as an argument. | ||
|
||
```bash | ||
pup workflow my-workflow | ||
# OR | ||
pup do my-workflow | ||
``` | ||
|
||
## Pseudo-workflows | ||
|
||
The `build` and `build_dev` properties within your `.puprc` file are also callable via the `workflow` command. | ||
|
||
```bash | ||
pup workflow build | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
<?php | ||
|
||
namespace StellarWP\Pup\Tests\Cli\Commands; | ||
|
||
use StellarWP\Pup\Tests\Cli\AbstractBase; | ||
use StellarWP\Pup\Tests\CliTester; | ||
|
||
class WorkflowCest extends AbstractBase { | ||
public function _before( CliTester $I ) { | ||
parent::_before( $I ); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_should_run_workflow( CliTester $I ) { | ||
$puprc = $this->get_puprc(); | ||
$puprc['workflows'] = []; | ||
$puprc['workflows']['bork'] = []; | ||
$puprc['workflows']['bork'][] = 'echo "fake project, yo"'; | ||
$this->write_puprc( $puprc ); | ||
|
||
chdir( $this->tests_root . '/_data/fake-project' ); | ||
|
||
$I->runShellCommand( "php {$this->pup} workflow bork" ); | ||
$I->seeResultCodeIs( 0 ); | ||
$I->seeInShellOutput( 'fake project, yo' ); | ||
$I->seeInShellOutput( 'Workflow complete.' ); | ||
|
||
$output = $I->grabShellOutput(); | ||
$this->assertMatchesStringSnapshot( $output ); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_should_run_do( CliTester $I ) { | ||
$puprc = $this->get_puprc(); | ||
$puprc['workflows'] = []; | ||
$puprc['workflows']['bork'] = []; | ||
$puprc['workflows']['bork'][] = 'echo "fake project, yo"'; | ||
$this->write_puprc( $puprc ); | ||
|
||
chdir( $this->tests_root . '/_data/fake-project' ); | ||
|
||
$I->runShellCommand( "php {$this->pup} do bork" ); | ||
$I->seeResultCodeIs( 0 ); | ||
$I->seeInShellOutput( 'fake project, yo' ); | ||
$I->seeInShellOutput( 'Workflow complete.' ); | ||
|
||
$output = $I->grabShellOutput(); | ||
$this->assertMatchesStringSnapshot( $output ); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_should_run_build_as_workflow( CliTester $I ) { | ||
$puprc = $this->get_puprc(); | ||
$puprc['build'][] = 'echo "fake project, yo"'; | ||
$this->write_puprc( $puprc ); | ||
|
||
chdir( $this->tests_root . '/_data/fake-project' ); | ||
|
||
$I->runShellCommand( "php {$this->pup} do build" ); | ||
$I->seeResultCodeIs( 0 ); | ||
$I->seeInShellOutput( 'fake project, yo' ); | ||
$I->seeInShellOutput( 'Workflow complete.' ); | ||
|
||
$output = $I->grabShellOutput(); | ||
$this->assertMatchesStringSnapshot( $output ); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_should_run_build_dev_as_workflow( CliTester $I ) { | ||
$puprc = $this->get_puprc(); | ||
$puprc['build_dev'][] = 'echo "fake project, yo"'; | ||
$this->write_puprc( $puprc ); | ||
|
||
chdir( $this->tests_root . '/_data/fake-project' ); | ||
|
||
$I->runShellCommand( "php {$this->pup} do build_dev" ); | ||
$I->seeResultCodeIs( 0 ); | ||
$I->seeInShellOutput( 'fake project, yo' ); | ||
$I->seeInShellOutput( 'Workflow complete.' ); | ||
|
||
$output = $I->grabShellOutput(); | ||
$this->assertMatchesStringSnapshot( $output ); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_should_run_an_empty_workflow( CliTester $I ) { | ||
$puprc = $this->get_puprc(); | ||
$puprc['workflows'] = []; | ||
$puprc['workflows']['bork'] = []; | ||
$this->write_puprc( $puprc ); | ||
|
||
chdir( $this->tests_root . '/_data/fake-project' ); | ||
|
||
$I->runShellCommand( "php {$this->pup} do bork" ); | ||
$I->seeResultCodeIs( 0 ); | ||
|
||
$output = $I->grabShellOutput(); | ||
$this->assertMatchesStringSnapshot( $output ); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_should_fail_non_existent_workflow( CliTester $I ) { | ||
$puprc = $this->get_puprc(); | ||
$puprc['workflows'] = []; | ||
$puprc['workflows']['bork'] = []; | ||
$puprc['workflows']['bork'][] = 'echo "fake project, yo"'; | ||
$this->write_puprc( $puprc ); | ||
|
||
chdir( $this->tests_root . '/_data/fake-project' ); | ||
|
||
$I->runShellCommand( "php {$this->pup} workflow whee", false ); | ||
$I->seeResultCodeIs( 1 ); | ||
$I->seeInShellOutput( '\'whee\' does not exist.' ); | ||
|
||
$output = $I->grabShellOutput(); | ||
$this->assertMatchesStringSnapshot( $output ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
tests/cli/Commands/__snapshots__/HelpCest__it_should_show_topic_docs__10.snapshot.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
|
||
Help: pup build | ||
=============== | ||
|
||
Runs the build commands from the .puprc file. | ||
|
||
|
||
If you want your dev builds to build differently, you can add a build_dev property to your .puprc file. | ||
|
||
> Usage: | ||
-------- | ||
|
||
.................................................. | ||
pup build [--dev] | ||
# or | ||
composer -- pup build [--dev] | ||
.................................................. | ||
|
||
> Arguments: | ||
------------ | ||
|
||
---------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- | ||
Argument Description | ||
---------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- | ||
--dev Optional. Whether or not this is a dev build. Using this option will run the build_dev commands from your .puprc file if they exist, otherwise it will run build commands. | ||
--root Optional. Run the command from a different directory from the current. | ||
---------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- | ||
|
||
|
||
> Specifying build commands: | ||
---------------------------- | ||
|
||
You can specify build commands within your .puprc file by adding to either the build or build_dev properties. These | ||
commands will be run in the order they are specified. By default, if any command fails, the build will fail. You can, | ||
however, prepend your commands with @ and that will tell pup to ignore failures for that step. Here's an example: | ||
|
||
.................................................. | ||
{ | ||
"build": [ | ||
"npm ci", | ||
"npm run build", | ||
"@composer run some-script" | ||
] | ||
} | ||
.................................................. | ||
|
||
In the above example, npm ci and npm run build will need to complete successfully for the build to succeed, but the | ||
composer run some-script is prepended by @ so if it fails, the build will continue forward. |
Oops, something went wrong.