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
This commit is contained in:
Riccardo Cipolleschi 2022-11-25 13:46:45 -08:00 коммит произвёл Facebook GitHub Bot
Родитель 8b8f4f3efd
Коммит a67286913c
2 изменённых файлов: 24 добавлений и 19 удалений

Просмотреть файл

@ -171,14 +171,19 @@ describe('version-utils', () => {
expect(prerelease).toBeUndefined(); expect(prerelease).toBeUndefined();
}); });
it('should reject nightly with no prerelease', () => { it('should parse nightly with no prerelease', () => {
// this should fail // this should fail
function testInvalidFunction() {
parseVersion('0.0.0', 'nightly'); const {version, major, minor, patch, prerelease} = parseVersion(
} '0.0.0',
expect(testInvalidFunction).toThrowErrorMatchingInlineSnapshot( 'nightly',
`"Version 0.0.0 is not valid for nightlies"`,
); );
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', () => { 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', () => { it('should parse dryrun for nightlies with no prerelease', () => {
function testInvalidFunction() { const {version, major, minor, patch, prerelease} = parseVersion(
parseVersion('0.0.0', 'dry-run'); '0.0.0',
} 'dry-run',
expect(testInvalidFunction).toThrowErrorMatchingInlineSnapshot(
`"Version 0.0.0 is not valid for dry-runs"`,
); );
expect(version).toBe('0.0.0');
expect(major).toBe('0');
expect(minor).toBe('0');
expect(patch).toBe('0');
expect(prerelease).toBeUndefined();
}); });
}); });

Просмотреть файл

@ -18,7 +18,7 @@ const VERSION_REGEX = /^v?((\d+)\.(\d+)\.(\d+)(?:-(.+))?)$/;
* Some examples of valid versions are: * Some examples of valid versions are:
* - stable: 0.68.1 * - stable: 0.68.1
* - stable prerelease: 0.70.0-rc.0 * - 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 * - dryrun: 1000.0.0
* *
* Parameters: * Parameters:
@ -95,11 +95,9 @@ function validateRelease(version) {
} }
function validateDryRun(version) { function validateDryRun(version) {
const isNightly = isNightlyBuild(version) && version.prerelease != null;
if ( if (
!isMain(version) && !isMain(version) &&
!isNightly && !isNightlyBuild(version) &&
!isStableRelease(version) && !isStableRelease(version) &&
!isStablePrerelease(version) !isStablePrerelease(version)
) { ) {
@ -109,9 +107,7 @@ function validateDryRun(version) {
function validateNightly(version) { function validateNightly(version) {
// a valid nightly is a prerelease // a valid nightly is a prerelease
const isPrerelease = version.prerelease != null; if (!isNightlyBuild(version)) {
const isValidNightly = isNightlyBuild(version) && isPrerelease;
if (!isValidNightly) {
throw new Error(`Version ${version.version} is not valid for nightlies`); throw new Error(`Version ${version.version} is not valid for nightlies`);
} }
} }