diff --git a/.puprc-defaults b/.puprc-defaults index 66dee83..68d623e 100644 --- a/.puprc-defaults +++ b/.puprc-defaults @@ -1,6 +1,7 @@ { "build": [], "build_dev": [], + "workflows": {}, "checks": { "tbd": { "fail_method": "error", diff --git a/README.md b/README.md index 03485c7..59c75e8 100644 --- a/README.md +++ b/README.md @@ -20,11 +20,13 @@ This is a CLI utility built by [StellarWP](https://stellarwp.com) for running pr * [`pup check:tbd`](/docs/commands.md#pup-checktbd) * [`pup check:version-conflict`](/docs/commands.md#pup-checkversion-conflict) * [`pup clean`](/docs/commands.md#pup-clean) + * [`pup do`](/docs/commands.md#pup-do) * [`pup get-version`](/docs/commands.md#pup-get-version) * [`pup help`](/docs/commands.md#pup-help) * [`pup i18n`](/docs/commands.md#pup-i18n) * [`pup info`](/docs/commands.md#pup-info) * [`pup package`](/docs/commands.md#pup-package) + * [`pup workflow`](/docs/commands.md#pup-workflow) * [`pup zip`](/docs/commands.md#pup-zip) * [`pup zip-name`](/docs/commands.md#pup-zip-name) * [Command flow for `pup zip`](/docs/flow.md) @@ -35,5 +37,9 @@ This is a CLI utility built by [StellarWP](https://stellarwp.com) for running pr * [Creating custom checks](#creating-custom-checks) * [Simple checks](#simple-checks) * [Class-based checks](#class-based-checks) +* [Workflows](/docs/workflows.md) + * [Defining workflows](/docs/workflows.md#defining-workflows) + * [Calling workflows](/docs/workflows.md#calling-workflows) + * [Pseudo-workflows](/docs/workflows.md#pseudo-workflows) * Examples * [GitHub Workflow: Zipping](/examples/workflows/zip.yml) - Breaks up the `pup zip` command into multiple steps so debugging is easy. diff --git a/docs/commands.md b/docs/commands.md index d9cd819..aebabd8 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -5,11 +5,13 @@ * [`pup check:tbd`](/docs/commands.md#pup-checktbd) * [`pup check:version-conflict`](/docs/commands.md#pup-checkversion-conflict) * [`pup clean`](/docs/commands.md#pup-clean) +* [`pup do`](/docs/commands.md#pup-do) * [`pup get-version`](/docs/commands.md#pup-get-version) * [`pup help`](/docs/commands.md#pup-help) * [`pup i18n`](/docs/commands.md#pup-i18n) * [`pup info`](/docs/commands.md#pup-info) * [`pup package`](/docs/commands.md#pup-package) +* [`pup workflow`](/docs/commands.md#pup-workflow) * [`pup zip`](/docs/commands.md#pup-zip) * [`pup zip-name`](/docs/commands.md#pup-zip-name) @@ -129,6 +131,24 @@ composer -- pup clean |----------|------------------------------------------------------------------------------| | `--root` | **Optional.** Run the command from a different directory from the current. | + +## `pup do` +Alias for `pup workflow`. See `pup help workflow` for more information. + +### Usage +```bash +pup do +# or +composer -- pup do +``` + +### Arguments +| Argument | Description | +|----------|----------------------------------------------------------------------------------------------------------------------------------------------------| +| `workflow` | **Required.** The workflow you would like to run. | +| `--root` | **Optional.** Run the command from a different directory from the current. | + + ## `pup get-version` Gets your project's version number. @@ -250,6 +270,54 @@ composer -- pup package | `version` | **Required.** The version number to use when packaging. You can generate this using [`pup get-version`](/docs/commands.md#pup-get-version) if desired. | | | `--root` | **Optional.** Run the command from a different directory from the current. | + +## `pup workflow` +Run a command workflow. + +An example workflow might look like this: + +```json +{ + "workflow": { + "my-workflow": [ + "npm ci", + "npm run build", + "@composer run some-script" + ] + } +} +``` + +Executing this workflow would work like this: + +```bash +pup workflow my-workflow +# OR +pup do my-workflow +# OR +composer -- pup workflow my-workflow +# OR +composer -- pup do my-workflow +``` + +### Usage +```bash +pup workflow +# or +pup do +# or +composer -- pup workflow +# or +composer -- pup do +``` + +### Arguments +| Argument | Description | +|----------|----------------------------------------------------------------------------------------------------------------------------------------------------| +| `workflow` | **Required.** The workflow you would like to run. | +| `--root` | **Optional.** Run the command from a different directory from the current. | + + ## `pup zip` Runs the full `pup` set of commands to create a zip file. diff --git a/docs/configuration.md b/docs/configuration.md index a80c4d0..90f1e20 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -5,15 +5,16 @@ root of the project. This file is a JSON file that contains the configuration op ## Top-level properties -| Property | Type | Description | -|-------------|----------------|-------------------------------------------------------------------------------------------------------------------------------------| -| `build` | `array` | An array of CLI commands to execute for the build process of your project. | -| `build_dev` | `array` | An array of CLI commands to execute for the `--dev` build process of your project. If empty, it defaults to the value of `build` | -| `checks` | `object` | An object of check configurations indexed by the check's slug. See the [docs for checks](/docs/checks.md) for more info. | -| `paths` | `object` | An object containing paths used by `pup`. [See below](#paths). | -| `repo` | `string`/`null` | The git repo used to clone the project. If not provided, at github URL is generated based on the `name` property of `composer.json` | -| `zip_use_default_ignore` | `boolean` | Whether or not additionally ignore files based on the [`.distignore-defaults`](/.distignore-defaults) file. Defaults to `true`. | -| `zip_name` | `string` | The name of the zip file to be generated. Defaults to the name of the project as set in `composer.json`. | +| Property | Type | Description | +|-------------|-----------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `build` | `array` | An array of CLI commands to execute for the build process of your project. | +| `build_dev` | `array` | An array of CLI commands to execute for the `--dev` build process of your project. If empty, it defaults to the value of `build` | +| `checks` | `object` | An object of check configurations indexed by the check's slug. See the [docs for checks](/docs/checks.md) for more info. | +| `paths` | `object` | An object containing paths used by `pup`. [See below](#paths). | +| `repo` | `string`/`null` | The git repo used to clone the project in the format of `/`. If not provided, at github URL is generated based on the `name` property of `composer.json` | +| `workflows` | `object` | An object of workflow configurations. The index is the workflow slug and the values are arrays of strings that hold commands. See the [docs for workflows](/docs/workflows.md) for more info. | +| `zip_use_default_ignore` | `boolean` | Whether or not additionally ignore files based on the [`.distignore-defaults`](/.distignore-defaults) file. Defaults to `true`. | +| `zip_name` | `string` | The name of the zip file to be generated. Defaults to the name of the project as set in `composer.json`. | ## Paths @@ -135,4 +136,4 @@ This is what you should add as a `paths.versions` entry: ] } } -``` \ No newline at end of file +``` diff --git a/docs/workflows.md b/docs/workflows.md new file mode 100644 index 0000000..acd18fe --- /dev/null +++ b/docs/workflows.md @@ -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 +``` diff --git a/pup b/pup index 8e31b17..61d72bc 100755 --- a/pup +++ b/pup @@ -3,7 +3,7 @@ namespace StellarWP\Pup; -const PUP_VERSION = '1.2.5'; +const PUP_VERSION = '1.3.0'; define( '__PUP_DIR__', __DIR__ ); if ( ! \Phar::running() ) { diff --git a/src/App.php b/src/App.php index 061e2c9..15202a9 100644 --- a/src/App.php +++ b/src/App.php @@ -61,6 +61,7 @@ public function __construct( string $version ) { $this->add( new Commands\I18n() ); $this->add( new Commands\Info() ); $this->add( new Commands\Package() ); + $this->add( new Commands\Workflow() ); $this->add( new Commands\Zip() ); $this->add( new Commands\ZipName() ); diff --git a/src/Commands/Workflow.php b/src/Commands/Workflow.php new file mode 100644 index 0000000..f7f35a6 --- /dev/null +++ b/src/Commands/Workflow.php @@ -0,0 +1,97 @@ +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 "workflows" property in .puprc 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( "The workflow '{$workflow_slug}' does not exist." ); + return 1; + } + + if ( $root ) { + chdir( $root ); + } + + $io->writeln( "Running {$workflow_slug} workflow steps..." ); + foreach ( $workflow->getCommands() as $step ) { + $bail_on_failure = true; + if ( strpos( $step, '@' ) === 0 ) { + $bail_on_failure = false; + $step = substr( $step, 1 ); + } + $io->section( "> {$step}" ); + system( $step, $result ); + $io->newLine(); + + if ( $result ) { + $io->writeln( "[FAIL] Workflow step failed: {$step}" ); + + if ( $bail_on_failure ) { + $io->writeln( "Exiting..." ); + return $result; + } + } + + if ( $root ) { + chdir( $config->getWorkingDir() ); + } + + $io->writeln( 'Workflow complete.' ); + } + + return 0; + } +} diff --git a/src/Config.php b/src/Config.php index 054f17f..46f74ab 100644 --- a/src/Config.php +++ b/src/Config.php @@ -60,11 +60,37 @@ public function __construct() { $this->puprc_file_path = $this->working_dir . '.puprc'; $this->mergeConfigWithDefaults(); + $this->buildWorkflows(); $this->parseCheckConfig(); $this->parseVersionFiles(); $this->validateConfig(); } + /** + * Builds the workflows from the config. + * + * @return void + */ + public function buildWorkflows() { + $collection = new Workflow\Collection(); + + if ( empty( $this->config->workflows->build ) && ! empty( $this->config->build ) ) { + $collection->add( new Workflow\Workflow( 'build', $this->config->build ) ); + } + + if ( empty( $this->config->workflows->build_dev ) && ! empty( $this->config->build_dev ) ) { + $collection->add( new Workflow\Workflow( 'build_dev', $this->config->build_dev ) ); + } + + if ( ! empty( $this->config->workflows ) ) { + foreach ( $this->config->workflows as $slug => $commands ) { + $collection->add( new Workflow\Workflow( $slug, $commands ) ); + } + } + + $this->config->workflows = $collection; + } + /** * Merges the local .puprc (if it exists) with the default .puprc-defaults. * @@ -478,6 +504,15 @@ public function getVersionFiles() : array { return $this->config->paths['versions']; } + /** + * Get the workflows from the config. + * + * @return Workflow\Collection + */ + public function getWorkflows(): Workflow\Collection { + return $this->config->workflows; + } + /** * @return string */ diff --git a/src/VersionFile.php b/src/VersionFile.php index 541f171..85159c8 100644 --- a/src/VersionFile.php +++ b/src/VersionFile.php @@ -49,10 +49,11 @@ public function getRegex(): string { /** * @inheritdoc */ + #[\ReturnTypeWillChange] public function jsonSerialize() { return [ 'file' => $this->getPath(), 'regex' => $this->getRegex(), ]; } -} \ No newline at end of file +} diff --git a/src/Workflow/Collection.php b/src/Workflow/Collection.php new file mode 100644 index 0000000..07db949 --- /dev/null +++ b/src/Workflow/Collection.php @@ -0,0 +1,150 @@ + + */ + protected $workflows = []; + + /** + * Adds a workflow to the collection. + * + * @since 1.0.0 + * + * @param Workflow $workflow Workflow instance. + * + * @return mixed + */ + public function add( Workflow $workflow ) { + $this->offsetSet( $workflow->getSlug(), $workflow ); + + return $this->offsetGet( $workflow->getSlug() ); + } + + /** + * @inheritDoc + */ + #[\ReturnTypeWillChange] + public function current() { + return current( $this->workflows ); + } + + /** + * Grabs a workflow from the collection. + * + * @param string $offset Workflow slug. + * + * @return Workflow|null + */ + #[\ReturnTypeWillChange] + public function get( $offset ) { + return $this->offsetGet( $offset ); + } + + /** + * @inheritDoc + */ + #[\ReturnTypeWillChange] + public function key() { + return key( $this->workflows ); + } + + /** + * @inheritDoc + */ + #[\ReturnTypeWillChange] + public function next() { + next( $this->workflows ); + } + + /** + * @inheritDoc + */ + public function offsetExists( $offset ): bool { + return isset( $this->workflows[ $offset ] ); + } + + /** + * @inheritDoc + */ + #[\ReturnTypeWillChange] + public function offsetGet( $offset ) { + if ( ! isset( $this->workflows[ $offset ] ) ) { + return null; + } + return $this->workflows[ $offset ]; + } + + /** + * @inheritDoc + */ + #[\ReturnTypeWillChange] + public function offsetSet( $offset, $value ) { + if ( ! $value instanceof Workflow ) { + throw new BaseException( 'The value must be an instance of ' . Workflow::class . '.' ); + } + + $this->workflows[ $offset ] = $value; // @phpstan-ignore-line - This is a valid assignment. + } + + /** + * @inheritDoc + */ + #[\ReturnTypeWillChange] + public function offsetUnset( $offset ) { + unset( $this->workflows[ $offset ] ); + } + + /** + * Helper function for removing a resource from the collection. + * + * @since 1.0.0 + * + * @param string $slug Workflow slug. + * + * @return void + */ + public function remove( $slug ) { + $this->offsetUnset( $slug ); + } + + /** + * @inheritDoc + */ + #[\ReturnTypeWillChange] + public function rewind() { + reset( $this->workflows ); + } + + /** + * Sets a resource in the collection. + * + * @param string $slug Workflow slug. + * @param Workflow $workflow Workflow instance. + * + * @return Workflow|null + */ + public function set( $slug, Workflow $workflow ) { + $this->offsetSet( $slug, $workflow ); + + return $this->offsetGet( $slug ); + } + + /** + * @inheritDoc + */ + public function valid(): bool { + return key( $this->workflows ) !== null; + } + + #[\ReturnTypeWillChange] + public function count() { + return count( $this->workflows ); + } +} diff --git a/src/Workflow/Workflow.php b/src/Workflow/Workflow.php new file mode 100644 index 0000000..d17b100 --- /dev/null +++ b/src/Workflow/Workflow.php @@ -0,0 +1,38 @@ + + */ + protected $commands; + + /** + * @param string $slug Workflow ID. + * @param array $commands Workflow commands. + */ + public function __construct( $slug, $commands ) { + $this->slug = $slug; + $this->commands = $commands; + } + + /** + * @return string + */ + public function getSlug(): string { + return $this->slug; + } + + /** + * @return array + */ + public function getCommands(): array { + return $this->commands; + } +} diff --git a/tests/cli/Commands/HelpCest.php b/tests/cli/Commands/HelpCest.php index a2bf682..2bb442b 100644 --- a/tests/cli/Commands/HelpCest.php +++ b/tests/cli/Commands/HelpCest.php @@ -54,10 +54,12 @@ protected function topicProvider(): array { [ 'topic' => 'check' ], [ 'topic' => 'check:tbd' ], [ 'topic' => 'check:version-conflict' ], + [ 'topic' => 'do' ], [ 'topic' => 'help' ], [ 'topic' => 'i18n' ], [ 'topic' => 'get-version' ], [ 'topic' => 'package' ], + [ 'topic' => 'workflow' ], [ 'topic' => 'zip' ], [ 'topic' => 'zip-name' ], ]; diff --git a/tests/cli/Commands/WorkflowCest.php b/tests/cli/Commands/WorkflowCest.php new file mode 100644 index 0000000..567f935 --- /dev/null +++ b/tests/cli/Commands/WorkflowCest.php @@ -0,0 +1,130 @@ +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 ); + } +} diff --git a/tests/cli/Commands/__snapshots__/HelpCest__it_should_default_to_help__0.snapshot.txt b/tests/cli/Commands/__snapshots__/HelpCest__it_should_default_to_help__0.snapshot.txt index 9908de2..79eb04b 100644 --- a/tests/cli/Commands/__snapshots__/HelpCest__it_should_default_to_help__0.snapshot.txt +++ b/tests/cli/Commands/__snapshots__/HelpCest__it_should_default_to_help__0.snapshot.txt @@ -16,11 +16,13 @@ Run pup help for more information on a specific command. check:version-conflict Verifies that all of your version numbers match. check Runs all registered check commands. clean This command cleans up any directories that pup creates. + do Alias for pup workflow. See pup help workflow for more information. get-version Gets your project's version number. help Shows the help menu. i18n Pulls in translations from a GlotPress instance. info Gets pup details for the current project. package Packages your project into a zip file with the passed in version number. + workflow Run a command workflow. zip-name Gets your project's zip name (sans the .zip extension). zip Runs the full pup set of commands to create a zip file. ------------------------ ------------------------------------------------------------------------------- diff --git a/tests/cli/Commands/__snapshots__/HelpCest__it_should_run_help__0.snapshot.txt b/tests/cli/Commands/__snapshots__/HelpCest__it_should_run_help__0.snapshot.txt index 9908de2..79eb04b 100644 --- a/tests/cli/Commands/__snapshots__/HelpCest__it_should_run_help__0.snapshot.txt +++ b/tests/cli/Commands/__snapshots__/HelpCest__it_should_run_help__0.snapshot.txt @@ -16,11 +16,13 @@ Run pup help for more information on a specific command. check:version-conflict Verifies that all of your version numbers match. check Runs all registered check commands. clean This command cleans up any directories that pup creates. + do Alias for pup workflow. See pup help workflow for more information. get-version Gets your project's version number. help Shows the help menu. i18n Pulls in translations from a GlotPress instance. info Gets pup details for the current project. package Packages your project into a zip file with the passed in version number. + workflow Run a command workflow. zip-name Gets your project's zip name (sans the .zip extension). zip Runs the full pup set of commands to create a zip file. ------------------------ ------------------------------------------------------------------------------- diff --git a/tests/cli/Commands/__snapshots__/HelpCest__it_should_show_topic_docs__10.snapshot.txt b/tests/cli/Commands/__snapshots__/HelpCest__it_should_show_topic_docs__10.snapshot.txt new file mode 100644 index 0000000..aba0b50 --- /dev/null +++ b/tests/cli/Commands/__snapshots__/HelpCest__it_should_show_topic_docs__10.snapshot.txt @@ -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. diff --git a/tests/cli/Commands/__snapshots__/HelpCest__it_should_show_topic_docs__9.snapshot.txt b/tests/cli/Commands/__snapshots__/HelpCest__it_should_show_topic_docs__9.snapshot.txt new file mode 100644 index 0000000..aba0b50 --- /dev/null +++ b/tests/cli/Commands/__snapshots__/HelpCest__it_should_show_topic_docs__9.snapshot.txt @@ -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. diff --git a/tests/cli/Commands/__snapshots__/InfoCest__it_should_provide_info__0.snapshot.txt b/tests/cli/Commands/__snapshots__/InfoCest__it_should_provide_info__0.snapshot.txt index b484193..99581eb 100644 --- a/tests/cli/Commands/__snapshots__/InfoCest__it_should_provide_info__0.snapshot.txt +++ b/tests/cli/Commands/__snapshots__/InfoCest__it_should_provide_info__0.snapshot.txt @@ -24,6 +24,7 @@ Config { "build": [], "build_dev": [], + "workflows": {}, "checks": { "tbd": { "fail_method": "error", diff --git a/tests/cli/Commands/__snapshots__/InfoCest__it_should_provide_info_with_distignore__0.snapshot.txt b/tests/cli/Commands/__snapshots__/InfoCest__it_should_provide_info_with_distignore__0.snapshot.txt index 6225f7c..2c591b0 100644 --- a/tests/cli/Commands/__snapshots__/InfoCest__it_should_provide_info_with_distignore__0.snapshot.txt +++ b/tests/cli/Commands/__snapshots__/InfoCest__it_should_provide_info_with_distignore__0.snapshot.txt @@ -24,6 +24,7 @@ Config { "build": [], "build_dev": [], + "workflows": {}, "checks": { "tbd": { "fail_method": "error", diff --git a/tests/cli/Commands/__snapshots__/InfoCest__it_should_provide_info_with_distinclude__0.snapshot.txt b/tests/cli/Commands/__snapshots__/InfoCest__it_should_provide_info_with_distinclude__0.snapshot.txt index 2fac089..fc9f180 100644 --- a/tests/cli/Commands/__snapshots__/InfoCest__it_should_provide_info_with_distinclude__0.snapshot.txt +++ b/tests/cli/Commands/__snapshots__/InfoCest__it_should_provide_info_with_distinclude__0.snapshot.txt @@ -24,6 +24,7 @@ Config { "build": [], "build_dev": [], + "workflows": {}, "checks": { "tbd": { "fail_method": "error", diff --git a/tests/cli/Commands/__snapshots__/InfoCest__it_should_provide_info_with_gitattributes__0.snapshot.txt b/tests/cli/Commands/__snapshots__/InfoCest__it_should_provide_info_with_gitattributes__0.snapshot.txt index 2c3fb1b..d5086d0 100644 --- a/tests/cli/Commands/__snapshots__/InfoCest__it_should_provide_info_with_gitattributes__0.snapshot.txt +++ b/tests/cli/Commands/__snapshots__/InfoCest__it_should_provide_info_with_gitattributes__0.snapshot.txt @@ -24,6 +24,7 @@ Config { "build": [], "build_dev": [], + "workflows": {}, "checks": { "tbd": { "fail_method": "error", diff --git a/tests/cli/Commands/__snapshots__/InfoCest__it_should_provide_info_with_puprc__0.snapshot.txt b/tests/cli/Commands/__snapshots__/InfoCest__it_should_provide_info_with_puprc__0.snapshot.txt index db11737..b0a60d0 100644 --- a/tests/cli/Commands/__snapshots__/InfoCest__it_should_provide_info_with_puprc__0.snapshot.txt +++ b/tests/cli/Commands/__snapshots__/InfoCest__it_should_provide_info_with_puprc__0.snapshot.txt @@ -26,6 +26,7 @@ Config "ls -a" ], "build_dev": [], + "workflows": {}, "checks": { "tbd": { "fail_method": "error", diff --git a/tests/cli/Commands/__snapshots__/InfoCest__it_should_show_invalid_puprc__0.snapshot.txt b/tests/cli/Commands/__snapshots__/InfoCest__it_should_show_invalid_puprc__0.snapshot.txt index 41dc6b8..6b198bd 100644 --- a/tests/cli/Commands/__snapshots__/InfoCest__it_should_show_invalid_puprc__0.snapshot.txt +++ b/tests/cli/Commands/__snapshots__/InfoCest__it_should_show_invalid_puprc__0.snapshot.txt @@ -24,6 +24,7 @@ Config { "build": [], "build_dev": [], + "workflows": {}, "checks": { "tbd": { "fail_method": "error", diff --git a/tests/cli/Commands/__snapshots__/WorkflowCest__it_should_fail_non_existent_workflow__0.snapshot.txt b/tests/cli/Commands/__snapshots__/WorkflowCest__it_should_fail_non_existent_workflow__0.snapshot.txt new file mode 100644 index 0000000..50424f0 --- /dev/null +++ b/tests/cli/Commands/__snapshots__/WorkflowCest__it_should_fail_non_existent_workflow__0.snapshot.txt @@ -0,0 +1 @@ +The workflow 'whee' does not exist. \ No newline at end of file diff --git a/tests/cli/Commands/__snapshots__/WorkflowCest__it_should_run_an_empty_workflow__0.snapshot.txt b/tests/cli/Commands/__snapshots__/WorkflowCest__it_should_run_an_empty_workflow__0.snapshot.txt new file mode 100644 index 0000000..9f76af8 --- /dev/null +++ b/tests/cli/Commands/__snapshots__/WorkflowCest__it_should_run_an_empty_workflow__0.snapshot.txt @@ -0,0 +1 @@ +Running bork workflow steps... \ No newline at end of file diff --git a/tests/cli/Commands/__snapshots__/WorkflowCest__it_should_run_build_as_workflow__0.snapshot.txt b/tests/cli/Commands/__snapshots__/WorkflowCest__it_should_run_build_as_workflow__0.snapshot.txt new file mode 100644 index 0000000..85cb5e0 --- /dev/null +++ b/tests/cli/Commands/__snapshots__/WorkflowCest__it_should_run_build_as_workflow__0.snapshot.txt @@ -0,0 +1,21 @@ +Running build workflow steps... + +> ls -a +------- + +. +.. +.puprc +bootstrap.php +other-file.php +package.json +src + +Workflow complete. + +> echo "fake project, yo" +------------------------- + +fake project, yo + +Workflow complete. \ No newline at end of file diff --git a/tests/cli/Commands/__snapshots__/WorkflowCest__it_should_run_build_dev_as_workflow__0.snapshot.txt b/tests/cli/Commands/__snapshots__/WorkflowCest__it_should_run_build_dev_as_workflow__0.snapshot.txt new file mode 100644 index 0000000..cc1cc37 --- /dev/null +++ b/tests/cli/Commands/__snapshots__/WorkflowCest__it_should_run_build_dev_as_workflow__0.snapshot.txt @@ -0,0 +1,8 @@ +Running build_dev workflow steps... + +> echo "fake project, yo" +------------------------- + +fake project, yo + +Workflow complete. \ No newline at end of file diff --git a/tests/cli/Commands/__snapshots__/WorkflowCest__it_should_run_do__0.snapshot.txt b/tests/cli/Commands/__snapshots__/WorkflowCest__it_should_run_do__0.snapshot.txt new file mode 100644 index 0000000..0e7d87e --- /dev/null +++ b/tests/cli/Commands/__snapshots__/WorkflowCest__it_should_run_do__0.snapshot.txt @@ -0,0 +1,8 @@ +Running bork workflow steps... + +> echo "fake project, yo" +------------------------- + +fake project, yo + +Workflow complete. \ No newline at end of file diff --git a/tests/cli/Commands/__snapshots__/WorkflowCest__it_should_run_workflow__0.snapshot.txt b/tests/cli/Commands/__snapshots__/WorkflowCest__it_should_run_workflow__0.snapshot.txt new file mode 100644 index 0000000..0e7d87e --- /dev/null +++ b/tests/cli/Commands/__snapshots__/WorkflowCest__it_should_run_workflow__0.snapshot.txt @@ -0,0 +1,8 @@ +Running bork workflow steps... + +> echo "fake project, yo" +------------------------- + +fake project, yo + +Workflow complete. \ No newline at end of file