Skip to content
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

Avoid failures on removal of published artifacts #416

Merged
merged 1 commit into from
Apr 6, 2023

Conversation

ljacomet
Copy link
Collaborator

@ljacomet ljacomet commented Apr 6, 2023

Summary

In the Gradle sigstore plugin:

  • Makes handling an artifact removal from the publication conditional to the plugin having derived a signature from it.

Unfortunately, testing this is quite messy as it would require a dual signing setup: sigstore + pgp. If required, I can add such a test. Ideally in a follow up PR as getting a version of the plugin released with this fix would be awesome. Conference driven development 😉

Result with the 0.4.0 sigstore version can be seen in this GH action run.

I have tested locally that the fix here allows to skip GPG signing of *.sigstore artifacts

Release Note

Documentation

NONE

@ljacomet ljacomet force-pushed the gradle-artifact-removal branch from e7607cd to de2e29e Compare April 6, 2023 10:14
@ljacomet ljacomet requested a review from vlsi April 6, 2023 10:14
@ljacomet ljacomet self-assigned this Apr 6, 2023
@@ -14,7 +14,7 @@ val localRepoElements by configurations.creating {
}
}

val localRepoDir = layout.buildDirectory.dir("local-maven-repo")
val localRepoDir = rootProject.layout.buildDirectory.dir("local-maven-repo")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would break multi-module concurrent execution. There's cleanLocalRepository to wipe the repo, and every module would run it at random, so you'll end up with half-empty local-maven-repo.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you are saying that folks run ./gradlew cleanLocalRepository publishAllPublicationsToTmp-mavenRepository in a single invocation?

I did not think of that indeed.

Let me see about figuring it out. Because the current setup really is messy for testing changes that require new versions of the whole stack.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me see about figuring it out. Because the current setup really is messy for testing changes that require new versions of the whole stack.

Could you clarify "messy"?
running with composite builds or publishToMavenLocal should work if you mean testing the changes for external project.

I would say the current setup is just fine for testing changes.
The only required bit is to add a PGP key and pass it to the existing test SigstorePublishSignTest

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I missed that the publication depends on the clean up task always.

Accidentally, the problem you describe cannot happen right now: Gradle marks all subsequent runs of the clean task as up-to-date. I believe this is because for Gradle the fingerprint of those tasks is a single value. But that is brittle anyway.

Looking for a better solution.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

publishToMavenLocal and unicorns die 😉

I really want Gradle to get rid of that option and instead recommend usage of local repositories. That's my attempt in tweaking this.

But I see that you have a different perspective. I'll back out this change for now as it is unrelated.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(thank you GH for not showing me the update when I replied on my before last message)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really want Gradle to get rid of that option and instead recommend usage of local repositories

I do not like publishToMavenLocal either, however, I think it would be nice if Gradle provided something like publishToRootProjectRepo.

Comment on lines 99 to 111
// 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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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) ?: return@whenPublishableArtifactRemoved
publication.removeDerivedArtifact(artifact)
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 }
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not a proficient Kotlin user. But from a personal perspective, I find following the flow with different return@ a bit harder.

Do you have a strong preference for your version @vlsi ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Early exit allows reducing the nesting of the blocks, and it enables easier reasoning.

In this case, we check the artifact, and skip everything if the artifact is unknown. The code like if (..) { if (...) { ...} } else {... } is hard to read.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had an if based version at first and I agree that the less likable of all. The also method feels more natural to me. But that's a style thing effectively.
Will move to your proposal.

@vlsi
Copy link
Collaborator

vlsi commented Apr 6, 2023

Testing would indeed require adding PGP key and signing with that (see

), so I think it might be ok if we keep manual tests only.

I wonder if we should exclude pgp-signing .sigstore files by default though (e.g. flagged with Gradle property for cases when users' repository requires .asc for everything), so the users apply sigstore plugin and deploy without signatures.

Only handle them when they are artifacts sigstore created a signature for.

Fixes sigstore#414

Signed-off-by: Louis Jacomet <louis@gradle.com>
@ljacomet ljacomet force-pushed the gradle-artifact-removal branch from de2e29e to 63585cd Compare April 6, 2023 13:47
@ljacomet
Copy link
Collaborator Author

ljacomet commented Apr 6, 2023

@vlsi I have updated the PR to focus on the issue only and applied your suggestion.

Would it be an option to release a 0.4.1 of the plugin once this is merged?

@vlsi vlsi added the safe to test conformance testing label label Apr 6, 2023
@vlsi vlsi changed the title Gradle artifact removal Avoid failures on removal of published artifacts Apr 6, 2023
@vlsi vlsi merged commit 8fb89b6 into sigstore:main Apr 6, 2023
@vlsi
Copy link
Collaborator

vlsi commented Apr 6, 2023

@ljacomet , I've pushed the plugin as 0.4.1: https://plugins.gradle.org/plugin/dev.sigstore.sign

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
safe to test conformance testing label
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gradle plugin: Logic to unregister derived artifacts from a publication is too eager
2 participants