Skip to content

build: fix staging sanity release checks picking up incorrect packages #23346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions .ng-dev/release.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,42 @@
import {BuiltPackage, ReleaseConfig} from '@angular/dev-infra-private/release/config';
import {ReleaseAction} from '@angular/dev-infra-private/release/publish/actions';
import {SemVer} from 'semver';

import {
assertValidFrameworkPeerDependency
} from '../tools/release-checks/check-framework-peer-dependency';
import {
assertValidUpdateMigrationCollections
} from '../tools/release-checks/check-migration-collections';
import {assertValidNpmPackageOutput} from '../tools/release-checks/npm-package-output';
import {fork} from 'child_process';
import {join} from 'path';
import {FatalReleaseActionError} from '@angular/dev-infra-private/release/publish/actions-error';

const actionProto = ReleaseAction.prototype as any;
const _origStageFn = actionProto.stageVersionForBranchAndCreatePullRequest;
const _origVerifyFn = actionProto._verifyPackageVersions;

/** Runs the staging sanity release checks for the given new version. */
async function runStagingReleaseChecks(newVersion: SemVer) {
return new Promise<void>((resolve, reject) => {
// Note: We run the staging release checks in a new node process. This is necessary
// because before staging, the correct publish branch is checked out. If we'd
// directly call into the release checks, the `.ng-dev/release` config would be
// cached by NodeJS and release checks would potentially check for packages which
// no longer exist in the publish branch (or the other way around).
const releaseChecksProcess = fork(
join(__dirname, '../tools/release-checks/index.js'), [newVersion.format()]);

releaseChecksProcess.on('close', code => {
if (code !== 0) {
reject(new FatalReleaseActionError());
} else {
resolve();
}
});
});
}

// Patches the `@angular/dev-infra-private` release tool to perform sanity checks
// before staging a release. This is temporary until the dev-infra team has implemented
// a more generic solution to running sanity checks before releasing (potentially building
// some of the checks we have in the components repository into the release tool).
actionProto.stageVersionForBranchAndCreatePullRequest = async function(newVersion: SemVer) {
await assertValidFrameworkPeerDependency(newVersion);
await assertValidUpdateMigrationCollections(newVersion);
await runStagingReleaseChecks(newVersion);

return await _origStageFn.apply(this, arguments);
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"scripts": {
"postinstall": "node tools/postinstall/apply-patches.js && ngcc --properties module main --create-ivy-entry-points && node tools/postinstall/update-ngcc-main-fields.js",
"build": "ts-node --project scripts/tsconfig.json ./scripts/build-packages-dist.js",
"build": "ts-node --project scripts/tsconfig.json ./scripts/build-packages-dist.ts",
"build-and-check-release-output": "ts-node --project scripts/tsconfig.json scripts/build-and-check-release-output.ts",
"build-docs-content": "node ./scripts/build-docs-content.js",
"dev-app": "ibazel run //src/dev-app:devserver",
Expand Down
27 changes: 27 additions & 0 deletions tools/release-checks/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require('ts-node').register({
dir: __dirname,
transpileOnly: true,
compilerOptions: {module: 'commonjs'},
})

const {parse} = require('semver');
const {assertValidFrameworkPeerDependency} = require('./check-framework-peer-dependency');
const {assertValidUpdateMigrationCollections} = require('./check-migration-collections');

async function main(newVersion) {
await assertValidFrameworkPeerDependency(newVersion);
await assertValidUpdateMigrationCollections(newVersion);
}

if (require.main === module) {
const newVersion = parse(process.argv[2]);

if (newVersion === null) {
throw Error('No proper version specified for release checks.');
}

main(newVersion).catch(e => {
console.error(e);
process.exit(1);
});
}