-
-
Notifications
You must be signed in to change notification settings - Fork 22
Skip creating GIT tag if one already exists, enabling re-running of the action if a release creation fails #230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Ocramius
merged 5 commits into
laminas:1.24.x
from
ghostwriter:feature/support-running-automatic-releases-actions-after-failure
Jan 5, 2023
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7199f49
Add support for git tag existence check
ghostwriter 277dbc9
Refactor: create tag via console if not exists
ghostwriter 6c9d81a
Revert Imports
ghostwriter b51fcfd
Add logs when skipping already existing tags
ghostwriter 1a77168
Fix Psalm docs
ghostwriter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Laminas\AutomaticReleases\Git; | ||
|
||
interface HasTag | ||
{ | ||
/** @param non-empty-string $repositoryDirectory */ | ||
ghostwriter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public function __invoke( | ||
string $repositoryDirectory, | ||
string $tagName, | ||
): bool; | ||
} |
This file contains hidden or 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,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Laminas\AutomaticReleases\Git; | ||
|
||
use function Psl\Shell\execute; | ||
use function str_contains; | ||
use function trim; | ||
|
||
final class HasTagViaConsole implements HasTag | ||
{ | ||
public function __invoke(string $repositoryDirectory, string $tagName): bool | ||
{ | ||
$outout = execute('git', ['tag', '--list', $tagName], $repositoryDirectory); | ||
ghostwriter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (trim($outout) === '') { | ||
return false; | ||
} | ||
|
||
return str_contains($outout, $tagName); | ||
Ocramius marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
This file contains hidden or 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 hidden or 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,75 @@ | ||
<?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 function array_map; | ||
use function Psl\Env\temp_dir; | ||
use function Psl\Filesystem\create_directory; | ||
use function Psl\Filesystem\create_temporary_file; | ||
use function Psl\Filesystem\delete_file; | ||
use function Psl\Shell\execute; | ||
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 = create_temporary_file(temp_dir(), 'HasTagViaConsoleRepository'); | ||
|
||
$this->hasTag = new HasTagViaConsole(); | ||
|
||
delete_file($this->repository); | ||
create_directory($this->repository); | ||
|
||
execute('git', ['init'], $this->repository); | ||
|
||
execute('git', ['config', 'user.email', '[email protected]'], $this->repository); | ||
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 | ||
{ | ||
execute('git', ['commit', '--allow-empty', '-m', 'a commit for version ' . $tag], $this->repository); | ||
execute('git', ['tag', '-a', $tag, '-m', 'version ' . $tag], $this->repository); | ||
} | ||
|
||
/** @param non-empty-string $repository */ | ||
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 */ | ||
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 | ||
{ | ||
self::assertGitTagExists($this->repository, '1.0.0'); | ||
} | ||
|
||
public function testHasTagMissing(): void | ||
{ | ||
self::assertGitTagMissing($this->repository, '10.0.0'); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.