From a67286913cd5f1697372ee86dadf5d717135abd8 Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Fri, 25 Nov 2022 13:46:45 -0800 Subject: [PATCH] Fix version validation for nightlies Summary: The nightly version is bumped after the check is performed, therefore it fails. With this diff, we become slightly more accepting with nightlies, allowing both `0.0.0` and `0.0.0-xxxx` as valid version for nightlies. ## Changelog [JS][Fixed] - Accept 0.0.0 with and without prelrelease for nightlies' versions Reviewed By: cortinico Differential Revision: D41534995 fbshipit-source-id: 2d0417441ca7d3d3f7660c9317133ac3c6de2eb9 --- scripts/__tests__/version-utils-test.js | 33 ++++++++++++++++--------- scripts/version-utils.js | 10 +++----- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/scripts/__tests__/version-utils-test.js b/scripts/__tests__/version-utils-test.js index 0dd087e20b..da5b67402a 100644 --- a/scripts/__tests__/version-utils-test.js +++ b/scripts/__tests__/version-utils-test.js @@ -171,14 +171,19 @@ describe('version-utils', () => { expect(prerelease).toBeUndefined(); }); - it('should reject nightly with no prerelease', () => { + it('should parse nightly with no prerelease', () => { // this should fail - function testInvalidFunction() { - parseVersion('0.0.0', 'nightly'); - } - expect(testInvalidFunction).toThrowErrorMatchingInlineSnapshot( - `"Version 0.0.0 is not valid for nightlies"`, + + const {version, major, minor, patch, prerelease} = parseVersion( + '0.0.0', + 'nightly', ); + + expect(version).toBe('0.0.0'); + expect(major).toBe('0'); + expect(minor).toBe('0'); + expect(patch).toBe('0'); + expect(prerelease).toBeUndefined(); }); it('should reject nightly with prerelease but wrong version numbers', () => { @@ -308,13 +313,17 @@ describe('version-utils', () => { ); }); - it('should reject dryrun for nightlies with invalid prerelease', () => { - function testInvalidFunction() { - parseVersion('0.0.0', 'dry-run'); - } - expect(testInvalidFunction).toThrowErrorMatchingInlineSnapshot( - `"Version 0.0.0 is not valid for dry-runs"`, + it('should parse dryrun for nightlies with no prerelease', () => { + const {version, major, minor, patch, prerelease} = parseVersion( + '0.0.0', + 'dry-run', ); + + expect(version).toBe('0.0.0'); + expect(major).toBe('0'); + expect(minor).toBe('0'); + expect(patch).toBe('0'); + expect(prerelease).toBeUndefined(); }); }); diff --git a/scripts/version-utils.js b/scripts/version-utils.js index e73ea62ed4..f482e1cc70 100644 --- a/scripts/version-utils.js +++ b/scripts/version-utils.js @@ -18,7 +18,7 @@ const VERSION_REGEX = /^v?((\d+)\.(\d+)\.(\d+)(?:-(.+))?)$/; * Some examples of valid versions are: * - stable: 0.68.1 * - stable prerelease: 0.70.0-rc.0 - * - nightly: 0.0.0-20221116-2018-0bc4547fc + * - nightly: 0.0.0-20221116-2018-0bc4547fc | 0.0.0 * - dryrun: 1000.0.0 * * Parameters: @@ -95,11 +95,9 @@ function validateRelease(version) { } function validateDryRun(version) { - const isNightly = isNightlyBuild(version) && version.prerelease != null; - if ( !isMain(version) && - !isNightly && + !isNightlyBuild(version) && !isStableRelease(version) && !isStablePrerelease(version) ) { @@ -109,9 +107,7 @@ function validateDryRun(version) { function validateNightly(version) { // a valid nightly is a prerelease - const isPrerelease = version.prerelease != null; - const isValidNightly = isNightlyBuild(version) && isPrerelease; - if (!isValidNightly) { + if (!isNightlyBuild(version)) { throw new Error(`Version ${version.version} is not valid for nightlies`); } }