Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
name: CI

on:
merge_group:
types:
- checks_requested
paths-ignore:
- '**.md'
push:
branches:
- main
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/update-changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Prepare Release
on:
merge_group:
types:
- checks_requested

jobs:
calculate_next_version:
uses: codenamephp/workflows.common/.github/workflows/calculate-next-version.yml@1
update_changelog:
uses: codenamephp/workflows.common/.github/workflows/update-changelog.yml@1
needs: calculate_next_version
with:
ref: ${{github.ref_name}}
future-release: ${{ needs.calculate_next_version.outputs.version }}
release-branch: 'release'
5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/deployer.crontab.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

130 changes: 130 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions .idea/jsonSchemas.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/php-test-framework.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"psalm": "tools/psalm --threads=10 --long-progress",
"composer-unused": "tools/composer-unused --no-progress --no-interaction",
"composer-require-checker": "tools/composer-require-checker --no-interaction",
"infection": "XDEBUG_MODE=coverage tools/infection --min-msi=95 --min-covered-msi=95 --threads=4 --no-progress --show-mutations",
"infection": "XDEBUG_MODE=coverage tools/infection --min-msi=100 --min-covered-msi=100 --threads=4 --no-progress --show-mutations",
"ci-all": [
"@phpunit",
"@psalm",
Expand Down
25 changes: 25 additions & 0 deletions src/Command/CrontabCommandFactoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php declare(strict_types=1);

namespace de\codenamephp\deployer\crontab\Command;

use de\codenamephp\deployer\command\iCommand;
use de\codenamephp\deployer\command\runConfiguration\iRunConfiguration;

/**
* Interface for factories that create crontab commands, e.g. by getting the binary from deployer
*
* @psalm-api
*/
interface CrontabCommandFactoryInterface
{
/**
* Implementations MUST make sure the command gets the correct binary (e.g. from deployer) and that all parameters are passed on correctly
*
* @param array<int, string> $options Array of arguments to pass to the command with numerical indexes so the arguments can be expanded, e.g. ['--production', '--fund=false']
* @param string|null $file The file to use. Defaults to null which means the default crontab file will be used
* @param bool $sudo Flag if the command should be executed as root
* @param iRunConfiguration|null $runConfiguration The run configuration for the command. Defaults to an empty configuration
* @return iCommand The command to run
*/
public function build(array $options = [], string $file = null, bool $sudo = false, iRunConfiguration $runConfiguration = null) : iCommand;
}
29 changes: 29 additions & 0 deletions src/Command/WithBinaryFromDeployer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php declare(strict_types=1);

namespace de\codenamephp\deployer\crontab\Command;

use de\codenamephp\deployer\base\functions\All;
use de\codenamephp\deployer\base\functions\iGet;
use de\codenamephp\deployer\command\Command;
use de\codenamephp\deployer\command\iCommand;
use de\codenamephp\deployer\command\runConfiguration\iRunConfiguration;
use de\codenamephp\deployer\command\runConfiguration\SimpleContainer;

/**
* Gets the crontab binary from deployer and defaults to crontab if it is not set
*
* @psalm-api
*/
final class WithBinaryFromDeployer implements CrontabCommandFactoryInterface {

public function __construct(public iGet $deployer = new All()) {}

public function build(array $options = [], string $file = null, bool $sudo = false, iRunConfiguration $runConfiguration = null) : iCommand {
return new Command(
(string) $this->deployer->get('crontab:binary', 'crontab'),
$options,
[],
$sudo,
$runConfiguration ?? new SimpleContainer());
}
}
52 changes: 52 additions & 0 deletions test/Command/WithBinaryFromDeployerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php declare(strict_types=1);

namespace de\codenamephp\deployer\crontab\test\Command;

use de\codenamephp\deployer\base\functions\All;
use de\codenamephp\deployer\base\functions\iGet;
use de\codenamephp\deployer\command\Command;
use de\codenamephp\deployer\command\runConfiguration\iRunConfiguration;
use de\codenamephp\deployer\command\runConfiguration\SimpleContainer;
use de\codenamephp\deployer\crontab\Command\WithBinaryFromDeployer;
use PHPUnit\Framework\TestCase;

final class WithBinaryFromDeployerTest extends TestCase {

public function test__construct() : void {
$sut = new WithBinaryFromDeployer();

self::assertInstanceOf(All::class, $sut->deployer);
}

public function test__construct_withOptionalArguments() : void {
$deployer = $this->createMock(iGet::class);

$sut = new WithBinaryFromDeployer($deployer);

self::assertSame($deployer, $sut->deployer);
}

public function testBuild() : void {
$deployer = $this->createMock(iGet::class);
$deployer->expects(self::once())->method('get')->with('crontab:binary', 'crontab')->willReturn('crontab');

$sut = new WithBinaryFromDeployer($deployer);

$command = $sut->build();

self::assertEquals(new Command('crontab', [], [], false, new SimpleContainer()), $command);
}

public function testBuild_withOptionalArguments() : void {
$deployer = $this->createMock(iGet::class);
$deployer->expects(self::once())->method('get')->with('crontab:binary', 'crontab')->willReturn(null);

$sut = new WithBinaryFromDeployer($deployer);

$runConfiguration = $this->createMock(iRunConfiguration::class);

$command = $sut->build(['some', 'options'], 'someFile', true, $runConfiguration);

self::assertEquals(new Command('', ['some', 'options'], [], true, $runConfiguration), $command);
}
}