feat(dev-infra): introduce new configuration for release tool (#38656)

Introduces a new configuration for the `ng-dev release` command. This
configuration will be the source of truth for all release packages
and how they can be built.

Additionally, in a temporary manner where each project has its own
way of generating the changelog, the changelog generation can be
configured. This will be removed in the future when there is
canonical changelog generation in the dev-infra shared package.

PR Close #38656
This commit is contained in:
Paul Gschwendtner 2020-09-09 14:37:38 +02:00 committed by Alex Rickabaugh
parent c1b47bcfaa
commit e1c11a36c7
4 changed files with 112 additions and 0 deletions

View File

@ -3,6 +3,7 @@ import {commitMessage} from './commit-message';
import {format} from './format';
import {github} from './github';
import {merge} from './merge';
import {release} from './release';
module.exports = {
commitMessage,
@ -10,4 +11,5 @@ module.exports = {
github,
merge,
caretaker,
release,
};

33
.ng-dev/release.ts Normal file
View File

@ -0,0 +1,33 @@
import {join} from 'path';
import {exec} from 'shelljs';
import {ReleaseConfig} from '../dev-infra/release/config';
/** Configuration for the `ng-dev release` command. */
export const release: ReleaseConfig = {
npmPackages: [
'@angular/animations',
'@angular/bazel',
'@angular/common',
'@angular/compiler',
'@angular/compiler-cli',
'@angular/core',
'@angular/elements',
'@angular/forms',
'@angular/language-service',
'@angular/localize',
'@angular/platform-browser',
'@angular/platform-browser-dynamic',
'@angular/platform-server',
'@angular/platform-webworker',
'@angular/platform-webworker-dynamic',
'@angular/router',
'@angular/service-worker',
'@angular/upgrade',
],
// TODO: Implement release package building here.
buildPackages: async () => [],
// TODO: This can be removed once there is a org-wide tool for changelog generation.
generateReleaseNotesForHead: async () => {
exec('yarn -s gulp changelog', {cwd: join(__dirname, '../')});
},
};

View File

@ -0,0 +1,14 @@
load("@npm_bazel_typescript//:index.bzl", "ts_library")
ts_library(
name = "config",
srcs = glob([
"**/*.ts",
]),
module_name = "@angular/dev-infra-private/release/config",
visibility = ["//dev-infra:__subpackages__"],
deps = [
"//dev-infra/utils",
"@npm//@types/semver",
],
)

View File

@ -0,0 +1,63 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import * as semver from 'semver';
import {assertNoErrors, getConfig, NgDevConfig} from '../../utils/config';
/** Interface describing a built package. */
export interface BuiltPackage {
/** Name of the package. */
name: string;
/** Path to the package output directory. */
outputPath: string;
}
/** Configuration for staging and publishing a release. */
export interface ReleaseConfig {
/** Registry URL used for publishing release packages. Defaults to the NPM registry. */
publishRegistry?: string;
/** 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<BuiltPackage[]|null>;
/** Generates the release notes from the most recent tag to `HEAD`. */
generateReleaseNotesForHead: (outputPath: string) => Promise<void>;
/**
* Gets a pattern for extracting the release notes of the a given version.
* @returns A pattern matching the notes for a given version (including the header).
*/
// TODO: Remove this in favor of a canonical changelog format across the Angular organization.
extractReleaseNotesPattern?: (version: semver.SemVer) => RegExp;
}
/** Configuration for releases in the dev-infra configuration. */
export type DevInfraReleaseConfig = NgDevConfig<{release: ReleaseConfig}>;
/** Retrieve and validate the config as `ReleaseConfig`. */
export function getReleaseConfig(config: Partial<DevInfraReleaseConfig> = getConfig()):
ReleaseConfig {
// List of errors encountered validating the config.
const errors: string[] = [];
if (config.release === undefined) {
errors.push(`No configuration defined for "release"`);
}
if (config.release?.npmPackages === undefined) {
errors.push(`No "npmPackages" configured for releasing.`);
}
if (config.release?.buildPackages === undefined) {
errors.push(`No "buildPackages" function configured for releasing.`);
}
if (config.release?.generateReleaseNotesForHead === undefined) {
errors.push(`No "generateReleaseNotesForHead" function configured for releasing.`);
}
assertNoErrors(errors);
return config.release!;
}