Skip to content

Sort git tags with node-semver

Fabien Catteau requested to merge sort-git-tags-node-semver into master

What does this MR do?

Use https://github.com/npm/node-semver to sort git tags, because sort -V doesn't sort prereleases properly.

Right now gemnasium v3.0.0 can't be published, b/c v3.0.0-alpha0 is considered to be the latest version. See https://gitlab.com/gitlab-org/security-products/analyzers/gemnasium/-/jobs/2480315309#L138

Install nodejs and semver will slow down the job a bit.

What are the relevant issue numbers?

None

Testing

Tested manually using the docker:20.10 image:

% lima nerdctl run -ti --rm docker:20.10
/ # apk add --no-cache -q git nodejs npm
/ # npm install -g semver

added 3 packages, and audited 4 packages in 2s

found 0 vulnerabilities
/ # cd tmp/
/tmp # git clone https://gitlab.com/gitlab-org/security-products/analyzers/gemnasium.git
Cloning into 'gemnasium'...
remote: Enumerating objects: 8784, done.
remote: Counting objects: 100% (1089/1089), done.
remote: Compressing objects: 100% (395/395), done.
remote: Total 8784 (delta 721), reused 946 (delta 634), pack-reused 7695
Receiving objects: 100% (8784/8784), 24.47 MiB | 2.23 MiB/s, done.
Resolving deltas: 100% (4598/4598), done.
/tmp # cd gemnasium/
/tmp/gemnasium # CHANGELOG_MAJOR_VERSION=$(grep -m 1 '^## v' CHANGELOG.md | sed -n "s/^## v\(\d\+\)\..*$/\1/p")
/tmp/gemnasium # echo $CHANGELOG_MAJOR_VERSION
2
/tmp/gemnasium # CI_COMMIT_TAG=$(semver $(git tag -l|grep -e v$CHANGELOG_MAJOR_VERSION'\.\d\+\.\d\+')|tail -n 1)
/tmp/gemnasium # echo $CI_COMMIT_TAG
2.38.0
/tmp/gemnasium # CHANGELOG_MAJOR_VERSION=3
/tmp/gemnasium # CI_COMMIT_TAG=$(semver $(git tag -l|grep -e v$CHANGELOG_MAJOR_VERSION'\.\d\+\.\d\+')|tail -n 1)
/tmp/gemnasium # echo $CI_COMMIT_TAG
3.0.0
/tmp/gemnasium # CI_COMMIT_TAG=$(git tag -l|grep -e v$CHANGELOG_MAJOR_VERSION'\.\d\+\.\d\+'|sort -V -r|head -n 1)
/tmp/gemnasium # echo $CI_COMMIT_TAG
v3.0.0-alpha0
Edited by Adam Cohen

Merge request reports