From 609c7c05b13214f2a834b251de095243f8dcbf68 Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Wed, 19 Jun 2024 10:53:18 +0100 Subject: [PATCH] [LOCAL] Fix handling of GITHUB_REF_NAME --- scripts/__tests__/npm-utils-test.js | 1 - scripts/npm-utils.js | 21 ++++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/scripts/__tests__/npm-utils-test.js b/scripts/__tests__/npm-utils-test.js index 71f796a6792622..a804a968409eb5 100644 --- a/scripts/__tests__/npm-utils-test.js +++ b/scripts/__tests__/npm-utils-test.js @@ -175,7 +175,6 @@ describe('npm-utils', () => { process.env.GITHUB_REF = null; process.env.GITHUB_REF_NAME = null; }); -}); describe('getVersionsBySpec', () => { it('should return array when single version returned', () => { diff --git a/scripts/npm-utils.js b/scripts/npm-utils.js index 7f694428b3dbc6..b7f16ae8a1bd7f 100644 --- a/scripts/npm-utils.js +++ b/scripts/npm-utils.js @@ -89,18 +89,25 @@ function getNpmInfo(buildType /*: BuildType */) /*: NpmInfo */ { } if (buildType === 'release') { - // GITHUB_REF contains the fully qualified ref, for example refs/tags/v0.75.0-rc.0 - // GITHUB_REF_NAME contains the short name, for example v0.75.0-rc.0 - if (process.env.CIRCLE_TAG == null || process.env.GITHUB_REF == null || !process.env.GITHUB_REF.includes('/tags/') || process.env.GITHUB_REF_NAME == null) { - console.log('GITHUB_REF:', process.env.GITHUB_REF); - console.log('GITHUB_REF_NAME:', process.env.GITHUB_REF_NAME); + let versionTag /*: string*/ = ''; + if (process.env.CIRCLE_TAG != null) { + versionTag = process.env.CIRCLE_TAG; + } else if ( + process.env.GITHUB_REF != null && + process.env.GITHUB_REF.includes('/tags/') && + process.env.GITHUB_REF_NAME != null + ) { + // GITHUB_REF contains the fully qualified ref, for example refs/tags/v0.75.0-rc.0 + // GITHUB_REF_NAME contains the short name, for example v0.75.0-rc.0 + versionTag = process.env.GITHUB_REF_NAME; + } + + if (versionTag == '') { throw new Error( 'No version tag found in CI. It looks like this script is running in release mode, but the CIRCLE_TAG or the GITHUB_REF_NAME are missing.', ); } - const versionTag /*: string*/ = process.env.CIRCLE_TAG != null ? process.env.CIRCLE_TAG : process.env.GITHUB_REF_NAME; - const {version, major, minor, patch, prerelease} = parseVersion( versionTag, buildType,