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

Not able to retrieve pre-existing tag version made before setting up semantic-release #2407

Open
Badisi opened this issue Apr 2, 2022 · 5 comments

Comments

@Badisi
Copy link

Badisi commented Apr 2, 2022

Current behavior

When using semantic-release for the first time on a project with existing git tags, those are not found and as a result the next version is not computed correctly.


Issue

Let's say we have an existing git with nothing but some pre-release tags.

master  beta
  |      |
  |     (x) v1.0.0-beta.3
  |      |
  |     (x) v1.0.0-beta.2
  |     ...

According to the documentation:

If a release has been published before setting up semantic-release you must make sure the most recent commit included in the last published release is in the release branches history and is tagged with the version released

But even with this, SR will compute the next version as : v1.0.0-beta.1 (instead of v1.0.0-beta.4).

Explanation

Looking at the code, there should be also a git note attached to each tag for this to work.

When no notes are found, channels will equals to [null] and as such no git tag version will be found at all on the branch.
get-tags.js#L22
get-last-release.js#L33

Solution

Update the documentation

A pull request for clarifying the documentation was made but yet to be approved (#2240).

Fix the issue

I'm not too familiar with this library's code but I think one of these two could solve the issue :

  1. channels in get-tags.js#L22 might be replaced by:

    const channels = (await getNote(tag, { cwd, env })).channels;
    if (!channels && branch.prelease === true) {
      channels = [branch.name];
    } else if (!channels && branch.prelease) {
      channels = [branch.prelease];
    } else {
      channels = [null];
    }
  2. channels could be normalized later in normalize.js.

What do you guys think ?

Environment

  • semantic-release version: 19.0.2
  • CI environment: local dry-run
  • Plugins used: none- default
  • semantic-release configuration: none - default
@aleclarson
Copy link

Is there a workaround for this? Perhaps by adding the git note manually?

@Badisi
Copy link
Author

Badisi commented Sep 6, 2022

Yes, to temporarily work around this you can add notes manually:

(see the doc here)

# example
git notes --ref semantic-release add -f -m '{"channels":["beta"]}' v2.0.0-beta.1
git push --force origin refs/notes/semantic-release

@aleclarson
Copy link

aleclarson commented Sep 6, 2022

Thanks @Badisi

Looks like there also needs to exist some tagged commits of a specific format

  • Using interactive rebase, edit the commit of the last version you manually published
  • Then for each package in your monorepo, do the following:
    git commit -m @foo/bar@1.0.0 --allow-empty
    git tag @foo/bar@1.0.0 head
  • Once finished, do git rebase --continue and run semantic-release --dry-run to verify it worked.

@aleclarson
Copy link

@Badisi
Copy link
Author

Badisi commented Sep 6, 2022

@aleclarson, this is exactly the documentation I was referring to in the description of this issue.

This doc is incomplete as SR will also look for a git note (see the Explanation).

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

No branches or pull requests

2 participants