semantic-release: Incorrect (duplicate) prerelease version determined even when git notes exist
I’m using GitHub Flow/Trunk Based Development thanks to semantic-release, and it’s great! I’m going to move all my packages over to a semantic-release CI/CD trunk-based flow, but most of them already have manually published releases. So, to create a uniform repo configuration for my packages, I’ve been playing with a dummy GitHub Actions/semantic-release repo. I tagged and manually released some initial commits to main to simulate switching a project with preexisting tags and releases over to semantic-release. I made several more commits to main and several successful semantic releases. Next, I configured a prerelease branch canary (channel is also canary) off main and pushed a breaking change. semantic-release published the prerelease no problem: v3.0.0-canary.1.
Current behavior
However, I made some more changes, I pushed them, I expected release v3.0.0-canary.2, but instead I got an error:

So… it’s trying to re-publish the same prerelease version, v3.0.0-canary.1? A quick scan of the issues shows problems similar to mine, perhaps related. The troubleshooting docs also talk about force pushing and git notes.
Some facts about my issue:
v3.0.0-canary.1is in the git history ofcanary:

- The proper git notes exist for all releases made by semantic release; there were no force pushes or anything like that. 3d91d82 is the note with
{"channels":[null]}while 6cae4d5 is the note with{"channels":['canary']}:


- It’s as if
semantic-releasedoesn’t “see” thev3.0.0-canary.1release it just made, instead finding the oldv2.3.4release:

And the 2d branch graph:

This same problem happens with GitHub Actions runners as well as my local machine when running npx semantic-release -d. I ended up spelunking down into the code similar to #1685 to see what was going on. It turns out that the problem may be git itself, or (perhaps more likely) the assumptions about how git notes show handles references. Specifically this line. It seems commands like git notes --ref semantic-release show v2.1.0 do not work (or at least don’t seem to). However, when using the commit hash instead of the tag name, i.e. git notes --ref semantic-release show 1eeba8e, everything works:

After forking semantic-release, adding a line that replaces the tag ref with the hash of the commit its pointing to, and replacing semantic-release with Xunnamius/semantic-release in my package.json, pushes to my prerelease branch are now released properly.
Expected behavior
v3.0.0-canary.1 is found as the previous release tag with branch canary and channel canary. The next release should then be v3.0.0-canary.2.
Environment
- semantic-release version: 17.3.0
- Environments: breaks in both environments: (1) GitHub Actions Ubuntu CI and (2) local dry-run dev environment (ubuntu 20.04.1, node 14.15.1, git 2.29.2)
- Plugins used:
@semantic-release/commit-analyzer@semantic-release/release-notes-generator@semantic-release/exec@semantic-release/changelog@semantic-release/npm@semantic-release/git@semantic-release/github - semantic-release configuration
- CI logs (broken using 17.3.0) vs CI logs (working using Xunnamius/semantic-release)
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 8
- Comments: 15 (3 by maintainers)
I’ve got this issue on some of my repos.
How to get it not work :
Branch architecture :
Step to reproduce :
Push something from a dev branch into
beta:That will create a release
v1.0.0-beta.1so everything is OkMerge
betaintorcThat will create a release
v1.0.0-rc.1on the exact same commit of thebetarelease. So the notes will be shared.Push something new on
beta.That will try to make a
v1.0.0-beta.1tag instead ofv1.0.0-beta.2and CI will fail because of tag already exist.I think the tag note must be :
But even in editing the note like this didn’t unlock the CI and
semantic-releasestill fail because of tag already exist.If someone got a workaround to unlock CI when we got this case, it can help me a lot.
Also, I’ve some trouble to understand why
semantic-releaseuse notes. I think it can parse tags to get the info contained in notes. Maybe it’s just to know the order of the release on the same tags ?Can someone explain to me ?
Update:
So I attempted to create a MRE here on my local machine, but I couldn’t initially reproduce the issue. Even when deploying directly from my development environment, it still worked. Issuing the raw command that failed in the other repo succeeded in the MRE repo:
Huh. In the old repo, I kept getting errors like:
Which was very strange to me because
git log show 4dbe4cb6c81c408cf34869aa295c52d91eb37940just output commitd13f38f6aedd05840e438f62ff2092218a806984 (tag: v3.0.0-canary.1). Turns out that4dbe4object is the actualv3.0.0-canary.1annotated tag object (and I learned something new about git 😁).semantic-releaseis using annotated tags in the first repo and lightweight tags in the new MRE repo. So a command likegit notes --ref=semantic-release show v3.0.0-canary.1, wherev3.0.0-canary.1is an annotated tag, tries to get notes added to the tag object itself (4dbe4) and not the release commit thatsemantic-releaseactually added the notes to (and that tag4dbe4is pointing to), which is why using the actual commit hash instead of the tag name fixed it in #1709 🥳Unlike my local environment where I set up the MRE, I have my GitHub Actions pipeline setup so that all tags must be signed via
tag.gpgsign=true, which apparently forces tags to be annotated rather than lightweight. Early on, when I was first playing withsemantic-release, I was getting strange behavior wheresemantic-releasewould fail after trying to open the default editor in the middle of the publication pipeline. I “fixed” it by addingEDITOR='echo semantic-release-bot > $1'to the CI environment variables and thought nothing more of it, but now it makes sense why that was happening.To evidence the two repos using different tags types, I ran
git for-each-ref refs/tagson both:Original repo (workflow-playground):
Tag
v1.0.15was created on my local machine (to simulate there already being releases in the repo), which is why it’s lightweight. Tagv2.0.0was the first tag created by semantic-release and before I configured default tag signing, which is why it’s also lightweight. Afterv2.0.0, all tags are managed bysemantic-releaseand signed (and annotated).Attempted MRE:
All tags in this repo are lightweight (they point directly to commits).
And for the cherry on top: forcing
semantic-releaseto sign releasev2.0.0-canary.2(complete withEDITORpatch) and then pushing another release-triggering commit makes semantic-release attempt to re-releasev2.0.0-canary.2instead ofv2.0.0-canary.3, which is the buggy behavior described in the OP:If I’m understanding this right, as a consequence of this bug, it appears all notes are functionally ignored by
semantic-releasefor repositories using annotated tags. The only reasonsemantic-releaseappears to work at all with annotated tags is because of this line where note-related errors cause{"channels":[null]}(default release branch) to be returned by default.I also saw #1192 which makes me think
semantic-releaseshould already be creating annotated tags by default (but I could easily be wrong, as I’ve stumbled upon #1266). Could this be a regression? Or is the existence of tag signing/annotated tags not supported bysemantic-release? If they are supported, a more holistic fix might be to move the notes off the commits and onto annotated tags, whichsemantic-releasewould create instead by default (making myEDITORhack unnecessary), but that sounds like a massively breaking change. Instead, #1709, plus providing a message whenexeca-ing thegit tagcommand ifsemantic-releasedetects its about to create an annotated tag (or just populate theEDITORenvironment variable in viaexecaoptions) would be a similarly holistic fix but without it being a breaking change. If annotated tags aren’t supported, #1709 + the above would allow them to be supported out of the box, I think.Arguments for supporting annotated tags too, from git-scm and stackoverflow:
Hello, any update ?
Just want to second the appreciation for your thorough investigation here Bernard 👍🏼
https://github.com/semantic-release/semantic-release/pull/1709#issuecomment-2461410971
@Xunnamius ah, no this was a red herring/I was totally mistaken. My issue is with Git tags as of course rebasing clobbers the previous tags. I guess I had just gotten used to being able to rebase prerelease branches with Changesets since it uses files instead of tags.
Pls to ignore — 😬 — sorry y’all
i’ll look deeper into your details later, but would like to at least point out that annotated tag support was reverted, as mentioned in https://github.com/semantic-release/semantic-release/issues/1262.
thanks a lot for investigating so thoroughly.