How to force a version in semantic release
Asked Answered
B

2

6

I have a npm package that I need to release in npmjs.com but because I unpublished a previously wrong version now npmjs doesn't allow me to re-publish an artefact with the same version (it throws an error saying You cannot publish over the previously published versions)

In my project I use semantic-release which automatically calculates the version to give to an artefact based on the commits from the last published version.

Therefore I am wondering if there is a way to overwrite or force semantic-release to give a different version than the one it calculates, for example typing it in when running its command in CI

Broken answered 20/12, 2019 at 17:33 Comment(0)
H
17

semantic-release uses tags to determine the last version and the new commits added since then. In order to skip the version that was unpublished from npm you can add a Git tag that correspond to that version on the commit associated with the latest version published.

git tag v<latest-version-published> v<version-to-skip> git push --tags origin

Then re-run your CI job that failed so semantic-release can run again, pick up the new tag and increment the version from there.

Hodgkinson answered 21/12, 2019 at 5:44 Comment(3)
the code above is used to rename an existing tag. syntax: git tag newName oldNameWhippersnapper
this will cause the error tag v<latest-version-published> already existsWhippersnapper
creating an artificial tag just to trigger the semantic release versioning actually worked. Thanks a lot.Langsdon
K
3

To solve a similar problem I run from my laptop the follow commands:

git tag v5.2.0                                       # I create a new tag based on the latest master. Can be even a minor update/major
git notes --ref semantic-release add -f -m '{"channels":["null"]}' v5.2.0  # I add the notes
git push origin  refs/tags/v5.2.0                    # I push the tag to the origin
git push --force origin  refs/notes/semantic-release # I force a note update. This was needed even if I didn't do any rebase

For some reason deleting the tag and trying to recreate it with the notes doesn't work but with the above procedure the next semantic-release runs find my tag and skip it.

Kaluga answered 8/11, 2023 at 16:33 Comment(1)
This actually helped me and I could also verify it in the semantic-release documentation semantic-release.gitbook.io/semantic-release/support/…Spadework

© 2022 - 2024 — McMap. All rights reserved.