Skip to content

CI npm template: Fix comparison of pre-release versions

What does this MR do and why?

Change the comparison of npm versions output (escaping) to fix pre-release versions comparisons. Our pre-release versions were not published and sh complained about unknown operands (version number)

Screenshots or screen recordings

Before (with extra echo of npm view "${NPM_PACKAGE_NAME}" versions):

$ echo $NPM_PACKAGE_VERSION
1.1.0-update-to-node16.69613.SHA-dba77c7c.1
$ if [[ ! $NPM_PACKAGE_NAME =~ ^@$CI_PROJECT_ROOT_NAMESPACE/ ]]; then # collapsed multi-line command
$ if [[ $(npm view "${NPM_PACKAGE_NAME}" versions) != *"'${NPM_PACKAGE_VERSION}'"* ]]; then # collapsed multi-line command
sh: '1.0.1',: unknown operand
Version 1.1.0-update-to-node16.69613.SHA-dba77c7c.1 of @baXXXXXe/eXXXXXd has already been published, so no new version has been published.
[
  '1.0.1',
  '1.0.2',
  '1.0.3',
  '1.1.0-update-to-node16.69575.SHA-796b697e.1'
]

After:

$ echo $NPM_PACKAGE_VERSION
1.1.0-update-to-node16.69736.SHA-571b8186.1
$ if [[ ! $NPM_PACKAGE_NAME =~ ^@$CI_PROJECT_ROOT_NAMESPACE/ ]]; then # collapsed multi-line command
$ NPM_REGISTRY_VERSIONS=$(npm view "${NPM_PACKAGE_NAME}" versions) # collapsed multi-line command
[ '1.0.1', '1.0.2', '1.0.3', '1.1.0-update-to-node16.69575.SHA-796b697e.1', '1.1.0-update-to-node16.69727.SHA-a993a409.1', '1.1.0-update-to-node16.69734.SHA-fa9ade89.1' ]
npm notice 
npm notice package: @baXXXXXe/eXXXXXd@1.1.0-update-to-node16.69736.SHA-571b8186.1
npm notice === Tarball Contents === 
....publishing of npm package to GitLab registry....

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Merge request reports

Loading