diff --git a/.ng-dev/release.ts b/.ng-dev/release.ts index ccef1fa41625..ee06ef8b0ae8 100644 --- a/.ng-dev/release.ts +++ b/.ng-dev/release.ts @@ -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((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); }; diff --git a/package.json b/package.json index 7f2a13bb5e17..0c98ae19abe2 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/tools/release-checks/index.js b/tools/release-checks/index.js new file mode 100644 index 000000000000..03ee333ccde7 --- /dev/null +++ b/tools/release-checks/index.js @@ -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); + }); +}