From e7607cd4e2d5cc961bc4a26b0cb967e9ac9d883f Mon Sep 17 00:00:00 2001 From: Louis Jacomet Date: Thu, 6 Apr 2023 12:04:00 +0200 Subject: [PATCH] Fix reacting to removed published artifacts Only handle them when they are artifacts sigstore created a signature for. Fixes #414 --- .../sigstore/sign/SigstoreSignExtension.kt | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/sigstore-gradle/sigstore-gradle-sign-base-plugin/src/main/kotlin/dev/sigstore/sign/SigstoreSignExtension.kt b/sigstore-gradle/sigstore-gradle-sign-base-plugin/src/main/kotlin/dev/sigstore/sign/SigstoreSignExtension.kt index e678b366..86c68a1c 100644 --- a/sigstore-gradle/sigstore-gradle-sign-base-plugin/src/main/kotlin/dev/sigstore/sign/SigstoreSignExtension.kt +++ b/sigstore-gradle/sigstore-gradle-sign-base-plugin/src/main/kotlin/dev/sigstore/sign/SigstoreSignExtension.kt @@ -96,18 +96,20 @@ abstract class SigstoreSignExtension(private val project: Project) { } publication.whenPublishableArtifactRemoved { val publishableArtifact = this - signTask.configure { - signatures.findByName(file.name) - ?.takeIf { publishableArtifact in it.builtBy } - ?.let { - signatures.remove(it) - return@configure - } - // Slow path just in case - signatures.removeIf { publishableArtifact in it.builtBy } + // Ignore artifacts that we have not added a signature for + artifacts.remove(publishableArtifact)?.also { + signTask.configure { + signatures.findByName(publishableArtifact.file.name) + ?.takeIf { publishableArtifact in it.builtBy } + ?.let { + signatures.remove(it) + return@configure + } + // Slow path just in case + signatures.removeIf { publishableArtifact in it.builtBy } + } + publication.removeDerivedArtifact(it) } - val artifact = artifacts.remove(publishableArtifact) - publication.removeDerivedArtifact(artifact) } } }