Skip to content

Commit

Permalink
Rework the releasing
Browse files Browse the repository at this point in the history
  • Loading branch information
lyrixx committed Nov 14, 2024
1 parent 002d395 commit 8cb3e13
Show file tree
Hide file tree
Showing 21 changed files with 280 additions and 77 deletions.
34 changes: 2 additions & 32 deletions .github/workflows/artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ name: Artifacts
on:
push:
branches: [ "main" ]
release:
types: [ "created" ]

permissions:
contents: write
Expand All @@ -31,7 +29,7 @@ jobs:
path: tools/phar/build/castor.linux-amd64.phar
if-no-files-found: error

- name: Upload the Linux ARM64 phar
- name: Upload the Linux amr64 phar
uses: actions/upload-artifact@v4
with:
name: 'castor.linux-arm64.phar'
Expand All @@ -45,7 +43,7 @@ jobs:
path: tools/phar/build/castor.darwin-amd64.phar
if-no-files-found: error

- name: Upload the Darwin ARM64 phar
- name: Upload the Darwin amr64 phar
uses: actions/upload-artifact@v4
with:
name: 'castor.darwin-arm64.phar'
Expand Down Expand Up @@ -157,31 +155,3 @@ jobs:
name: "castor.darwin-arm64"
path: ./castor.darwin-arm64
if-no-files-found: error

release:
name: Upload artifacts to the release
if: github.event_name == 'release'
needs: [phars, static-linux-amd64, static-darwin-amd64, static-darwin-arm64]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: retrieve artifacts
uses: actions/download-artifact@v4
with:
path: build
merge-multiple: true

- name: Upload files
run: |
gh release upload ${{ github.ref_name }} ./build/castor.darwin-amd64
gh release upload ${{ github.ref_name }} ./build/castor.darwin-amd64.phar
gh release upload ${{ github.ref_name }} ./build/castor.darwin-arm64
gh release upload ${{ github.ref_name }} ./build/castor.darwin-arm64.phar
gh release upload ${{ github.ref_name }} ./build/castor.linux-amd64
gh release upload ${{ github.ref_name }} ./build/castor.linux-amd64.phar
gh release upload ${{ github.ref_name }} ./build/castor.linux-arm64.phar
gh release upload ${{ github.ref_name }} ./build/castor.windows-amd64.phar
env:
GH_TOKEN: ${{ github.token }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
!/castor.composer.json
!/castor.composer.lock
site/
/tools/release/artifacts/
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Not released yet

### Internal

* Rework the releasing

## 0.20.0 (2024-11-13)

### Features
Expand Down
1 change: 1 addition & 0 deletions bin/generate-tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
'watch:stop',
'open:documentation',
'open:multiple',
'release',
// Not examples
'castor:compile',
'castor:phar:build',
Expand Down
1 change: 1 addition & 0 deletions castor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import(__DIR__ . '/tools/static/castor.php');

mount(__DIR__ . '/tools/phar');
mount(__DIR__ . '/tools/release');
mount(__DIR__ . '/tools/watcher');

#[AsTask(description: 'hello')]
Expand Down
18 changes: 18 additions & 0 deletions src/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
namespace Castor\Console;

use Castor\Container;
use Castor\Exception\ProblemException;
use Castor\Kernel;
use Symfony\Component\Console\Application as SymfonyApplication;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/** @internal */
Expand All @@ -23,6 +26,8 @@ class Application extends SymfonyApplication
public function __construct(
private readonly ContainerBuilder $containerBuilder,
private readonly Kernel $kernel,
#[Autowire(lazy: true)]
private readonly SymfonyStyle $io,
) {
parent::__construct(static::NAME, static::VERSION);
}
Expand Down Expand Up @@ -53,6 +58,19 @@ public function getHelp(): string
return $this->getLogo() . parent::getHelp();
}

public function renderThrowable(\Throwable $e, OutputInterface $output): void
{
if (!$output->isVerbose()) {
if ($e instanceof ProblemException) {
$this->io->error($e->getMessage());

return;
}
}

parent::renderThrowable($e, $output);
}

protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output): int
{
$this->command = $command;
Expand Down
15 changes: 15 additions & 0 deletions src/Exception/ProblemException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Castor\Exception;

class ProblemException extends \RuntimeException
{
public function __construct(string $message, int $code = 1, ?\Throwable $previous = null)
{
if ($code < 1) {
throw new \InvalidArgumentException('The code must be greater than 0.');
}

parent::__construct($message, $code, $previous);
}
}
3 changes: 1 addition & 2 deletions src/Runner/ProcessRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Symfony\Component\Process\Process;

use function Castor\context;
use function Castor\Internal\fix_exception;

/** @internal */
class ProcessRunner
Expand Down Expand Up @@ -218,7 +217,7 @@ public function run(
throw new ProcessFailedException($process);
}

throw fix_exception(new \Exception("The command \"{$process->getCommandLine()}\" failed."), 1);
throw new \RuntimeException("The command \"{$process->getCommandLine()}\" failed.");
}

return $process;
Expand Down
2 changes: 1 addition & 1 deletion src/functions-internal.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function castor_require(string $file): void
*
* @internal
*/
function fix_exception(\Exception $exception, int $depth = 0): \Exception
function fix_exception(\Throwable $exception, int $depth = 0): \Throwable
{
$lastFrame = $exception->getTrace()[$depth];
foreach (['file', 'line'] as $key) {
Expand Down
85 changes: 53 additions & 32 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,26 @@ function run(
$workingDirectory = $path;
}

return Container::get()->processRunner->run(
$command,
$environment,
$workingDirectory,
$tty,
$pty,
$timeout,
$quiet,
$allowFailure,
$notify,
$callback,
$context,
);
try {
return Container::get()
->processRunner
->run(
$command,
$environment,
$workingDirectory,
$tty,
$pty,
$timeout,
$quiet,
$allowFailure,
$notify,
$callback,
$context,
)
;
} catch (\Throwable $e) {
throw fix_exception($e, 1);
}
}

/**
Expand All @@ -101,23 +108,30 @@ function capture(
?string $path = null,
): string {
if ($workingDirectory && $path) {
throw new \LogicException('You cannot use both the "path" and "workingDirectory" arguments at the same time.');
throw fix_exception(new \LogicException('You cannot use both the "path" and "workingDirectory" arguments at the same time.'), 1);
}
if ($path) {
trigger_deprecation('jolicode/castor', '0.15', 'The "path" argument is deprecated, use "workingDirectory" instead.');

$workingDirectory = $path;
}

return Container::get()->processRunner->capture(
$command,
$environment,
$workingDirectory,
$timeout,
$allowFailure,
$onFailure,
$context,
);
try {
return Container::get()
->processRunner
->capture(
$command,
$environment,
$workingDirectory,
$timeout,
$allowFailure,
$onFailure,
$context,
)
;
} catch (\Throwable $e) {
throw fix_exception($e, 2);
}
}

/**
Expand All @@ -134,22 +148,29 @@ function exit_code(
?string $path = null,
): int {
if ($workingDirectory && $path) {
throw new \LogicException('You cannot use both the "path" and "workingDirectory" arguments at the same time.');
throw fix_exception(new \LogicException('You cannot use both the "path" and "workingDirectory" arguments at the same time.'));
}
if ($path) {
trigger_deprecation('jolicode/castor', '0.15', 'The "path" argument is deprecated, use "workingDirectory" instead.');

$workingDirectory = $path;
}

return Container::get()->processRunner->exitCode(
$command,
$environment,
$workingDirectory,
$timeout,
$quiet,
$context,
);
try {
return Container::get()
->processRunner
->exitCode(
$command,
$environment,
$workingDirectory,
$timeout,
$quiet,
$context,
)
;
} catch (\Throwable $e) {
throw fix_exception($e, 2);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
In ProcessRunner.php line XXXX:
In functions.php line XXXX:

The command "bash -c i_do_not_exist -x -e" failed.

Expand Down
1 change: 1 addition & 0 deletions tests/Generated/ListTest.php.output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ hello hello
help Display help for a command
list List commands
no-namespace Task without a namespace
release Release a new version of castor
args:another-args Dumps all arguments and options, without configuration
args:args Dumps all arguments and options, with custom configuration
args:autocomplete-argument Provides autocomplete for an argument
Expand Down
4 changes: 2 additions & 2 deletions tests/Generated/RunExceptionVerboseTest.php.err.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
In ProcessRunner.php line XXXX:
In run.php line 64:

[Symfony\Component\Process\Exception\ProcessFailedException]
The command "echo foo; echo bar>&2; exit 1" failed.
Expand All @@ -18,7 +18,7 @@ In ProcessRunner.php line XXXX:


Exception trace:
at .../src/Runner/ProcessRunner.php:XXXX
at .../examples/run.php:XXXX
Castor\Runner\ProcessRunner->run() at .../src/functions.php:XXXX
Castor\run() at .../examples/run.php:XXXX
run\exception() at .../src/Console/Command/TaskCommand.php:XXXX
Expand Down
2 changes: 1 addition & 1 deletion tests/Generated/ShellBashTest.php.err.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
In Process.php line XXXX:
In functions.php line XXXX:

TTY mode requires /dev/tty to be read/writable.

Expand Down
2 changes: 1 addition & 1 deletion tests/Generated/ShellShTest.php.err.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
In Process.php line XXXX:
In functions.php line XXXX:

TTY mode requires /dev/tty to be read/writable.

Expand Down
2 changes: 1 addition & 1 deletion tests/Generated/SshDownloadTest.php.err.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ssh: Could not resolve hostname server-1.example.com: Name or service not known

In SshRunner.php line XXXX:
In ProcessRunner.php line XXXX:

The command "scp -r [email protected]:/tmp/test.html /var/www/index.html" failed.

Expand Down
2 changes: 1 addition & 1 deletion tests/Generated/SshLsTest.php.err.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ssh: Could not resolve hostname server-1.example.com: Name or service not known

In SshRunner.php line XXXX:
In ProcessRunner.php line XXXX:

The command "ssh -p 2222 [email protected] 'bash -se' << \EOF-SPATIE-SSH
cd /var/www && ls -alh
Expand Down
2 changes: 1 addition & 1 deletion tests/Generated/SshRealTimeOutputTest.php.err.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
In SshRunner.php line XXXX:
In ProcessRunner.php line XXXX:

The command "ssh [email protected] 'bash -se' << \EOF-SPATIE-SSH
ls -alh
Expand Down
2 changes: 1 addition & 1 deletion tests/Generated/SshUploadTest.php.err.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ssh: Could not resolve hostname server-1.example.com: Name or service not known

In SshRunner.php line XXXX:
In ProcessRunner.php line XXXX:

The command "scp -r .../examples/ssh.php [email protected]:/var/www/index.html" failed.

Expand Down
2 changes: 1 addition & 1 deletion tests/Generated/SshWhoamiTest.php.err.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ssh: Could not resolve hostname server-1.example.com: Name or service not known

In SshRunner.php line XXXX:
In ProcessRunner.php line XXXX:

The command "ssh -p 2222 server-1.example.com 'bash -se' << \EOF-SPATIE-SSH
cd /var/www && whoami
Expand Down
Loading

0 comments on commit 8cb3e13

Please sign in to comment.