From f424aa3f0fa36e4527b211669ba50b910d9f4e73 Mon Sep 17 00:00:00 2001 From: Joey Perrott Date: Tue, 25 May 2021 09:42:36 -0700 Subject: [PATCH] feat(dev-infra): add support for determining if builds should be stamped (#42319) Add support for the build process to determine if the generated builds should be stamped for release. PR Close #42319 --- dev-infra/build-worker.js | 6 +++--- dev-infra/release/build/build-worker.ts | 6 +++--- dev-infra/release/build/build.spec.ts | 2 +- dev-infra/release/build/cli.ts | 19 +++++++++++++------ dev-infra/release/build/index.ts | 5 +++-- dev-infra/release/config/index.ts | 2 +- 6 files changed, 24 insertions(+), 16 deletions(-) diff --git a/dev-infra/build-worker.js b/dev-infra/build-worker.js index 66a47b1fe5..e392a8010d 100644 --- a/dev-infra/build-worker.js +++ b/dev-infra/build-worker.js @@ -704,15 +704,15 @@ function getReleaseConfig(config = getConfig()) { * found in the LICENSE file at https://angular.io/license */ // Start the release package building. -main(); +main(process.argv[2] === 'true'); /** Main function for building the release packages. */ -function main() { +function main(stampForRelease) { return tslib.__awaiter(this, void 0, void 0, function* () { if (process.send === undefined) { throw Error('This script needs to be invoked as a NodeJS worker.'); } const config = getReleaseConfig(); - const builtPackages = yield config.buildPackages(); + const builtPackages = yield config.buildPackages(stampForRelease); // Transfer the built packages back to the parent process. process.send(builtPackages); }); diff --git a/dev-infra/release/build/build-worker.ts b/dev-infra/release/build/build-worker.ts index 5cc090495e..97d7a9bcec 100644 --- a/dev-infra/release/build/build-worker.ts +++ b/dev-infra/release/build/build-worker.ts @@ -16,16 +16,16 @@ import {getReleaseConfig} from '../config/index'; // Start the release package building. -main(); +main(process.argv[2] === 'true'); /** Main function for building the release packages. */ -async function main() { +async function main(stampForRelease: boolean) { if (process.send === undefined) { throw Error('This script needs to be invoked as a NodeJS worker.'); } const config = getReleaseConfig(); - const builtPackages = await config.buildPackages(); + const builtPackages = await config.buildPackages(stampForRelease); // Transfer the built packages back to the parent process. process.send(builtPackages); diff --git a/dev-infra/release/build/build.spec.ts b/dev-infra/release/build/build.spec.ts index 6302752233..1853a66538 100644 --- a/dev-infra/release/build/build.spec.ts +++ b/dev-infra/release/build/build.spec.ts @@ -33,7 +33,7 @@ describe('ng-dev release build', () => { async function invokeBuild({json}: {json?: boolean} = {}) { spyOn(releaseConfig, 'getReleaseConfig') .and.returnValue({npmPackages, buildPackages, releaseNotes: {}}); - await ReleaseBuildCommandModule.handler({json: !!json, $0: '', _: []}); + await ReleaseBuildCommandModule.handler({json: !!json, stampForRelease: true, $0: '', _: []}); } it('should invoke configured build packages function', async () => { diff --git a/dev-infra/release/build/cli.ts b/dev-infra/release/build/cli.ts index 9898e5f74b..9b281c76bc 100644 --- a/dev-infra/release/build/cli.ts +++ b/dev-infra/release/build/cli.ts @@ -17,21 +17,28 @@ import {buildReleaseOutput} from './index'; /** Command line options for building a release. */ export interface ReleaseBuildOptions { json: boolean; + stampForRelease: boolean; } /** Yargs command builder for configuring the `ng-dev release build` command. */ function builder(argv: Argv): Argv { - return argv.option('json', { - type: 'boolean', - description: 'Whether the built packages should be printed to stdout as JSON.', - default: false, - }); + return argv + .option('json', { + type: 'boolean', + description: 'Whether the built packages should be printed to stdout as JSON.', + default: false, + }) + .option('stampForRelease', { + type: 'boolean', + description: 'Whether the built packages should be stamped for release.', + default: false, + }); } /** Yargs command handler for building a release. */ async function handler(args: Arguments) { const {npmPackages} = getReleaseConfig(); - let builtPackages = await buildReleaseOutput(); + let builtPackages = await buildReleaseOutput(args.stampForRelease); // If package building failed, print an error and exit with an error code. if (builtPackages === null) { diff --git a/dev-infra/release/build/index.ts b/dev-infra/release/build/index.ts index 7a024490a4..97bf1c3847 100644 --- a/dev-infra/release/build/index.ts +++ b/dev-infra/release/build/index.ts @@ -16,9 +16,10 @@ import {BuiltPackage} from '../config/index'; * pollute the stdout in such cases, we launch a child process for building the release packages * and redirect all stdout output to the stderr channel (which can be read in the terminal). */ -export async function buildReleaseOutput(): Promise { +export async function buildReleaseOutput(stampForRelease: boolean = false): + Promise { return new Promise(resolve => { - const buildProcess = fork(require.resolve('./build-worker'), [], { + const buildProcess = fork(require.resolve('./build-worker'), [`${stampForRelease}`], { // The stdio option is set to redirect any "stdout" output directly to the "stderr" file // descriptor. An additional "ipc" file descriptor is created to support communication with // the build process. https://nodejs.org/api/child_process.html#child_process_options_stdio. diff --git a/dev-infra/release/config/index.ts b/dev-infra/release/config/index.ts index fb87ce3e6e..2f4bd12e46 100644 --- a/dev-infra/release/config/index.ts +++ b/dev-infra/release/config/index.ts @@ -23,7 +23,7 @@ export interface ReleaseConfig { /** List of NPM packages that are published as part of this project. */ npmPackages: string[]; /** Builds release packages and returns a list of paths pointing to the output. */ - buildPackages: () => Promise; + buildPackages: (stampForRelease?: boolean) => Promise; /** The list of github labels to add to the release PRs. */ releasePrLabels?: string[]; /** Configuration for creating release notes during publishing. */