Skip to content

Commit c42bfe8

Browse files
cipolleschiOlimpiaZurek
authored andcommitted
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
1 parent efd8987 commit c42bfe8

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

scripts/__tests__/version-utils-test.js

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,19 @@ describe('version-utils', () => {
171171
expect(prerelease).toBeUndefined();
172172
});
173173

174-
it('should reject nightly with no prerelease', () => {
174+
it('should parse nightly with no prerelease', () => {
175175
// this should fail
176-
function testInvalidFunction() {
177-
parseVersion('0.0.0', 'nightly');
178-
}
179-
expect(testInvalidFunction).toThrowErrorMatchingInlineSnapshot(
180-
`"Version 0.0.0 is not valid for nightlies"`,
176+
177+
const {version, major, minor, patch, prerelease} = parseVersion(
178+
'0.0.0',
179+
'nightly',
181180
);
181+
182+
expect(version).toBe('0.0.0');
183+
expect(major).toBe('0');
184+
expect(minor).toBe('0');
185+
expect(patch).toBe('0');
186+
expect(prerelease).toBeUndefined();
182187
});
183188

184189
it('should reject nightly with prerelease but wrong version numbers', () => {
@@ -308,13 +313,17 @@ describe('version-utils', () => {
308313
);
309314
});
310315

311-
it('should reject dryrun for nightlies with invalid prerelease', () => {
312-
function testInvalidFunction() {
313-
parseVersion('0.0.0', 'dry-run');
314-
}
315-
expect(testInvalidFunction).toThrowErrorMatchingInlineSnapshot(
316-
`"Version 0.0.0 is not valid for dry-runs"`,
316+
it('should parse dryrun for nightlies with no prerelease', () => {
317+
const {version, major, minor, patch, prerelease} = parseVersion(
318+
'0.0.0',
319+
'dry-run',
317320
);
321+
322+
expect(version).toBe('0.0.0');
323+
expect(major).toBe('0');
324+
expect(minor).toBe('0');
325+
expect(patch).toBe('0');
326+
expect(prerelease).toBeUndefined();
318327
});
319328
});
320329

scripts/version-utils.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const VERSION_REGEX = /^v?((\d+)\.(\d+)\.(\d+)(?:-(.+))?)$/;
1818
* Some examples of valid versions are:
1919
* - stable: 0.68.1
2020
* - stable prerelease: 0.70.0-rc.0
21-
* - nightly: 0.0.0-20221116-2018-0bc4547fc
21+
* - nightly: 0.0.0-20221116-2018-0bc4547fc | 0.0.0
2222
* - dryrun: 1000.0.0
2323
*
2424
* Parameters:
@@ -95,11 +95,9 @@ function validateRelease(version) {
9595
}
9696

9797
function validateDryRun(version) {
98-
const isNightly = isNightlyBuild(version) && version.prerelease != null;
99-
10098
if (
10199
!isMain(version) &&
102-
!isNightly &&
100+
!isNightlyBuild(version) &&
103101
!isStableRelease(version) &&
104102
!isStablePrerelease(version)
105103
) {
@@ -109,9 +107,7 @@ function validateDryRun(version) {
109107

110108
function validateNightly(version) {
111109
// a valid nightly is a prerelease
112-
const isPrerelease = version.prerelease != null;
113-
const isValidNightly = isNightlyBuild(version) && isPrerelease;
114-
if (!isValidNightly) {
110+
if (!isNightlyBuild(version)) {
115111
throw new Error(`Version ${version.version} is not valid for nightlies`);
116112
}
117113
}

0 commit comments

Comments
 (0)