-
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.
Merge pull request #17 from stellarwp/feature/workflows
Implement pup workflows and add docs
- Loading branch information
Showing
30 changed files
with
741 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?php | ||
|
||
namespace StellarWP\Pup\Commands; | ||
|
||
use StellarWP\Pup\App; | ||
use StellarWP\Pup\Exceptions\BaseException; | ||
use StellarWP\Pup\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class Workflow extends Command { | ||
/** | ||
* @inheritDoc | ||
* | ||
* @return void | ||
*/ | ||
protected function configure() { | ||
$this->setName( 'workflow' ) | ||
->setAliases( [ 'do' ] ) | ||
->addArgument( 'workflow', InputArgument::REQUIRED, 'The workflow you would like to run.' ) | ||
->addOption( 'root', null, InputOption::VALUE_REQUIRED, 'Set the root directory for running commands.' ) | ||
->setDescription( 'Run a command workflow.' ) | ||
->setHelp( 'Run a command workflow.' ); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
protected function execute( InputInterface $input, OutputInterface $output ) { | ||
parent::execute( $input, $output ); | ||
$config = App::getConfig(); | ||
$root = $input->getOption( 'root' ); | ||
$workflow_slug = $input->getArgument( 'workflow' ); | ||
$io = $this->getIO(); | ||
$application = $this->getApplication(); | ||
if ( ! $application ) { | ||
throw new BaseException( 'Could not run pup.' ); | ||
} | ||
|
||
$collection = $config->getWorkflows(); | ||
|
||
if ( $collection->count() === 0 ) { | ||
$io->writeln( '📣 The .puprc does not have any workflows configured.' ); | ||
$io->writeln( '💡 If you would like to use workflows, simply add a "<comment>workflows</comment>" property in <comment>.puprc</comment> similar to:' ); | ||
$io->writeln( '' ); | ||
$io->writeln( '"workflows": {' ); | ||
$io->writeln( ' "my-workflow": [' ); | ||
$io->writeln( ' "composer install",' ); | ||
$io->writeln( ' "npm run build"' ); | ||
$io->writeln( ' ]' ); | ||
$io->writeln( '}' ); | ||
$io->writeln( '' ); | ||
return 0; | ||
} | ||
|
||
$workflow = $collection->get( $workflow_slug ); | ||
if ( ! $workflow ) { | ||
$io->writeln( "<error>The workflow '{$workflow_slug}' does not exist.</error>" ); | ||
return 1; | ||
} | ||
|
||
if ( $root ) { | ||
chdir( $root ); | ||
} | ||
|
||
$io->writeln( "<comment>Running {$workflow_slug} workflow steps...</comment>" ); | ||
foreach ( $workflow->getCommands() as $step ) { | ||
$bail_on_failure = true; | ||
if ( strpos( $step, '@' ) === 0 ) { | ||
$bail_on_failure = false; | ||
$step = substr( $step, 1 ); | ||
} | ||
$io->section( "> <fg=cyan>{$step}</>" ); | ||
system( $step, $result ); | ||
$io->newLine(); | ||
|
||
if ( $result ) { | ||
$io->writeln( "[FAIL] Workflow step failed: {$step}" ); | ||
|
||
if ( $bail_on_failure ) { | ||
$io->writeln( "<fg=red>Exiting...</>" ); | ||
return $result; | ||
} | ||
} | ||
|
||
if ( $root ) { | ||
chdir( $config->getWorkingDir() ); | ||
} | ||
|
||
$io->writeln( '<info>Workflow complete.</info>' ); | ||
} | ||
|
||
return 0; | ||
} | ||
} |
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
Oops, something went wrong.