allegro / axion-release-plugin

Gradle release & version management plugin.
https://axion-release-plugin.readthedocs.io/
Apache License 2.0
562 stars 155 forks source link

If release fails the new tag is deleted locally but left on the remote #551

Open sourcedelica opened 2 years ago

sourcedelica commented 2 years ago

Tested in version 1.14.2

If for some reason the release fails when pushing the tags (I say "tags" plural due to #224) the tag is deleted locally but left on the remote. For example:

$ git ls-remote origin refs/tags/v4.6.1

$ ./gradlew release -Prelease.disableChecks -Prelease.pushTagsOnly

> Task :verifyRelease
Skipping uncommitted changes check
Skipping ahead of remote check
Skipping snapshot dependencies check

> Task :release FAILED
Creating tag: v4.6.1
Pushing all to remote: origin
Removing tag: v4.6.1
Tag v4.6.1 removed
remote message:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':release'.
> pl.allegro.tech.build.axion.release.ReleaseFailedException (no error message)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

BUILD FAILED in 1s
2 actionable tasks: 2 executed

$ git tag -l v4.6.1   

$ git ls-remote origin refs/tags/v4.6.1
7558fe477fe48ba7fa20ddf7fadbffd30e1bc4f9        refs/tags/v4.6.1

# Hmm, need to delete that so the next release works
$ git push origin --delete v4.6.1
To https://gitlab.tradeweb.com/erictest/foopy.git
 - [deleted]         v4.6.1

Note also there is no indication as to what the problem is. You just get a generic error message. Even if you run with --debug or --stacktrace you can't figure out what the problem is. Now that I know about #224 I can emulate the problem by running git push --tags:

$ git push --tags
To https://gitlab.tradeweb.com/erictest/foopy.git
 ! [rejected]        v4.4.0 -> v4.4.0 (already exists)
error: failed to push some refs to 'https://gitlab.tradeweb.com/erictest/foopy.git'
hint: Updates were rejected because the tag already exists in the remote.

# Ok, the v4.4.0 tag is bad on the remote, let's delete it and re-release

$ git push origin --delete v4.4.0
To https://gitlab.tradeweb.com/erictest/foopy.git
 - [deleted]         v4.4.0

$ ./gradlew release -Prelease.disableChecks -Prelease.pushTagsOnly

> Task :verifyRelease
Skipping uncommitted changes check
Skipping ahead of remote check
Skipping snapshot dependencies check

> Task :release
Creating tag: v4.6.1
Pushing all to remote: origin

BUILD SUCCESSFUL in 956ms
2 actionable tasks: 2 executed

# Hooray!
bgalek commented 1 year ago

Hi @sourcedelica this is a bit tricky! After a tag was pushed to remote there is no easy way going back! (i.e. pipeline watching on new tag event was already started) I really don't have any idea what to do instead.