Skip to content

Commit 6c63566

Browse files
committed
build: use new release prechecks for validating release before publish
Uses the new release precheck feature for validating release output and other inputs.
1 parent 2533dab commit 6c63566

File tree

4 files changed

+18
-66
lines changed

4 files changed

+18
-66
lines changed

.ng-dev/release.ts

Lines changed: 10 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,8 @@
1-
import {
2-
BuiltPackage,
3-
ReleaseConfig,
4-
ReleaseAction as _ReleaseAction,
5-
FatalReleaseActionError,
6-
} from '@angular/dev-infra-private/ng-dev';
71
import {SemVer} from 'semver';
2+
import {ReleaseConfig} from '@angular/dev-infra-private/ng-dev';
3+
import {assertValidFrameworkPeerDependency} from '../tools/release-checks/check-framework-peer-dependency';
4+
import {assertValidUpdateMigrationCollections} from '../tools/release-checks/check-migration-collections';
85
import {assertValidNpmPackageOutput} from '../tools/release-checks/npm-package-output';
9-
import {fork} from 'child_process';
10-
import {join} from 'path';
11-
12-
// The `ng-dev` release tool exposes the `ReleaseAction` instance through `global`,
13-
// allowing it to be monkey-patched for our release checks. This can be removed
14-
// when the release tool has a public API for release checks.
15-
const actionProto = ((global as any).ReleaseAction ?? _ReleaseAction).prototype;
16-
const _origStageFn = actionProto.stageVersionForBranchAndCreatePullRequest;
17-
const _origVerifyFn = actionProto._verifyPackageVersions;
18-
19-
/** Runs the staging sanity release checks for the given new version. */
20-
async function runStagingReleaseChecks(newVersion: SemVer) {
21-
return new Promise<void>((resolve, reject) => {
22-
// Note: We run the staging release checks in a new node process. This is necessary
23-
// because before staging, the correct publish branch is checked out. If we'd
24-
// directly call into the release checks, the `.ng-dev/release` config would be
25-
// cached by NodeJS and release checks would potentially check for packages which
26-
// no longer exist in the publish branch (or the other way around).
27-
const releaseChecksProcess = fork(join(__dirname, '../tools/release-checks/index.js'), [
28-
newVersion.format(),
29-
]);
30-
31-
releaseChecksProcess.on('close', code => {
32-
if (code !== 0) {
33-
reject(new FatalReleaseActionError());
34-
} else {
35-
resolve();
36-
}
37-
});
38-
});
39-
}
40-
41-
// Patches the `@angular/dev-infra-private` release tool to perform sanity checks
42-
// before staging a release. This is temporary until the dev-infra team has implemented
43-
// a more generic solution to running sanity checks before releasing (potentially building
44-
// some of the checks we have in the components repository into the release tool).
45-
actionProto.stageVersionForBranchAndCreatePullRequest = async function (newVersion: SemVer) {
46-
await runStagingReleaseChecks(newVersion);
47-
48-
return await _origStageFn.apply(this, arguments);
49-
};
50-
51-
// Patches the `@angular/dev-infra-private` release tool to perform sanity
52-
// checks of the NPM package output, before publishing to NPM.
53-
actionProto._verifyPackageVersions = async function (
54-
newVersion: SemVer,
55-
builtPackages: BuiltPackage[],
56-
) {
57-
await assertValidNpmPackageOutput(builtPackages, newVersion);
58-
59-
return await _origVerifyFn.apply(this, arguments);
60-
};
616

627
/**
638
* Packages that will be published as part of the project.
@@ -104,4 +49,11 @@ export const release: ReleaseConfig = {
10449
const {performNpmReleaseBuild} = await import('../scripts/build-packages-dist');
10550
return performNpmReleaseBuild();
10651
},
52+
prereleaseCheck: async (newVersionStr, builtPackagesWithInfo) => {
53+
const newVersion = new SemVer(newVersionStr);
54+
55+
await assertValidFrameworkPeerDependency(newVersion);
56+
await assertValidUpdateMigrationCollections(newVersion);
57+
await assertValidNpmPackageOutput(builtPackagesWithInfo, newVersion);
58+
},
10759
};

tools/release-checks/check-framework-peer-dependency.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {error, FatalReleaseActionError} from '@angular/dev-infra-private/ng-dev';
1+
import {error, ReleasePrecheckError} from '@angular/dev-infra-private/ng-dev';
22
import {SemVer} from 'semver';
33
import {join} from 'path';
44
import {existsSync, readFileSync} from 'fs';
@@ -34,7 +34,7 @@ export async function assertValidFrameworkPeerDependency(newVersion: SemVer) {
3434
),
3535
);
3636
error(chalk.red(` Please manually update the version range ` + `in: ${bzlConfigPath}`));
37-
throw new FatalReleaseActionError();
37+
throw new ReleasePrecheckError();
3838
}
3939
}
4040

@@ -50,7 +50,7 @@ function _extractAngularVersionPlaceholderOrThrow(): string {
5050
`the Angular peerDependency placeholder value. Looked for: ${bzlConfigPath}`,
5151
),
5252
);
53-
throw new FatalReleaseActionError();
53+
throw new ReleasePrecheckError();
5454
}
5555

5656
const configFileContent = readFileSync(bzlConfigPath, 'utf8');
@@ -63,7 +63,7 @@ function _extractAngularVersionPlaceholderOrThrow(): string {
6363
`Looked in: ${bzlConfigPath}`,
6464
),
6565
);
66-
throw new FatalReleaseActionError();
66+
throw new ReleasePrecheckError();
6767
}
6868
return matches[1];
6969
}

tools/release-checks/check-migration-collections.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {error} from '@angular/dev-infra-private/ng-dev';
1+
import {error, ReleasePrecheckError} from '@angular/dev-infra-private/ng-dev';
22
import chalk from 'chalk';
33
import {existsSync, readFileSync} from 'fs';
44
import {dirname, join} from 'path';
@@ -32,7 +32,7 @@ export async function assertValidUpdateMigrationCollections(newVersion: semver.S
3232
if (failures.length) {
3333
error(chalk.red(` ✘ Failures in ng-update migration collection detected:`));
3434
failures.forEach(f => error(f));
35-
process.exit(1);
35+
throw new ReleasePrecheckError();
3636
}
3737
}
3838

tools/release-checks/npm-package-output/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {SemVer} from 'semver';
22
import {checkReleasePackage} from './check-package';
3-
import {BuiltPackage, error} from '@angular/dev-infra-private/ng-dev';
3+
import {BuiltPackage, error, ReleasePrecheckError} from '@angular/dev-infra-private/ng-dev';
44
import chalk from 'chalk';
55

66
/** Asserts that the given built packages are valid for public consumption. */
@@ -16,6 +16,6 @@ export async function assertValidNpmPackageOutput(
1616

1717
if (!passing) {
1818
error(chalk.red(` ✘ NPM package output does not pass all release validations.`));
19-
process.exit(1);
19+
throw new ReleasePrecheckError();
2020
}
2121
}

0 commit comments

Comments
 (0)