-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #230 from ghostwriter/feature/support-running-auto…
…matic-releases-actions-after-failure Re-running automatic releases actions after failure
- Loading branch information
Showing
7 changed files
with
210 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Laminas\AutomaticReleases\Git; | ||
|
||
interface HasTag | ||
{ | ||
/** | ||
* @param non-empty-string $repositoryDirectory | ||
* @param non-empty-string $tagName | ||
*/ | ||
public function __invoke( | ||
string $repositoryDirectory, | ||
string $tagName, | ||
): bool; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Laminas\AutomaticReleases\Git; | ||
|
||
use Psl\Shell; | ||
|
||
use function str_contains; | ||
use function trim; | ||
|
||
final class HasTagViaConsole implements HasTag | ||
{ | ||
public function __invoke(string $repositoryDirectory, string $tagName): bool | ||
{ | ||
$output = Shell\execute('git', ['tag', '--list', $tagName], $repositoryDirectory); | ||
|
||
if (trim($output) === '') { | ||
return false; | ||
} | ||
|
||
return str_contains($output, $tagName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Laminas\AutomaticReleases\Test\Unit\Git; | ||
|
||
use Laminas\AutomaticReleases\Git\HasTag; | ||
use Laminas\AutomaticReleases\Git\HasTagViaConsole; | ||
use PHPUnit\Framework\TestCase; | ||
use Psl\Env; | ||
use Psl\Filesystem; | ||
use Psl\Shell; | ||
|
||
use function array_map; | ||
use function sprintf; | ||
|
||
/** @covers \Laminas\AutomaticReleases\Git\HasTagViaConsole */ | ||
final class HasTagViaConsoleTest extends TestCase | ||
{ | ||
/** @var non-empty-string */ | ||
private string $repository; | ||
private HasTag $hasTag; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->repository = Filesystem\create_temporary_file(Env\temp_dir(), 'HasTagViaConsoleRepository'); | ||
|
||
$this->hasTag = new HasTagViaConsole(); | ||
|
||
Filesystem\delete_file($this->repository); | ||
Filesystem\create_directory($this->repository); | ||
|
||
Shell\execute('git', ['init'], $this->repository); | ||
|
||
Shell\execute('git', ['config', 'user.email', '[email protected]'], $this->repository); | ||
Shell\execute('git', ['config', 'user.name', 'Just Me'], $this->repository); | ||
|
||
array_map(fn (string $tag) => $this->createTag($tag), [ | ||
'1.0.0', | ||
'2.0.0', | ||
]); | ||
} | ||
|
||
private function createTag(string $tag): void | ||
{ | ||
Shell\execute('git', ['commit', '--allow-empty', '-m', 'a commit for version ' . $tag], $this->repository); | ||
Shell\execute('git', ['tag', '-a', $tag, '-m', 'version ' . $tag], $this->repository); | ||
} | ||
|
||
/** | ||
* @param non-empty-string $repository | ||
* @param non-empty-string $tag | ||
*/ | ||
private function assertGitTagExists(string $repository, string $tag): void | ||
{ | ||
self::assertTrue(($this->hasTag)($repository, $tag), sprintf('Failed asserting git tag "%s" exists.', $tag)); | ||
} | ||
|
||
/** | ||
* @param non-empty-string $repository | ||
* @param non-empty-string $tag | ||
*/ | ||
private function assertGitTagMissing(string $repository, string $tag): void | ||
{ | ||
self::assertFalse(($this->hasTag)($repository, $tag), sprintf('Failed asserting git tag "%s" is missing.', $tag)); | ||
} | ||
|
||
public function testHasTag(): void | ||
{ | ||
$this->assertGitTagExists($this->repository, '1.0.0'); | ||
} | ||
|
||
public function testHasTagMissing(): void | ||
{ | ||
$this->assertGitTagMissing($this->repository, '10.0.0'); | ||
} | ||
} |