fix(dev-infra): fix creating experimental semver versions to include prerelease chunk (#42917)

SemVers created for experimental versions should also include the prerelease chunk (i.e. -next.3).

PR Close #42917
This commit is contained in:
Joey Perrott 2021-07-21 16:36:52 -07:00 committed by Dylan Hunn
parent 69d4ebffa9
commit d2b1c3ec15
3 changed files with 19 additions and 3 deletions

View File

@ -6199,6 +6199,13 @@ function semverInc(version, release, identifier) {
const clone = new semver.SemVer(version.version);
return clone.inc(release, identifier);
}
/** Creates the equivalent experimental version for a provided SemVer. */
function createExperimentalSemver(version) {
const experimentalVersion = new semver.SemVer(version.format());
experimentalVersion.major = 0;
experimentalVersion.minor = version.major * 100 + version.minor;
return new semver.SemVer(experimentalVersion.format());
}
/**
* @license
@ -6843,7 +6850,7 @@ class ReleaseAction {
_verifyPackageVersions(version, packages) {
return tslib.__awaiter(this, void 0, void 0, function* () {
/** Experimental equivalent version for packages created with the provided version. */
const experimentalVersion = new semver.SemVer(`0.${version.major * 100 + version.minor}.${version.patch}`);
const experimentalVersion = createExperimentalSemver(version);
for (const pkg of packages) {
const { version: packageJsonVersion } = JSON.parse(yield fs.promises.readFile(path.join(pkg.outputPath, 'package.json'), 'utf8'));
const mismatchesVersion = version.compare(packageJsonVersion) !== 0;

View File

@ -18,6 +18,7 @@ import {BuiltPackage, ReleaseConfig} from '../config/index';
import {ReleaseNotes} from '../notes/release-notes';
import {NpmDistTag} from '../versioning';
import {ActiveReleaseTrains} from '../versioning/active-release-trains';
import {createExperimentalSemver} from '../versioning/inc-semver';
import {runNpmPublish} from '../versioning/npm-publish';
import {FatalReleaseActionError, UserAbortedReleaseActionError} from './actions-error';
@ -521,8 +522,8 @@ export abstract class ReleaseAction {
/** Verify the version of each generated package exact matches the specified version. */
private async _verifyPackageVersions(version: semver.SemVer, packages: BuiltPackage[]) {
/** Experimental equivalent version for packages created with the provided version. */
const experimentalVersion =
new semver.SemVer(`0.${version.major * 100 + version.minor}.${version.patch}`);
const experimentalVersion = createExperimentalSemver(version);
for (const pkg of packages) {
const {version: packageJsonVersion} =
JSON.parse(await fs.readFile(join(pkg.outputPath, 'package.json'), 'utf8')) as

View File

@ -17,3 +17,11 @@ export function semverInc(
const clone = new semver.SemVer(version.version);
return clone.inc(release, identifier);
}
/** Creates the equivalent experimental version for a provided SemVer. */
export function createExperimentalSemver(version: semver.SemVer): semver.SemVer {
const experimentalVersion = new semver.SemVer(version.format());
experimentalVersion.major = 0;
experimentalVersion.minor = version.major * 100 + version.minor;
return new semver.SemVer(experimentalVersion.format());
}