Skip to content

Commit

Permalink
Merge branch 'main' into fix/jsonSerialize
Browse files Browse the repository at this point in the history
  • Loading branch information
Camwyn authored May 20, 2024
2 parents 2c25a52 + 821af18 commit c7c3bd1
Show file tree
Hide file tree
Showing 53 changed files with 1,071 additions and 93 deletions.
1 change: 1 addition & 0 deletions .puprc-defaults
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"build": [],
"build_dev": [],
"workflows": {},
"checks": {
"tbd": {
"fail_method": "error",
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
68 changes: 68 additions & 0 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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 <workflow>
# or
composer -- pup do <workflow>
```

### 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.

Expand Down Expand Up @@ -250,6 +270,54 @@ composer -- pup package <version>
| `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 <workflow>
# or
pup do <workflow>
# or
composer -- pup workflow <workflow>
# or
composer -- pup do <workflow>
```

### 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.

Expand Down
21 changes: 11 additions & 10 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<org>/<repo>`. 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

Expand Down Expand Up @@ -135,4 +136,4 @@ This is what you should add as a `paths.versions` entry:
]
}
}
```
```
46 changes: 46 additions & 0 deletions docs/workflows.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Workflows

Workflows are a way to declare a series of commands that you want to run in a specific order. This allows you to specify
workflows that differ from the `build` and `build_dev` commands.

* [Defining workflows](#defining-workflows)
* [Calling workflows](#calling-workflows)
* [Pseudo-workflows](#pseudo-workflows)

## Defining workflows

Workflows are defined in the `workflows` property of your `.puprc` file.

```json
{
"workflows": {
"my-workflow": [
"npm ci",
"npm run build",
"@composer run some-script"
],
"my-other-workflow": [
"@composer run some-other-script",
"@composer run make-pot"
]
}
}
```

## Calling workflows

You can call a workflow by running the `workflow` command (or its alias `do`) with the name of the workflow as an argument.

```bash
pup workflow my-workflow
# OR
pup do my-workflow
```

## Pseudo-workflows

The `build` and `build_dev` properties within your `.puprc` file are also callable via the `workflow` command.

```bash
pup workflow build
```
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ parameters:

ignoreErrors:
- '#^Constant __PUP_DIR__ not found\.$#'
- '#^Constant PUP_VERSION not found\.$#'
- '#^Constant (.*)PUP_VERSION not found\.$#'
2 changes: 1 addition & 1 deletion pup
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace StellarWP\Pup;

const PUP_VERSION = '1.2.5';
const PUP_VERSION = '1.3.2';
define( '__PUP_DIR__', __DIR__ );

if ( ! \Phar::running() ) {
Expand Down
2 changes: 2 additions & 0 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ 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() );
$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() );

Expand Down
13 changes: 12 additions & 1 deletion src/Command/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand All @@ -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.
*
Expand Down Expand Up @@ -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 );
}

Expand All @@ -65,4 +76,4 @@ protected function getIO(): Io {
public function setShouldNotValidatePuprc() {
$this->should_validate_puprc = false;
}
}
}
2 changes: 1 addition & 1 deletion src/Commands/Build.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected function execute( InputInterface $input, OutputInterface $output ) {
chdir( $config->getWorkingDir() );
}

$io->writeln( '<info>Build complete.</info>' );
$io->writeln( '<fg=green>✓</> <success>Build complete.</success>' );
return 0;
}
}
2 changes: 1 addition & 1 deletion src/Commands/Checks/AbstractCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,4 @@ public function shouldBailOnFailureDev(): bool {
protected function writeln( string $message ) {
$this->getIO()->writeln( $message );
}
}
}
6 changes: 3 additions & 3 deletions src/Commands/Checks/Tbd.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ protected function checkExecute( InputInterface $input, Io $output ): int {
$output->writeln( '' );
}
} else {
$output->writeln( '<info>No TBDs found!</info>' );
$output->writeln( '<success>No TBDs found!</success>' );
$output->writeln( '' );
}
$output->writeln( '' );

if ( $found_tbds ) {
$output->writeln( "<fg=red>TBDs have been found!</>" );
} else {
$output->writeln( '<info>Success! No TBDs found.</info>' );
$output->writeln( '<success>Success! No TBDs found.</success>' );
}

return $found_tbds ? 1 : 0;
Expand Down Expand Up @@ -168,4 +168,4 @@ protected function scanDir( string $root, string $current_dir, string $scan_dir,

return $matched_lines;
}
}
}
4 changes: 2 additions & 2 deletions src/Commands/Checks/VersionConflict.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ protected function checkExecute( InputInterface $input, Io $output ): int {
return 1;
}

$output->writeln( '<info>No version conflicts found.</info>' );
$output->writeln( '<success>No version conflicts found.</success>' );
return 0;
}
}
}
14 changes: 6 additions & 8 deletions src/Commands/Clean.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,22 @@ protected function execute( InputInterface $input, OutputInterface $output ) {
$clean_steps = $config->getCleanCommands();
$io = $this->getIO();

$output->writeln( '<fg=yellow>Cleaning up...</>' );
$this->io->section( '<fg=yellow>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( "<fg=green>✓</> 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( "<fg=green>✓</> 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( '<fg=green>✓</> Removing .pup-distfiles...Complete.' );
} else {
throw new \Exception( "Could not remove {$build_dir}." );
}
Expand All @@ -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( '<fg=green>✓</> Removing .pup-distignore...Complete.' );
} else {
throw new \Exception( "Could not remove {$build_dir}." );
}
Expand All @@ -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( '<fg=green>✓</> Removing .pup-distinclude...Complete.' );
} else {
throw new \Exception( "Could not remove {$build_dir}." );
}
Expand Down
Loading

0 comments on commit c7c3bd1

Please sign in to comment.