From b1a25e0d4868b667497879c686c1cb7bc168a9c4 Mon Sep 17 00:00:00 2001 From: test Date: Mon, 22 Apr 2024 10:47:19 -0400 Subject: [PATCH 01/12] Adding pup workflow support --- docs/commands.md | 24 +++++++ src/App.php | 13 ++++ src/Commands/Workflow.php | 98 ++++++++++++++++++++++++++ src/Config.php | 37 ++++++++++ src/Workflow/Collection.php | 135 ++++++++++++++++++++++++++++++++++++ src/Workflow/Workflow.php | 38 ++++++++++ 6 files changed, 345 insertions(+) create mode 100644 src/Commands/Workflow.php create mode 100644 src/Workflow/Collection.php create mode 100644 src/Workflow/Workflow.php diff --git a/docs/commands.md b/docs/commands.md index d9cd819..33aa69b 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) @@ -250,6 +252,28 @@ 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. + +### 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/src/App.php b/src/App.php index 061e2c9..c129a14 100644 --- a/src/App.php +++ b/src/App.php @@ -197,6 +197,19 @@ public static function getConfig(): Config { return static::$config; } + /** + * Get the workflow collection. + * + * @return Workflow\Collection + */ + public static function getWorkflowCollection(): Workflow\Collection { + if ( ! isset( static::$workflow_collection ) ) { + static::$workflow_collection = new Workflow\Collection(); + } + + return static::$workflow_collection; + } + /** * Sets whether the app is running from a phar. * diff --git a/src/Commands/Workflow.php b/src/Commands/Workflow.php new file mode 100644 index 0000000..c3b6615 --- /dev/null +++ b/src/Commands/Workflow.php @@ -0,0 +1,98 @@ +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 = App::getWorkflowCollection(); + $failures = []; + + 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..aab89cf 100644 --- a/src/Config.php +++ b/src/Config.php @@ -60,11 +60,39 @@ 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() { + if ( empty( $this->config->workflows ) ) { + return; + } + + $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 ) ); + } + + 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 +506,15 @@ public function getVersionFiles() : array { return $this->config->paths['versions']; } + /** + * Get the workflows from the config. + * + * @return array + */ + public function getWorkflows(): array { + return $this->config->workflows; + } + /** * @return string */ diff --git a/src/Workflow/Collection.php b/src/Workflow/Collection.php new file mode 100644 index 0000000..f73afd9 --- /dev/null +++ b/src/Workflow/Collection.php @@ -0,0 +1,135 @@ + + */ + 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 ); + } + + /** + * @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 ) { + 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; + } +} From 9094b4a626a7d3e9c60fa8aeb33e3140e318b01a Mon Sep 17 00:00:00 2001 From: test Date: Mon, 22 Apr 2024 11:01:03 -0400 Subject: [PATCH 02/12] Finalize the parsing and processing of workflows. Add docs --- docs/commands.md | 18 ++++++++++++++++++ src/App.php | 14 +------------- src/Commands/Workflow.php | 5 ++--- src/Config.php | 14 ++++++-------- src/Workflow/Collection.php | 8 ++++++++ 5 files changed, 35 insertions(+), 24 deletions(-) diff --git a/docs/commands.md b/docs/commands.md index 33aa69b..1d43fc5 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -131,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. diff --git a/src/App.php b/src/App.php index c129a14..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() ); @@ -197,19 +198,6 @@ public static function getConfig(): Config { return static::$config; } - /** - * Get the workflow collection. - * - * @return Workflow\Collection - */ - public static function getWorkflowCollection(): Workflow\Collection { - if ( ! isset( static::$workflow_collection ) ) { - static::$workflow_collection = new Workflow\Collection(); - } - - return static::$workflow_collection; - } - /** * Sets whether the app is running from a phar. * diff --git a/src/Commands/Workflow.php b/src/Commands/Workflow.php index c3b6615..37f0b13 100644 --- a/src/Commands/Workflow.php +++ b/src/Commands/Workflow.php @@ -5,7 +5,7 @@ use StellarWP\Pup\App; use StellarWP\Pup\Exceptions\BaseException; use StellarWP\Pup\Command\Command; -use Symfony\Component\Console\Input\ArrayInput; +use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -39,8 +39,7 @@ protected function execute( InputInterface $input, OutputInterface $output ) { throw new BaseException( 'Could not run pup.' ); } - $collection = App::getWorkflowCollection(); - $failures = []; + $collection = $config->getWorkflows(); if ( $collection->count() === 0 ) { $io->writeln( '📣 The .puprc does not have any workflows configured.' ); diff --git a/src/Config.php b/src/Config.php index aab89cf..46f74ab 100644 --- a/src/Config.php +++ b/src/Config.php @@ -72,10 +72,6 @@ public function __construct() { * @return void */ public function buildWorkflows() { - if ( empty( $this->config->workflows ) ) { - return; - } - $collection = new Workflow\Collection(); if ( empty( $this->config->workflows->build ) && ! empty( $this->config->build ) ) { @@ -86,8 +82,10 @@ public function buildWorkflows() { $collection->add( new Workflow\Workflow( 'build_dev', $this->config->build_dev ) ); } - foreach ( $this->config->workflows as $slug => $commands ) { - $collection->add( new Workflow\Workflow( $slug, $commands ) ); + if ( ! empty( $this->config->workflows ) ) { + foreach ( $this->config->workflows as $slug => $commands ) { + $collection->add( new Workflow\Workflow( $slug, $commands ) ); + } } $this->config->workflows = $collection; @@ -509,9 +507,9 @@ public function getVersionFiles() : array { /** * Get the workflows from the config. * - * @return array + * @return Workflow\Collection */ - public function getWorkflows(): array { + public function getWorkflows(): Workflow\Collection { return $this->config->workflows; } diff --git a/src/Workflow/Collection.php b/src/Workflow/Collection.php index f73afd9..e941b25 100644 --- a/src/Workflow/Collection.php +++ b/src/Workflow/Collection.php @@ -35,6 +35,14 @@ public function current() { return current( $this->workflows ); } + /** + * @inheritDoc + */ + #[\ReturnTypeWillChange] + public function get( $offset ) { + return $this->offsetGet( $offset ); + } + /** * @inheritDoc */ From 1032be0f160140383555e812bd2d39b2d179b987 Mon Sep 17 00:00:00 2001 From: test Date: Thu, 25 Apr 2024 11:43:06 -0400 Subject: [PATCH 03/12] Implement pup workflows and add docs --- .puprc-defaults | 1 + README.md | 6 + docs/commands.md | 26 ++++ docs/configuration.md | 21 +-- docs/workflows.md | 46 +++++++ src/Commands/Workflow.php | 2 +- src/Workflow/Collection.php | 3 + tests/cli/Commands/HelpCest.php | 2 + tests/cli/Commands/WorkflowCest.php | 130 ++++++++++++++++++ ..._it_should_default_to_help__0.snapshot.txt | 2 + ...lpCest__it_should_run_help__0.snapshot.txt | 2 + ...it_should_show_topic_docs__10.snapshot.txt | 48 +++++++ ..._it_should_show_topic_docs__9.snapshot.txt | 48 +++++++ ...st__it_should_provide_info__0.snapshot.txt | 1 + ...ovide_info_with_distignore__0.snapshot.txt | 1 + ...vide_info_with_distinclude__0.snapshot.txt | 1 + ...de_info_with_gitattributes__0.snapshot.txt | 1 + ...ld_provide_info_with_puprc__0.snapshot.txt | 1 + ..._should_show_invalid_puprc__0.snapshot.txt | 1 + ...fail_non_existent_workflow__0.snapshot.txt | 1 + ...ould_run_an_empty_workflow__0.snapshot.txt | 1 + ...ould_run_build_as_workflow__0.snapshot.txt | 21 +++ ..._run_build_dev_as_workflow__0.snapshot.txt | 8 ++ ...flowCest__it_should_run_do__0.snapshot.txt | 8 ++ ...st__it_should_run_workflow__0.snapshot.txt | 8 ++ 25 files changed, 379 insertions(+), 11 deletions(-) create mode 100644 docs/workflows.md create mode 100644 tests/cli/Commands/WorkflowCest.php create mode 100644 tests/cli/Commands/__snapshots__/HelpCest__it_should_show_topic_docs__10.snapshot.txt create mode 100644 tests/cli/Commands/__snapshots__/HelpCest__it_should_show_topic_docs__9.snapshot.txt create mode 100644 tests/cli/Commands/__snapshots__/WorkflowCest__it_should_fail_non_existent_workflow__0.snapshot.txt create mode 100644 tests/cli/Commands/__snapshots__/WorkflowCest__it_should_run_an_empty_workflow__0.snapshot.txt create mode 100644 tests/cli/Commands/__snapshots__/WorkflowCest__it_should_run_build_as_workflow__0.snapshot.txt create mode 100644 tests/cli/Commands/__snapshots__/WorkflowCest__it_should_run_build_dev_as_workflow__0.snapshot.txt create mode 100644 tests/cli/Commands/__snapshots__/WorkflowCest__it_should_run_do__0.snapshot.txt create mode 100644 tests/cli/Commands/__snapshots__/WorkflowCest__it_should_run_workflow__0.snapshot.txt 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 1d43fc5..aebabd8 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -274,6 +274,32 @@ composer -- pup package ## `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 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/src/Commands/Workflow.php b/src/Commands/Workflow.php index 37f0b13..f7f35a6 100644 --- a/src/Commands/Workflow.php +++ b/src/Commands/Workflow.php @@ -57,7 +57,7 @@ protected function execute( InputInterface $input, OutputInterface $output ) { $workflow = $collection->get( $workflow_slug ); if ( ! $workflow ) { - $io->writeln( "The workflow '{$workflow_slug}' does not exist." ); + $io->writeln( "The workflow '{$workflow_slug}' does not exist." ); return 1; } diff --git a/src/Workflow/Collection.php b/src/Workflow/Collection.php index e941b25..6dfd5d9 100644 --- a/src/Workflow/Collection.php +++ b/src/Workflow/Collection.php @@ -71,6 +71,9 @@ public function offsetExists( $offset ): bool { */ #[\ReturnTypeWillChange] public function offsetGet( $offset ) { + if ( ! isset( $this->workflows[ $offset ] ) ) { + return null; + } return $this->workflows[ $offset ]; } 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 From 02ffd40568d3f1a9981844c9ad8a6c9997b310de Mon Sep 17 00:00:00 2001 From: test Date: Thu, 25 Apr 2024 11:46:57 -0400 Subject: [PATCH 04/12] Resolve errors flagged by PHPStan --- src/VersionFile.php | 3 ++- src/Workflow/Collection.php | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) 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 index 6dfd5d9..07db949 100644 --- a/src/Workflow/Collection.php +++ b/src/Workflow/Collection.php @@ -36,7 +36,11 @@ public function current() { } /** - * @inheritDoc + * Grabs a workflow from the collection. + * + * @param string $offset Workflow slug. + * + * @return Workflow|null */ #[\ReturnTypeWillChange] public function get( $offset ) { From 430116da65a3c2ced29c70a543ca98977a3f44ca Mon Sep 17 00:00:00 2001 From: test Date: Thu, 25 Apr 2024 11:48:02 -0400 Subject: [PATCH 05/12] Change the version number to 1.3.0 --- pup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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() ) { From 43b61a02213d1126809f333b846d42b000132318 Mon Sep 17 00:00:00 2001 From: Gustavo Bordoni Date: Sat, 27 Apr 2024 14:31:56 -0400 Subject: [PATCH 06/12] Ensure all of our PUP requests to i18n use a diff User-Agent, as the Guzzle one is blocked --- src/Commands/I18n.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Commands/I18n.php b/src/Commands/I18n.php index 8d5aaeb..b2b8562 100644 --- a/src/Commands/I18n.php +++ b/src/Commands/I18n.php @@ -62,6 +62,20 @@ protected function execute( InputInterface $input, OutputInterface $output ) { return 0; } + /** + * Returns default client options. + * + * @return array> + */ + protected function get_default_client_options() { + $version = \StellarWP\Pup\PUP_VERSION; + return [ + 'headers' => [ + 'User-Agent' => "StellarWP PUP/{$version}", + ], + ]; + } + /** * Downloads language files. * @@ -85,7 +99,7 @@ protected function download_language_files( I18nConfig $i18n_config ): int { $io->writeln( "Fetching language files for {$options->text_domain} from {$options->url}" ); // @phpstan-ignore-line: Those are strings. - $client = new Client(); + $client = new Client( $this->get_default_client_options() ); $project_url = $options->url . '/api/projects/' . $options->slug; $project_res = $client->request( 'GET', $project_url ); @@ -150,7 +164,7 @@ protected function download_and_save_translation( $options, $translation, $forma $tried++; - $client = new Client(); + $client = new Client( $this->get_default_client_options() ); $request = new Request( 'GET', $translation_url ); $promise = $client->sendAsync( $request )->then( function ( $response ) use ( $translation_url, $options, $translation, $format, $project_url, $tried, $io ) { From 081675f6e10c618511b77cb06f64ade055f02b18 Mon Sep 17 00:00:00 2001 From: Gustavo Bordoni Date: Sat, 27 Apr 2024 23:45:10 -0400 Subject: [PATCH 07/12] PHPStan fix. --- src/Commands/I18n.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Commands/I18n.php b/src/Commands/I18n.php index b2b8562..d3e29e8 100644 --- a/src/Commands/I18n.php +++ b/src/Commands/I18n.php @@ -5,6 +5,7 @@ use GuzzleHttp\Client; use GuzzleHttp\Psr7\Request; use StellarWP\Pup\App; +use StellarWP\Pup; use StellarWP\Pup\Command\Command; use StellarWP\Pup\I18nConfig; use Symfony\Component\Console\Input\InputInterface; @@ -68,7 +69,7 @@ protected function execute( InputInterface $input, OutputInterface $output ) { * @return array> */ protected function get_default_client_options() { - $version = \StellarWP\Pup\PUP_VERSION; + $version = Pup\PUP_VERSION; return [ 'headers' => [ 'User-Agent' => "StellarWP PUP/{$version}", From ba732aee909ef95a5b945ca5bc1671dfae2093fe Mon Sep 17 00:00:00 2001 From: Gustavo Bordoni Date: Sat, 27 Apr 2024 23:49:02 -0400 Subject: [PATCH 08/12] Avoid problems with PHPStan by ensuring the Ignore works on all usages of PUP_VERSION --- phpstan.neon.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 980c1d7..e595008 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -23,4 +23,4 @@ parameters: ignoreErrors: - '#^Constant __PUP_DIR__ not found\.$#' - - '#^Constant PUP_VERSION not found\.$#' + - '#^Constant (.*)PUP_VERSION not found\.$#' From ea878f94aa3ff058fb957ae7c57bb84a75bdc9e7 Mon Sep 17 00:00:00 2001 From: Matthew Batchelder Date: Sun, 28 Apr 2024 08:21:23 -0400 Subject: [PATCH 09/12] Update pup version number --- pup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pup b/pup index 61d72bc..e1fe795 100755 --- a/pup +++ b/pup @@ -3,7 +3,7 @@ namespace StellarWP\Pup; -const PUP_VERSION = '1.3.0'; +const PUP_VERSION = '1.3.1'; define( '__PUP_DIR__', __DIR__ ); if ( ! \Phar::running() ) { From c37b9bbe136b4c22b55688f3d3dd40fe88ac4c4e Mon Sep 17 00:00:00 2001 From: borkweb Date: Thu, 2 May 2024 10:21:23 -0400 Subject: [PATCH 10/12] Add the clone command and adjust output --- src/App.php | 1 + src/Command/Command.php | 13 ++- src/Commands/Build.php | 2 +- src/Commands/Checks/AbstractCheck.php | 2 +- src/Commands/Checks/Tbd.php | 6 +- src/Commands/Checks/VersionConflict.php | 4 +- src/Commands/Clean.php | 14 ++-- src/Commands/CloneCommand.php | 60 ++++++++++++++ src/Commands/Package.php | 16 ++-- src/Commands/Workflow.php | 2 +- src/Commands/Zip.php | 39 ++++++--- tests/cli/Commands/CloneCest.php | 79 +++++++++++++++++++ ...dCest__it_should_run_build__0.snapshot.txt | 2 +- ...d_steps_when_missing_puprc__0.snapshot.txt | 2 +- ...teps_when_not_set_in_puprc__0.snapshot.txt | 2 +- ...ould_clean_up_after_itself__0.snapshot.txt | 9 ++- ...cific_branch_of_a_git_repo__0.snapshot.txt | 2 + ...fault_branch_of_a_git_repo__0.snapshot.txt | 2 + ..._it_should_package_the_zip__0.snapshot.txt | 15 +++- ..._version_number_if_unknown__0.snapshot.txt | 15 +++- ...ing_file_colon_slash_slash__0.snapshot.txt | 27 +++++-- ...d_zip_with_repo_using_path__0.snapshot.txt | 27 +++++-- ...should_zip_without_cloning__0.snapshot.txt | 27 +++++-- ...ecks_when_checks_are_empty__0.snapshot.txt | 27 +++++-- 24 files changed, 315 insertions(+), 80 deletions(-) create mode 100644 src/Commands/CloneCommand.php create mode 100644 tests/cli/Commands/CloneCest.php create mode 100644 tests/cli/Commands/__snapshots__/CloneCest__it_should_clone_a_specific_branch_of_a_git_repo__0.snapshot.txt create mode 100644 tests/cli/Commands/__snapshots__/CloneCest__it_should_clone_the_default_branch_of_a_git_repo__0.snapshot.txt diff --git a/src/App.php b/src/App.php index 15202a9..24f0ab2 100644 --- a/src/App.php +++ b/src/App.php @@ -56,6 +56,7 @@ public function __construct( string $version ) { $this->add( new Commands\Build() ); $this->add( new Commands\Check() ); $this->add( new Commands\Clean() ); + $this->add( new Commands\CloneCommand() ); $this->add( new Commands\GetVersion() ); $this->add( new Commands\Help() ); $this->add( new Commands\I18n() ); diff --git a/src/Command/Command.php b/src/Command/Command.php index 2c7bbc4..eba7424 100644 --- a/src/Command/Command.php +++ b/src/Command/Command.php @@ -5,7 +5,9 @@ use StellarWP\Pup\App; use Symfony\Component\Console\Command\Command as SymfonyCommand; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Formatter\OutputFormatterStyle; abstract class Command extends SymfonyCommand { /** @@ -18,6 +20,13 @@ abstract class Command extends SymfonyCommand { */ protected $should_validate_puprc = true; + public function __construct( string $name = null ) { + parent::__construct( $name ); + + // Declare options that we want to be able to use globally in workflows without declaring it in each command. + $this->addOption( 'branch', null, InputOption::VALUE_REQUIRED, 'The branch to use.' ); + } + /** * Runs the wrapping execute command. * @@ -47,6 +56,8 @@ protected function execute( InputInterface $input, OutputInterface $output ) { * @return void */ protected function initialize( InputInterface $input, OutputInterface $output ) { + $output->getFormatter()->setStyle( 'info', new OutputFormatterStyle( 'blue' ) ); + $output->getFormatter()->setStyle( 'success', new OutputFormatterStyle( 'green' ) ); $this->io = new Io( $input, $output ); } @@ -65,4 +76,4 @@ protected function getIO(): Io { public function setShouldNotValidatePuprc() { $this->should_validate_puprc = false; } -} \ No newline at end of file +} diff --git a/src/Commands/Build.php b/src/Commands/Build.php index e25d197..8a33565 100644 --- a/src/Commands/Build.php +++ b/src/Commands/Build.php @@ -62,7 +62,7 @@ protected function execute( InputInterface $input, OutputInterface $output ) { chdir( $config->getWorkingDir() ); } - $io->writeln( 'Build complete.' ); + $io->writeln( '✓ Build complete.' ); return 0; } } diff --git a/src/Commands/Checks/AbstractCheck.php b/src/Commands/Checks/AbstractCheck.php index fda888c..73390c6 100644 --- a/src/Commands/Checks/AbstractCheck.php +++ b/src/Commands/Checks/AbstractCheck.php @@ -181,4 +181,4 @@ public function shouldBailOnFailureDev(): bool { protected function writeln( string $message ) { $this->getIO()->writeln( $message ); } -} \ No newline at end of file +} diff --git a/src/Commands/Checks/Tbd.php b/src/Commands/Checks/Tbd.php index 2c388be..613de91 100644 --- a/src/Commands/Checks/Tbd.php +++ b/src/Commands/Checks/Tbd.php @@ -81,7 +81,7 @@ protected function checkExecute( InputInterface $input, Io $output ): int { $output->writeln( '' ); } } else { - $output->writeln( 'No TBDs found!' ); + $output->writeln( 'No TBDs found!' ); $output->writeln( '' ); } $output->writeln( '' ); @@ -89,7 +89,7 @@ protected function checkExecute( InputInterface $input, Io $output ): int { if ( $found_tbds ) { $output->writeln( "TBDs have been found!" ); } else { - $output->writeln( 'Success! No TBDs found.' ); + $output->writeln( 'Success! No TBDs found.' ); } return $found_tbds ? 1 : 0; @@ -168,4 +168,4 @@ protected function scanDir( string $root, string $current_dir, string $scan_dir, return $matched_lines; } -} \ No newline at end of file +} diff --git a/src/Commands/Checks/VersionConflict.php b/src/Commands/Checks/VersionConflict.php index 33b0373..3acb57f 100644 --- a/src/Commands/Checks/VersionConflict.php +++ b/src/Commands/Checks/VersionConflict.php @@ -112,7 +112,7 @@ protected function checkExecute( InputInterface $input, Io $output ): int { return 1; } - $output->writeln( 'No version conflicts found.' ); + $output->writeln( 'No version conflicts found.' ); return 0; } -} \ No newline at end of file +} diff --git a/src/Commands/Clean.php b/src/Commands/Clean.php index 29c5ca7..aefcbdc 100644 --- a/src/Commands/Clean.php +++ b/src/Commands/Clean.php @@ -32,24 +32,22 @@ protected function execute( InputInterface $input, OutputInterface $output ) { $clean_steps = $config->getCleanCommands(); $io = $this->getIO(); - $output->writeln( 'Cleaning up...' ); + $this->io->section( 'Cleaning up...' ); - $output->write( "* Removing zip dir..." ); if ( file_exists( $zip_dir ) && DirectoryUtils::rmdir( $zip_dir ) !== 0 ) { throw new \Exception( "Could not remove {$zip_dir}." ); } - $output->write( 'Complete.' . PHP_EOL ); + $output->writeln( "✓ Removing zip dir...Complete." ); - $output->write( "* Removing build dir..." ); if ( file_exists( $build_dir ) && DirectoryUtils::rmdir( $build_dir ) !== 0 ) { throw new \Exception( "Could not remove {$build_dir}." ); } - $output->write( 'Complete.' . PHP_EOL ); + $output->writeln( "✓ Removing build dir...Complete." ); $pup_distfiles = $config->getWorkingDir() . '.pup-distfiles'; if ( file_exists( $pup_distfiles ) ) { if ( unlink( $pup_distfiles ) ) { - $output->writeln( 'Removing .pup-distfiles...Complete.' ); + $output->writeln( '✓ Removing .pup-distfiles...Complete.' ); } else { throw new \Exception( "Could not remove {$build_dir}." ); } @@ -58,7 +56,7 @@ protected function execute( InputInterface $input, OutputInterface $output ) { $pup_distignore = $config->getWorkingDir() . '.pup-distignore'; if ( file_exists( $pup_distignore ) ) { if ( unlink( $pup_distignore ) ) { - $output->writeln( 'Removing .pup-distignore...Complete.' ); + $output->writeln( '✓ Removing .pup-distignore...Complete.' ); } else { throw new \Exception( "Could not remove {$build_dir}." ); } @@ -67,7 +65,7 @@ protected function execute( InputInterface $input, OutputInterface $output ) { $pup_distinclude = $config->getWorkingDir() . '.pup-distinclude'; if ( file_exists( $pup_distinclude ) ) { if ( unlink( $pup_distinclude ) ) { - $output->writeln( 'Removing .pup-distinclude...Complete.' ); + $output->writeln( '✓ Removing .pup-distinclude...Complete.' ); } else { throw new \Exception( "Could not remove {$build_dir}." ); } diff --git a/src/Commands/CloneCommand.php b/src/Commands/CloneCommand.php new file mode 100644 index 0000000..ed0d063 --- /dev/null +++ b/src/Commands/CloneCommand.php @@ -0,0 +1,60 @@ +setName( 'clone' ) + ->setDescription( 'Clone a git repository.' ) + ->setHelp( 'Clone a git repository.' ); + } + + /** + * @inheritDoc + */ + protected function execute( InputInterface $input, OutputInterface $output ) { + parent::execute( $input, $output ); + $config = App::getConfig(); + $build_dir = $config->getBuildDir(); + $branch = $input->getOption( 'branch' ); + + $branch_arg = ''; + if ( $branch ) { + $branch_arg = "-b {$branch}"; + } + + $repo = App::getConfig()->getRepo(); + + if ( file_exists( $build_dir ) ) { + $build_dir_basename = basename( $build_dir ); + $output->writeln( "The {$build_dir_basename} already exists." ); + $output->write( "Removing build dir..." ); + if ( file_exists( $build_dir ) && DirectoryUtils::rmdir( $build_dir ) !== 0 ) { + throw new \Exception( "Could not remove {$build_dir}." ); + } + $output->write( 'Complete.' . PHP_EOL ); + } + + $output->writeln( 'Cloning the ' . $repo . ' repo into ' . App::getConfig()->getBuildDir( false ) . '...' ); + system( 'git clone --quiet --recurse-submodules -j8 --shallow-submodules --depth 1 ' . $branch_arg . ' ' . $repo . ' ' . App::getConfig()->getBuildDir( false ) ); + $output->writeln( '✓ Clone complete.' ); + + return 0; + } +} diff --git a/src/Commands/Package.php b/src/Commands/Package.php index 15daf42..2618b41 100644 --- a/src/Commands/Package.php +++ b/src/Commands/Package.php @@ -66,7 +66,7 @@ protected function execute( InputInterface $input, OutputInterface $output ) { $config = App::getConfig(); $zip_name = $config->getZipName(); - $output->writeln( 'Packaging zip...' ); + $this->io->section( 'Packaging zip...' ); $buffer = new BufferedOutput(); $application = $this->getApplication(); @@ -77,13 +77,13 @@ protected function execute( InputInterface $input, OutputInterface $output ) { $zip_filename = "{$full_zip_name}.zip"; - $output->write( '* Updating version files...' ); + $output->writeln( '- Updating version files...' ); if ( $version !== 'unknown' ) { $this->updateVersionsInFiles( $version ); } - $output->write( 'Complete.' . PHP_EOL ); + $output->writeln( '✓ Updating version files...Complete.' ); - $output->write( '* Synchronizing files to zip directory...' ); + $output->writeln( '- Synchronizing files to zip directory...' ); $pup_zip_dir = $config->getZipDir(); DirectoryUtils::rmdir( $pup_zip_dir ); @@ -91,25 +91,25 @@ protected function execute( InputInterface $input, OutputInterface $output ) { mkdir( $pup_zip_dir ); $results = $this->syncFiles( $root, $pup_zip_dir ); - $output->write( 'Complete.' . PHP_EOL ); + $output->writeln( '✓ Synchronizing files to zip directory...Complete.' ); if ( $results !== 0 ) { $this->undoChanges(); return $results; } - $output->write( '* Zipping...' ); + $output->writeln( '- Zipping...' ); $results = $this->createZip( $pup_zip_dir, $zip_filename, $zip_name ); if ( $results !== 0 ) { $this->undoChanges(); return $results; } - $output->write( 'Complete.' . PHP_EOL ); + $output->writeln( '✓ Zipping...Complete.' ); $this->undoChanges(); - $this->output->writeln( "Zip {$zip_filename} created!" ); + $this->output->writeln( PHP_EOL . "✓ Zip {$zip_filename} created!" . PHP_EOL ); return 0; } diff --git a/src/Commands/Workflow.php b/src/Commands/Workflow.php index f7f35a6..1bb66ac 100644 --- a/src/Commands/Workflow.php +++ b/src/Commands/Workflow.php @@ -89,7 +89,7 @@ protected function execute( InputInterface $input, OutputInterface $output ) { chdir( $config->getWorkingDir() ); } - $io->writeln( 'Workflow complete.' ); + $io->writeln( 'Workflow complete.' ); } return 0; diff --git a/src/Commands/Zip.php b/src/Commands/Zip.php index 4bfdb10..491131e 100644 --- a/src/Commands/Zip.php +++ b/src/Commands/Zip.php @@ -51,16 +51,11 @@ protected function execute( InputInterface $input, OutputInterface $output ) { $branch = $this->input->getArgument( 'branch' ); if ( ! $this->input->getOption( 'no-clone' ) ) { - $branch_arg = ''; - if ( $branch ) { - $branch_arg = "-b {$branch}"; + $results = $this->runClone(); + if ( $results !== 0 ) { + $output->writeln( 'The clone step of `pup zip` failed.' ); + return $results; } - - $repo = App::getConfig()->getRepo(); - - $output->writeln( 'Cloning the ' . $repo . ' repo into ' . App::getConfig()->getBuildDir( false ) . '...' ); - system( 'git clone --quiet --recurse-submodules -j8 --shallow-submodules --depth 1 ' . $branch_arg . ' ' . $repo . ' ' . App::getConfig()->getBuildDir( false ) ); - $output->writeln( 'Clone complete.' ); } elseif ( $branch ) { system( 'git checkout --quiet ' . $branch ); } @@ -164,6 +159,32 @@ protected function runCheck(): int { return $command->run( $command_input, $this->output ); } + /** + * Run the clone command. + * + * @throws \Symfony\Component\Console\Exception\ExceptionInterface + * + * @return int + */ + protected function runClone(): int { + $application = $this->getApplication(); + if ( ! $application ) { + return 1; + } + + $command = $application->find( 'clone' ); + $arguments = []; + + $branch = $this->input->getArgument( 'branch' ); + + if ( $branch ) { + $arguments['--branch'] = $this->input->getArgument( 'branch' ); + } + + $command_input = new ArrayInput( $arguments ); + return $command->run( $command_input, $this->output ); + } + /** * Run the get-version command. * diff --git a/tests/cli/Commands/CloneCest.php b/tests/cli/Commands/CloneCest.php new file mode 100644 index 0000000..7808663 --- /dev/null +++ b/tests/cli/Commands/CloneCest.php @@ -0,0 +1,79 @@ +tests_root . '/_data/fake-project-git-repo'; + system( 'rm -rf ' . $project_path ); + system( 'cp -r ' . $this->tests_root . '/_data/fake-project ' . $project_path ); + + chdir( $project_path ); + + system( 'cd ' . $project_path . ' && git init --quiet' ); + system( 'cd ' . $project_path . ' && git add .' ); + system( 'cd ' . $project_path . ' && git commit -m "Initial commit" --quiet' ); + + $puprc = $this->get_puprc(); + $puprc['repo'] = $project_path; + $this->write_puprc( $puprc, 'fake-project-git-repo' ); + + $I->runShellCommand( "php {$this->pup} clone" ); + $I->seeResultCodeIs( 0 ); + + $I->assertTrue( file_exists( '.pup-build/bootstrap.php' ) ); + + $output = $I->grabShellOutput(); + $this->assertMatchesStringSnapshot( $output ); + + $I->runShellCommand( "php {$this->pup} clean" ); + + $this->reset_data_and_location(); + + system( 'rm -rf ' . $project_path ); + } + + /** + * @test + */ + public function it_should_clone_a_specific_branch_of_a_git_repo( CliTester $I ) { + $project_path = $this->tests_root . '/_data/fake-project-git-repo'; + system( 'rm -rf ' . $project_path ); + system( 'cp -r ' . $this->tests_root . '/_data/fake-project ' . $project_path ); + + chdir( $project_path ); + + system( 'cd ' . $project_path . ' && git init --quiet' ); + system( 'cd ' . $project_path . ' && git add .' ); + system( 'cd ' . $project_path . ' && git commit -m "Initial commit" --quiet' ); + system( 'cd ' . $project_path . ' && git checkout -b other-branch --quiet' ); + system( 'cd ' . $project_path . ' && touch new-file.txt' ); + system( 'cd ' . $project_path . ' && git add new-file.txt' ); + system( 'cd ' . $project_path . ' && git commit new-file.txt -m "Added new file" --quiet' ); + + $puprc = $this->get_puprc(); + $puprc['repo'] = $project_path; + $this->write_puprc( $puprc, 'fake-project-git-repo' ); + + $I->runShellCommand( "php {$this->pup} clone --branch other-branch" ); + $I->seeResultCodeIs( 0 ); + + $I->assertTrue( file_exists( '.pup-build/new-file.txt' ) ); + + $output = $I->grabShellOutput(); + $this->assertMatchesStringSnapshot( $output ); + + $I->runShellCommand( "php {$this->pup} clean" ); + + $this->reset_data_and_location(); + + system( 'rm -rf ' . $project_path ); + } +} diff --git a/tests/cli/Commands/__snapshots__/BuildCest__it_should_run_build__0.snapshot.txt b/tests/cli/Commands/__snapshots__/BuildCest__it_should_run_build__0.snapshot.txt index 43cc1a2..a02c5e8 100644 --- a/tests/cli/Commands/__snapshots__/BuildCest__it_should_run_build__0.snapshot.txt +++ b/tests/cli/Commands/__snapshots__/BuildCest__it_should_run_build__0.snapshot.txt @@ -16,4 +16,4 @@ src fake project, yo -Build complete. \ No newline at end of file +✓ Build complete. \ No newline at end of file diff --git a/tests/cli/Commands/__snapshots__/BuildCest__it_should_run_no_build_steps_when_missing_puprc__0.snapshot.txt b/tests/cli/Commands/__snapshots__/BuildCest__it_should_run_no_build_steps_when_missing_puprc__0.snapshot.txt index b60408e..46bc566 100644 --- a/tests/cli/Commands/__snapshots__/BuildCest__it_should_run_no_build_steps_when_missing_puprc__0.snapshot.txt +++ b/tests/cli/Commands/__snapshots__/BuildCest__it_should_run_no_build_steps_when_missing_puprc__0.snapshot.txt @@ -1,2 +1,2 @@ Running build steps... -Build complete. \ No newline at end of file +✓ Build complete. \ No newline at end of file diff --git a/tests/cli/Commands/__snapshots__/BuildCest__it_should_run_no_build_steps_when_not_set_in_puprc__0.snapshot.txt b/tests/cli/Commands/__snapshots__/BuildCest__it_should_run_no_build_steps_when_not_set_in_puprc__0.snapshot.txt index b60408e..46bc566 100644 --- a/tests/cli/Commands/__snapshots__/BuildCest__it_should_run_no_build_steps_when_not_set_in_puprc__0.snapshot.txt +++ b/tests/cli/Commands/__snapshots__/BuildCest__it_should_run_no_build_steps_when_not_set_in_puprc__0.snapshot.txt @@ -1,2 +1,2 @@ Running build steps... -Build complete. \ No newline at end of file +✓ Build complete. \ No newline at end of file diff --git a/tests/cli/Commands/__snapshots__/CleanCest__it_should_clean_up_after_itself__0.snapshot.txt b/tests/cli/Commands/__snapshots__/CleanCest__it_should_clean_up_after_itself__0.snapshot.txt index 4ed43b2..7a9d595 100644 --- a/tests/cli/Commands/__snapshots__/CleanCest__it_should_clean_up_after_itself__0.snapshot.txt +++ b/tests/cli/Commands/__snapshots__/CleanCest__it_should_clean_up_after_itself__0.snapshot.txt @@ -1,4 +1,7 @@ + Cleaning up... -* Removing zip dir...Complete. -* Removing build dir...Complete. -Removing .pup-distignore...Complete. \ No newline at end of file +-------------- + +✓ Removing zip dir...Complete. +✓ Removing build dir...Complete. +✓ Removing .pup-distignore...Complete. \ No newline at end of file diff --git a/tests/cli/Commands/__snapshots__/CloneCest__it_should_clone_a_specific_branch_of_a_git_repo__0.snapshot.txt b/tests/cli/Commands/__snapshots__/CloneCest__it_should_clone_a_specific_branch_of_a_git_repo__0.snapshot.txt new file mode 100644 index 0000000..e1e56e6 --- /dev/null +++ b/tests/cli/Commands/__snapshots__/CloneCest__it_should_clone_a_specific_branch_of_a_git_repo__0.snapshot.txt @@ -0,0 +1,2 @@ +Cloning the /home/matt/git/pup/tests/_data/fake-project-git-repo repo into .pup-build... +✓ Clone complete. \ No newline at end of file diff --git a/tests/cli/Commands/__snapshots__/CloneCest__it_should_clone_the_default_branch_of_a_git_repo__0.snapshot.txt b/tests/cli/Commands/__snapshots__/CloneCest__it_should_clone_the_default_branch_of_a_git_repo__0.snapshot.txt new file mode 100644 index 0000000..e1e56e6 --- /dev/null +++ b/tests/cli/Commands/__snapshots__/CloneCest__it_should_clone_the_default_branch_of_a_git_repo__0.snapshot.txt @@ -0,0 +1,2 @@ +Cloning the /home/matt/git/pup/tests/_data/fake-project-git-repo repo into .pup-build... +✓ Clone complete. \ No newline at end of file diff --git a/tests/cli/Commands/__snapshots__/PackageCest__it_should_package_the_zip__0.snapshot.txt b/tests/cli/Commands/__snapshots__/PackageCest__it_should_package_the_zip__0.snapshot.txt index 3e8bce8..d7b3526 100644 --- a/tests/cli/Commands/__snapshots__/PackageCest__it_should_package_the_zip__0.snapshot.txt +++ b/tests/cli/Commands/__snapshots__/PackageCest__it_should_package_the_zip__0.snapshot.txt @@ -1,5 +1,12 @@ + Packaging zip... -* Updating version files...Complete. -* Synchronizing files to zip directory...Complete. -* Zipping...Complete. -Zip fake-project.1.0.0.zip created! \ No newline at end of file +---------------- + +- Updating version files... +✓ Updating version files...Complete. +- Synchronizing files to zip directory... +✓ Synchronizing files to zip directory...Complete. +- Zipping... +✓ Zipping...Complete. + +✓ Zip fake-project.1.0.0.zip created! diff --git a/tests/cli/Commands/__snapshots__/PackageCest__it_should_package_the_zip_without_version_number_if_unknown__0.snapshot.txt b/tests/cli/Commands/__snapshots__/PackageCest__it_should_package_the_zip_without_version_number_if_unknown__0.snapshot.txt index f293b43..956010e 100644 --- a/tests/cli/Commands/__snapshots__/PackageCest__it_should_package_the_zip_without_version_number_if_unknown__0.snapshot.txt +++ b/tests/cli/Commands/__snapshots__/PackageCest__it_should_package_the_zip_without_version_number_if_unknown__0.snapshot.txt @@ -1,5 +1,12 @@ + Packaging zip... -* Updating version files...Complete. -* Synchronizing files to zip directory...Complete. -* Zipping...Complete. -Zip fake-project.zip created! \ No newline at end of file +---------------- + +- Updating version files... +✓ Updating version files...Complete. +- Synchronizing files to zip directory... +✓ Synchronizing files to zip directory...Complete. +- Zipping... +✓ Zipping...Complete. + +✓ Zip fake-project.zip created! diff --git a/tests/cli/Commands/__snapshots__/ZipCest__it_should_zip_with_repo_using_file_colon_slash_slash__0.snapshot.txt b/tests/cli/Commands/__snapshots__/ZipCest__it_should_zip_with_repo_using_file_colon_slash_slash__0.snapshot.txt index 4fe1d1e..e8c932e 100644 --- a/tests/cli/Commands/__snapshots__/ZipCest__it_should_zip_with_repo_using_file_colon_slash_slash__0.snapshot.txt +++ b/tests/cli/Commands/__snapshots__/ZipCest__it_should_zip_with_repo_using_file_colon_slash_slash__0.snapshot.txt @@ -1,5 +1,5 @@ Cloning the file:///home/matt/git/pup/tests/_data/fake-project-git-repo repo into .pup-build... -Clone complete. +✓ Clone complete. Running build steps... > ls -a @@ -13,7 +13,7 @@ other-file.php package.json src -Build complete. +✓ Build complete. [tbd] Checking for TBDs... [tbd] -------------------- @@ -27,11 +27,22 @@ Build complete. [version-conflict] --------------------------------- [version-conflict] No version conflicts found. + Packaging zip... -* Updating version files...Complete. -* Synchronizing files to zip directory...Complete. -* Zipping...Complete. -Zip fake-project.1.0.0.1.zip created! +---------------- + +- Updating version files... +✓ Updating version files...Complete. +- Synchronizing files to zip directory... +✓ Synchronizing files to zip directory...Complete. +- Zipping... +✓ Zipping...Complete. + +✓ Zip fake-project.1.0.0.1.zip created! + + Cleaning up... -* Removing zip dir...Complete. -* Removing build dir...Complete. \ No newline at end of file +-------------- + +✓ Removing zip dir...Complete. +✓ Removing build dir...Complete. \ No newline at end of file diff --git a/tests/cli/Commands/__snapshots__/ZipCest__it_should_zip_with_repo_using_path__0.snapshot.txt b/tests/cli/Commands/__snapshots__/ZipCest__it_should_zip_with_repo_using_path__0.snapshot.txt index c71c260..213de35 100644 --- a/tests/cli/Commands/__snapshots__/ZipCest__it_should_zip_with_repo_using_path__0.snapshot.txt +++ b/tests/cli/Commands/__snapshots__/ZipCest__it_should_zip_with_repo_using_path__0.snapshot.txt @@ -1,5 +1,5 @@ Cloning the /home/matt/git/pup/tests/_data/fake-project-git-repo repo into .pup-build... -Clone complete. +✓ Clone complete. Running build steps... > ls -a @@ -13,7 +13,7 @@ other-file.php package.json src -Build complete. +✓ Build complete. [tbd] Checking for TBDs... [tbd] -------------------- @@ -27,11 +27,22 @@ Build complete. [version-conflict] --------------------------------- [version-conflict] No version conflicts found. + Packaging zip... -* Updating version files...Complete. -* Synchronizing files to zip directory...Complete. -* Zipping...Complete. -Zip fake-project.1.0.0.1.zip created! +---------------- + +- Updating version files... +✓ Updating version files...Complete. +- Synchronizing files to zip directory... +✓ Synchronizing files to zip directory...Complete. +- Zipping... +✓ Zipping...Complete. + +✓ Zip fake-project.1.0.0.1.zip created! + + Cleaning up... -* Removing zip dir...Complete. -* Removing build dir...Complete. \ No newline at end of file +-------------- + +✓ Removing zip dir...Complete. +✓ Removing build dir...Complete. \ No newline at end of file diff --git a/tests/cli/Commands/__snapshots__/ZipCest__it_should_zip_without_cloning__0.snapshot.txt b/tests/cli/Commands/__snapshots__/ZipCest__it_should_zip_without_cloning__0.snapshot.txt index 4a13324..9b5f7bb 100644 --- a/tests/cli/Commands/__snapshots__/ZipCest__it_should_zip_without_cloning__0.snapshot.txt +++ b/tests/cli/Commands/__snapshots__/ZipCest__it_should_zip_without_cloning__0.snapshot.txt @@ -11,7 +11,7 @@ other-file.php package.json src -Build complete. +✓ Build complete. [tbd] Checking for TBDs... [tbd] -------------------- @@ -25,12 +25,23 @@ Build complete. [version-conflict] --------------------------------- [version-conflict] No version conflicts found. + Packaging zip... -* Updating version files...Complete. -* Synchronizing files to zip directory...Complete. -* Zipping...Complete. -Zip fake-project.1.0.0.1.zip created! +---------------- + +- Updating version files... +✓ Updating version files...Complete. +- Synchronizing files to zip directory... +✓ Synchronizing files to zip directory...Complete. +- Zipping... +✓ Zipping...Complete. + +✓ Zip fake-project.1.0.0.1.zip created! + + Cleaning up... -* Removing zip dir...Complete. -* Removing build dir...Complete. -Removing .pup-distignore...Complete. \ No newline at end of file +-------------- + +✓ Removing zip dir...Complete. +✓ Removing build dir...Complete. +✓ Removing .pup-distignore...Complete. \ No newline at end of file diff --git a/tests/cli/Commands/__snapshots__/ZipCest__it_should_zip_without_running_checks_when_checks_are_empty__0.snapshot.txt b/tests/cli/Commands/__snapshots__/ZipCest__it_should_zip_without_running_checks_when_checks_are_empty__0.snapshot.txt index 3d15ee7..139afa2 100644 --- a/tests/cli/Commands/__snapshots__/ZipCest__it_should_zip_without_running_checks_when_checks_are_empty__0.snapshot.txt +++ b/tests/cli/Commands/__snapshots__/ZipCest__it_should_zip_without_running_checks_when_checks_are_empty__0.snapshot.txt @@ -11,13 +11,24 @@ other-file.php package.json src -Build complete. +✓ Build complete. + Packaging zip... -* Updating version files...Complete. -* Synchronizing files to zip directory...Complete. -* Zipping...Complete. -Zip fake-project.1.0.0.1.zip created! +---------------- + +- Updating version files... +✓ Updating version files...Complete. +- Synchronizing files to zip directory... +✓ Synchronizing files to zip directory...Complete. +- Zipping... +✓ Zipping...Complete. + +✓ Zip fake-project.1.0.0.1.zip created! + + Cleaning up... -* Removing zip dir...Complete. -* Removing build dir...Complete. -Removing .pup-distignore...Complete. \ No newline at end of file +-------------- + +✓ Removing zip dir...Complete. +✓ Removing build dir...Complete. +✓ Removing .pup-distignore...Complete. \ No newline at end of file From 829a95c5cf2419550fd4b80b623a87c6e30090f2 Mon Sep 17 00:00:00 2001 From: borkweb Date: Thu, 2 May 2024 10:23:19 -0400 Subject: [PATCH 11/12] Remove superfluous check --- src/Commands/CloneCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Commands/CloneCommand.php b/src/Commands/CloneCommand.php index ed0d063..444adf5 100644 --- a/src/Commands/CloneCommand.php +++ b/src/Commands/CloneCommand.php @@ -45,7 +45,7 @@ protected function execute( InputInterface $input, OutputInterface $output ) { $build_dir_basename = basename( $build_dir ); $output->writeln( "The {$build_dir_basename} already exists." ); $output->write( "Removing build dir..." ); - if ( file_exists( $build_dir ) && DirectoryUtils::rmdir( $build_dir ) !== 0 ) { + if ( DirectoryUtils::rmdir( $build_dir ) !== 0 ) { throw new \Exception( "Could not remove {$build_dir}." ); } $output->write( 'Complete.' . PHP_EOL ); From 821af183f102364449228795778dc14145eb67b7 Mon Sep 17 00:00:00 2001 From: borkweb Date: Thu, 2 May 2024 10:24:05 -0400 Subject: [PATCH 12/12] Updating pup version --- pup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pup b/pup index e1fe795..596dcc4 100755 --- a/pup +++ b/pup @@ -3,7 +3,7 @@ namespace StellarWP\Pup; -const PUP_VERSION = '1.3.1'; +const PUP_VERSION = '1.3.2'; define( '__PUP_DIR__', __DIR__ ); if ( ! \Phar::running() ) {