From 4f92a27d8521bd878e23f7d27785335219335a29 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Thu, 3 Oct 2024 16:18:23 +1300 Subject: [PATCH] ENH Skip repositories we've already tagged 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. --- src/Model/Modules/Library.php | 14 ++++++++++++++ src/Steps/Release/PublishRelease.php | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/Model/Modules/Library.php b/src/Model/Modules/Library.php index c601d8e..d55230b 100644 --- a/src/Model/Modules/Library.php +++ b/src/Model/Modules/Library.php @@ -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 * diff --git a/src/Steps/Release/PublishRelease.php b/src/Steps/Release/PublishRelease.php index 22d8e83..3d98149 100644 --- a/src/Steps/Release/PublishRelease.php +++ b/src/Steps/Release/PublishRelease.php @@ -118,6 +118,11 @@ protected function releaseLibrary( die(); } + if ($this->hasTag($releasePlanNode)) { + $this->log($output, "Library {$name} has already been released. Skipping."); + return; + } + $versionName = $releasePlanNode->getVersion()->getValue(); $this->log($output, "Releasing library {$name} at version {$versionName}"); @@ -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