Skip to content

Commit 0ed1cbe

Browse files
authored
build: fix staging sanity release checks picking up incorrect packages (#23346)
Currently the new release tool hacks around the ng-dev publish tool in order to run staging sanity checks. The logic is currently running in the same Node process that started the publish process from `master`. This results in the sanity checks accidentally receiving a cached list of release packages, instead of the one local to the publish branch (like `12.2.x`build: fix staging sanity release checks picking up incorrect packages Currently the new release tool hacks around the ng-dev publish tool in order to run staging sanity checks. The logic is currently running in the same Node process that started the publish process from `master`. This results in the sanity checks accidentally receiving a cached list of release packages, instead of the one local to the publish branch (like `12.2.x`)
1 parent 74f18ed commit 0ed1cbe

File tree

3 files changed

+53
-10
lines changed

3 files changed

+53
-10
lines changed

.ng-dev/release.ts

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,42 @@
11
import {BuiltPackage, ReleaseConfig} from '@angular/dev-infra-private/release/config';
22
import {ReleaseAction} from '@angular/dev-infra-private/release/publish/actions';
33
import {SemVer} from 'semver';
4-
5-
import {
6-
assertValidFrameworkPeerDependency
7-
} from '../tools/release-checks/check-framework-peer-dependency';
8-
import {
9-
assertValidUpdateMigrationCollections
10-
} from '../tools/release-checks/check-migration-collections';
114
import {assertValidNpmPackageOutput} from '../tools/release-checks/npm-package-output';
5+
import {fork} from 'child_process';
6+
import {join} from 'path';
7+
import {FatalReleaseActionError} from '@angular/dev-infra-private/release/publish/actions-error';
128

139
const actionProto = ReleaseAction.prototype as any;
1410
const _origStageFn = actionProto.stageVersionForBranchAndCreatePullRequest;
1511
const _origVerifyFn = actionProto._verifyPackageVersions;
1612

13+
/** Runs the staging sanity release checks for the given new version. */
14+
async function runStagingReleaseChecks(newVersion: SemVer) {
15+
return new Promise<void>((resolve, reject) => {
16+
// Note: We run the staging release checks in a new node process. This is necessary
17+
// because before staging, the correct publish branch is checked out. If we'd
18+
// directly call into the release checks, the `.ng-dev/release` config would be
19+
// cached by NodeJS and release checks would potentially check for packages which
20+
// no longer exist in the publish branch (or the other way around).
21+
const releaseChecksProcess = fork(
22+
join(__dirname, '../tools/release-checks/index.js'), [newVersion.format()]);
23+
24+
releaseChecksProcess.on('close', code => {
25+
if (code !== 0) {
26+
reject(new FatalReleaseActionError());
27+
} else {
28+
resolve();
29+
}
30+
});
31+
});
32+
}
33+
1734
// Patches the `@angular/dev-infra-private` release tool to perform sanity checks
1835
// before staging a release. This is temporary until the dev-infra team has implemented
1936
// a more generic solution to running sanity checks before releasing (potentially building
2037
// some of the checks we have in the components repository into the release tool).
2138
actionProto.stageVersionForBranchAndCreatePullRequest = async function(newVersion: SemVer) {
22-
await assertValidFrameworkPeerDependency(newVersion);
23-
await assertValidUpdateMigrationCollections(newVersion);
39+
await runStagingReleaseChecks(newVersion);
2440

2541
return await _origStageFn.apply(this, arguments);
2642
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
},
1616
"scripts": {
1717
"postinstall": "node tools/postinstall/apply-patches.js && ngcc --properties module main --create-ivy-entry-points && node tools/postinstall/update-ngcc-main-fields.js",
18-
"build": "ts-node --project scripts/tsconfig.json ./scripts/build-packages-dist.js",
18+
"build": "ts-node --project scripts/tsconfig.json ./scripts/build-packages-dist.ts",
1919
"build-and-check-release-output": "ts-node --project scripts/tsconfig.json scripts/build-and-check-release-output.ts",
2020
"build-docs-content": "node ./scripts/build-docs-content.js",
2121
"dev-app": "ibazel run //src/dev-app:devserver",

tools/release-checks/index.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
require('ts-node').register({
2+
dir: __dirname,
3+
transpileOnly: true,
4+
compilerOptions: {module: 'commonjs'},
5+
})
6+
7+
const {parse} = require('semver');
8+
const {assertValidFrameworkPeerDependency} = require('./check-framework-peer-dependency');
9+
const {assertValidUpdateMigrationCollections} = require('./check-migration-collections');
10+
11+
async function main(newVersion) {
12+
await assertValidFrameworkPeerDependency(newVersion);
13+
await assertValidUpdateMigrationCollections(newVersion);
14+
}
15+
16+
if (require.main === module) {
17+
const newVersion = parse(process.argv[2]);
18+
19+
if (newVersion === null) {
20+
throw Error('No proper version specified for release checks.');
21+
}
22+
23+
main(newVersion).catch(e => {
24+
console.error(e);
25+
process.exit(1);
26+
});
27+
}

0 commit comments

Comments
 (0)