Skip to content

Commit 4f8357f

Browse files
Merge pull request #17 from codenamephp/task/addReleaseInfo
Task: Add Revison Task
2 parents 52bc9e6 + e4dec89 commit 4f8357f

2 files changed

Lines changed: 114 additions & 0 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* Copyright 2023 Bastian Schwarz <[email protected]>.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
namespace de\codenamephp\deployer\base\task\deploy\releaseInfo\Revision;
19+
20+
use de\codenamephp\deployer\base\functions\All;
21+
use de\codenamephp\deployer\base\functions\iRun;
22+
use de\codenamephp\deployer\base\task\iTask;
23+
use de\codenamephp\deployer\base\task\iTaskWithDescription;
24+
use de\codenamephp\deployer\base\task\iTaskWithName;
25+
26+
/**
27+
* Creates a revision file from a config value that can be used to identify the release, e.g. in a sentry client.
28+
*
29+
* The config key is used to get the value from the config using the usual replacement syntax, so it is passed to run with {{configKey}}. This means
30+
* that the revision can be set with "-o releaseInfo.revision=1234" on the command line or in the config file.
31+
*/
32+
final class FromConfig implements iTask, iTaskWithName, iTaskWithDescription {
33+
34+
public const NAME = 'deploy:release_info:revision:from_config';
35+
36+
public function __construct(
37+
public readonly string $configKey = 'releaseInfo.revision',
38+
public readonly string $revisionFile = '{{release_or_current_path}}/REVISION',
39+
public readonly iRun $run = new All(),
40+
) {}
41+
42+
public function getDescription() : string {
43+
return "Creates a revision file from a config value that can be used to identify the release, e.g. in a sentry client. Set the value with -o {$this->configKey}='your revision' on the command line or in the config file.";
44+
}
45+
46+
public function getName() : string {
47+
return self::NAME;
48+
}
49+
50+
public function __invoke() : void {
51+
$this->run->run("echo '{{{$this->configKey}}}' > '$this->revisionFile'");
52+
}
53+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* Copyright 2023 Bastian Schwarz <[email protected]>.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
namespace de\codenamephp\deployer\base\test\task\deploy\releaseInfo\Revision;
19+
20+
use de\codenamephp\deployer\base\functions\All;
21+
use de\codenamephp\deployer\base\functions\iRun;
22+
use de\codenamephp\deployer\base\task\deploy\releaseInfo\Revision\FromConfig;
23+
use PHPUnit\Framework\TestCase;
24+
25+
final class FromConfigTest extends TestCase {
26+
27+
public function test__invoke() : void {
28+
$run = $this->createMock(iRun::class);
29+
$run->expects(self::once())->method('run')->with("echo '{{some key}}' > 'some path'");
30+
31+
$sut = new FromConfig('some key', 'some path', $run);
32+
33+
$sut();
34+
}
35+
36+
public function testGetDescription() : void {
37+
self::assertSame("Creates a revision file from a config value that can be used to identify the release, e.g. in a sentry client. Set the value with -o releaseInfo.revision='your revision' on the command line or in the config file.", (new FromConfig())->getDescription());
38+
}
39+
40+
public function test__construct() : void {
41+
$sut = new FromConfig();
42+
43+
self::assertSame('releaseInfo.revision', $sut->configKey);
44+
self::assertSame('{{release_or_current_path}}/REVISION', $sut->revisionFile);
45+
self::assertInstanceOf(All::class, $sut->run);
46+
}
47+
48+
public function test__construct_withOptionalArguments() : void {
49+
$run = $this->createMock(iRun::class);
50+
51+
$sut = new FromConfig('some key', 'some path', $run);
52+
53+
self::assertSame('some key', $sut->configKey);
54+
self::assertSame('some path', $sut->revisionFile);
55+
self::assertSame($run, $sut->run);
56+
}
57+
58+
public function testGetName() : void {
59+
self::assertSame(FromConfig::NAME, (new FromConfig())->getName());
60+
}
61+
}

0 commit comments

Comments
 (0)