Skip to content

Commit

Permalink
ENH Skip repositories we've already tagged (#260)
Browse files Browse the repository at this point in the history
If an error occurs when cow has already tagged 15 repos, we want to be
able to rerun the release command and skip anything we've already
tagged.
  • Loading branch information
GuySartorelli authored Oct 8, 2024
1 parent 04c2493 commit 4c8273c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Model/Modules/Library.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,20 @@ public function getTags()
return $this->tags;
}

/**
* Check if a tag exists in the repository
*/
public function hasTag(string $tag): bool
{
$repo = $this->getRepository();
if ($this->getProject()->getFetchTags()) {
// Fetch remote tags from origin first
$repo->run('fetch', ['--tags']);
}

return (bool) $repo->run('tag', ['--list', $tag]);
}

/**
* Tag this module
*
Expand Down
14 changes: 14 additions & 0 deletions src/Steps/Release/PublishRelease.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ protected function releaseLibrary(
die();
}

if ($this->hasTag($releasePlanNode)) {
$this->log($output, "Library <info>{$name}</info> has already been released. <comment>Skipping.</comment>");
return;
}

$versionName = $releasePlanNode->getVersion()->getValue();
$this->log($output, "Releasing library <info>{$name}</info> at version <info>{$versionName}</info>");

Expand Down Expand Up @@ -163,6 +168,15 @@ protected function publishTag(OutputInterface $output, LibraryRelease $releasePl
$this->log($output, 'Tagging complete');
}

/**
* Check if this release node already has the tag we're going to release
*/
protected function hasTag(LibraryRelease $releasePlan): bool
{
$library = $releasePlan->getLibrary();
$tag = $releasePlan->getVersion()->getValue();
return $library->hasTag($tag);
}

/**
* Update github release notes via github API
Expand Down

0 comments on commit 4c8273c

Please sign in to comment.