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

[CY-5396] git hash may violate semver #53

Open
trykyn opened this issue Dec 30, 2021 · 6 comments
Open

[CY-5396] git hash may violate semver #53

trykyn opened this issue Dec 30, 2021 · 6 comments
Labels
jira-issue Issue tracked on JIRA

Comments

@trykyn
Copy link

trykyn commented Dec 30, 2021

The git hash in the output can be all numeric in which case it violates semver

Example violation:
1.0.1-featurebranchname.0.0148718

While the probability is high that the git hash isn't all numeric but rather alphanumeric, the chance does exist and brakes with futher tools down the road (e.g. helm)

https://github.com/semver/semver/blob/master/semver.md

A pre-release version MAY be denoted by appending a hyphen and a series of dot separated identifiers immediately following the patch version. Identifiers MUST comprise only ASCII alphanumerics and hyphens [0-9A-Za-z-]. Identifiers MUST NOT be empty. Numeric identifiers MUST NOT include leading zeroes. Pre-release versions have a lower precedence than the associated normal version. A pre-release version indicates that the version is unstable and might not satisfy the intended compatibility requirements as denoted by its associated normal version. Examples: 1.0.0-alpha, 1.0.0-alpha.1, 1.0.0-0.3.7, 1.0.0-x.7.z.92, 1.0.0-x-y-z.--.

@github-actions github-actions bot changed the title git hash may violate semver [CY-5396] git hash may violate semver Dec 30, 2021
@github-actions github-actions bot added the jira-issue Issue tracked on JIRA label Dec 30, 2021
@github-actions
Copy link

Internal ticket created : CY-5396

@jsmith-kno2
Copy link

I just encountered this problem myself. I believe replacing the use of . with - in the prerelease content would resolve this issue. Perhaps making this a configuration option to override the character used for the prerelease delimiter would be an easy, backwards compatible solution.

Here's the example I encountered where the generated version was rejected by npm as an invalid semver:

npm version 2023.10.1-rc.3.0112925 --no-git-tag-version
npm ERR! npm version [<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease [--preid=<prerelease-id>] | from-git]
npm ERR! (run in package dir)
npm ERR! 'npm -v' or 'npm --version' to print npm version (6.1[4](https://github.com/Kno2/kno2fy-web/actions/runs/6550380252/job/17789527742#step:5:4).[12](https://github.com/Kno2/kno2fy-web/actions/runs/6550380252/job/17789527742#step:5:13))
npm ERR! 'npm view <pkg> version' to view a package's published version
npm ERR! 'npm ls' to inspect current package/dependency versions
Error: Process completed with exit code 1.

@ThijsBorst
Copy link

I have this problem with Helm. Can we fix this?

Error: Version segment starts with 0

@jsmith-kno2
Copy link

In case this is helpful to anyone else, the following bash commands will reformat the pre-release tag to use - in lieu of . as a workaround until this can be solved in a more first class way:

pre_release_tag=$(echo ${{ steps.version.outputs.version }} | awk -F'-' '{for (i=2; i<=NF; i++) printf $i"-"}' | sed 's/-$//')
new_pre_release_tag=$(echo $pre_release_tag | sed 's/\./-/g')
valid_semver_version=$(echo ${{ steps.version.outputs.version }} | sed "s/$pre_release_tag/$new_pre_release_tag/")

@ThijsBorst
Copy link

In case this is helpful to anyone else, the following bash commands will reformat the pre-release tag to use - in lieu of . as a workaround until this can be solved in a more first class way:

pre_release_tag=$(echo ${{ steps.version.outputs.version }} | awk -F'-' '{for (i=2; i<=NF; i++) printf $i"-"}' | sed 's/-$//')
new_pre_release_tag=$(echo $pre_release_tag | sed 's/\./-/g')
valid_semver_version=$(echo ${{ steps.version.outputs.version }} | sed "s/$pre_release_tag/$new_pre_release_tag/")

Can verify this workaround works! Thanks @jsmith-kno2 !

@jsmith-kno2
Copy link

jsmith-kno2 commented Apr 30, 2024

Any updates from the devs on this issue? The solution I offered earlier is a workaround but a pretty ugly one at that. Would be great if we could make the delimiter configurable to avoid this problem all together.

In lieu of that, approving #83 would be extremely helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
jira-issue Issue tracked on JIRA
Projects
None yet
Development

No branches or pull requests

3 participants