Fixing goreleaser error: failed to publish artifacts .. already_exists
TL;DR: If you have the same issue as I did, then you are not restricting the goreleaser
action to tags, and you trigger the same release from the main
branch and the git tag.
Today I tried to release a new version of godu
and the release action failed 💥.
⨯ release failed after 2m18s
error=scm releases: failed to publish artifacts:
failed to upload godu_1.4.0_Linux_arm64.tar.gz after 1 tries:
POST https://uploads.github.com/repos/viktomas/godu/releases/83296480/assets?name=godu_1.4.0_Linux_arm64.tar.gz:
422 Validation Failed [{Resource:ReleaseAsset Field:name Code:already_exists Message:}]
After some searching, I found this GitHub issue [Bug]: publishing multiple artifacts broken, which explained the problem.
In my release action, I don’t restrict where the action is run (tags, branches, PRs). I do that on purpose. I’m taking advantage of the following goreleaser
behaviour:
- When you trigger release action on a commit without a tag,
goreleaser
runs in a snapshot mode. It still validates that the release action works but it doesn’t publish the release.
The goreleaser GitHub action recommends to run it only on tags:
on:
push:
tags:
- '*'
But that way, I would lose the release verification on non-tag builds.
I caused the issue by pushing both the tag and the main
branch at the same time, triggering two identical release actions.
My solution is pragmatic: first push the main
branch, wait for the green build and then push the tag.