Skip to content

Commit

Permalink
Fix version validation for nightlies
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cipolleschi authored and facebook-github-bot committed Nov 25, 2022
1 parent 8b8f4f3 commit a672869
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
33 changes: 21 additions & 12 deletions scripts/__tests__/version-utils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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();
});
});

Expand Down
10 changes: 3 additions & 7 deletions scripts/version-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
) {
Expand All @@ -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`);
}
}
Expand Down

0 comments on commit a672869

Please sign in to comment.