Skip to content

Commit

Permalink
[LOCAL] Fix handling of GITHUB_REF_NAME
Browse files Browse the repository at this point in the history
  • Loading branch information
cortinico committed Jun 19, 2024
1 parent 5f11ed9 commit 609c7c0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
1 change: 0 additions & 1 deletion scripts/__tests__/npm-utils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
21 changes: 14 additions & 7 deletions scripts/npm-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 609c7c0

Please sign in to comment.