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

automatically close the created repository and optionally also release it #403

Merged
merged 1 commit into from Sep 4, 2022

Conversation

gabrielittner
Copy link
Collaborator

This will automatically close the repository that we created at the end of the build and based on a Gradle property or a parameter in the DSL also release it automatically. I think we don't need an option to control the automatic closing, each build will create a new repository anyways so there shouldn't be anything added after the fact. If there is a valid use case for it we can still make it optional later. Releasing on the other hand is a bigger step so I decided to make it opt-in. Even if you want to use it it allows for something like only enabling it on CI by setting an env var.

The closing and releasing is not done through the closeAndReleaseRepository task. The issue with the task is that it would need to wait for publishing in all other subprojects to finish so we would need cross project dependencies. One solution would have been the root plugin that we had before which would at least simplify it to only the root project task having to wait for all projects to finish publishing, but I also had some other issues that plugin. The solution is to trigger this from the build service. When a build service implements AutoCloseable Gradle will call close when the build service is no longer needed. Implementing OperationCompletionListener and registering it will make it so that we can detect that no task failed (in that case close and release is not run) and will make it so that the build service is needed for the whole build which means that close is only called after the last task finished. The close implementation then checks if a staging repo was created and then does the close and release operations.

I'm not 100% sure yet about the future of the close and release task. For now I made a small change to the nexus code so that running it on an already close repo will simply release it instead of printing an error that it is not open. So it can be used to then release it manually if automatic releasing isn't enabled. It could also be used to manually retry closing and releasing the already created staging repo if it failed. So it probably continue existing. One future change could be making the --release cli parameter required though and removing automatically finding a repo. The build will print the id of the repo when creating and automatically closing it, so you always know it.

if (stagingRepositoryId != null) {
nexus.closeStagingRepository(stagingRepositoryId)
if (parameters.automaticRelease.get()) {
nexus.releaseStagingRepository(stagingRepositoryId)
Copy link
Owner

Choose a reason for hiding this comment

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

Isn't this a change from what we had before when executing closeAndReleaseRepository. With 0.21.0 it always does close and release. And now when upgrading to this version it only does close. Why don't we auto release by default?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is how it compares:

Running publish:
0.21.0: implictly createst staging repo, uploads
now - flag off (default): creates staging repo, uploads, closes it
now - flag on: creates staging repo, uploads, closes it, releases it

Running closeAndReleaseRepository when repo is open
0.21.0: finds repo, if there is just one closes and releases it
now: finds repo, if there is just one closes and releases it

Running closeAndReleaseRepository when repo is closed
0.21.0: finds repo, fails
now: finds repo, if there is just one releases it

So closeAndReleaseRepository generally behaves like before and if you had publish and closeAndReleaseRepository running on ci (or you were manually executing them) the end result is the same. The automatic release flag gives you the option to let publish also release it so that you don't need to run closeAndReleaseRepository at all. I thought making the automatic release opt in is a bit safer as it's not something you can reverse.

Copy link
Owner

Choose a reason for hiding this comment

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

Aaah okay. Now i understand it, thanks!

@gabrielittner gabrielittner merged commit c143338 into master Sep 4, 2022
@gabrielittner gabrielittner deleted the automatic-close branch September 4, 2022 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants