Skip to content

Commit 18e85e2

Browse files
authored
build: switch to release tool from dev-infra
Switches to the release tool from the shared dev-infra package. This script is more aligned with the versioning and branching the whole Angular organization follows as this point. We work around a couple of APIs that need to be discussed within the release tool in order to wire up custom release stage / publish validations. We still want to keep them for now so we use some monkey-patching (which is acceptable for the interim until we have determined which checks should be built-in / how consumers can wire up additional checks)
1 parent 0114ccd commit 18e85e2

34 files changed

+286
-206
lines changed

.bazelrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ test --test_output=errors
4545

4646
# Configures script to do version stamping.
4747
# See https://docs.bazel.build/versions/master/user-manual.html#flag--workspace_status_command
48-
build:release --workspace_status_command="node ./tools/bazel-stamp-vars.js"
48+
build:release --workspace_status_command="yarn -s ng-dev release build-env-stamp --mode=release"
4949
build:release --stamp
5050

51-
build:snapshot-build --workspace_status_command="node ./tools/bazel-stamp-vars.js --snapshot"
51+
build:snapshot-build --workspace_status_command="yarn -s ng-dev release build-env-stamp --mode=snapshot"
5252
build:snapshot-build --stamp
5353

5454
################################

.circleci/config.yml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -386,16 +386,8 @@ jobs:
386386
- *yarn_install
387387
- *setup_bazel_binary
388388

389-
- run: yarn build
390-
- run:
391-
name: Checking release output
392-
command: |
393-
pkg_json_version=$(node -pe "require('./package.json').version")
394-
expected_version="${pkg_json_version}-sha-$(git rev-parse --short HEAD)"
395-
yarn check-release-output ${expected_version}
396-
- run:
397-
name: Checking tooling scripts
398-
command: yarn check-tools
389+
- run: yarn build-and-check-release-output
390+
- run: yarn check-tools
399391

400392
# TODO(devversion): replace this with bazel tests that run Madge. This is
401393
# cumbersome and doesn't guarantee no circular deps for other entry-points.

.ng-dev/release.ts

Lines changed: 59 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,66 @@
1-
import {join} from 'path';
2-
import {ReleaseConfig} from '@angular/dev-infra-private/release/config';
3-
import {releasePackages} from '../tools/release/release-output/release-packages';
4-
import {promptAndGenerateChangelog} from '../tools/release/changelog';
1+
import {BuiltPackage, ReleaseConfig} from '@angular/dev-infra-private/release/config';
2+
import {ReleaseAction} from '@angular/dev-infra-private/release/publish/actions';
3+
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';
11+
import {assertValidNpmPackageOutput} from '../tools/release-checks/npm-package-output';
12+
13+
const actionProto = ReleaseAction.prototype as any;
14+
const _origStageFn = actionProto.stageVersionForBranchAndCreatePullRequest;
15+
const _origVerifyFn = actionProto._verifyPackageVersions;
16+
17+
// Patches the `@angular/dev-infra-private` release tool to perform sanity checks
18+
// before staging a release. This is temporary until the dev-infra team has implemented
19+
// a more generic solution to running sanity checks before releasing (potentially building
20+
// some of the checks we have in the components repository into the release tool).
21+
actionProto.stageVersionForBranchAndCreatePullRequest = async function(newVersion: SemVer) {
22+
await assertValidFrameworkPeerDependency(newVersion);
23+
await assertValidUpdateMigrationCollections(newVersion);
24+
25+
return await _origStageFn.apply(this, arguments);
26+
};
27+
28+
// Patches the `@angular/dev-infra-private` release tool to perform sanity
29+
// checks of the NPM package output, before publishing to NPM.
30+
actionProto._verifyPackageVersions =
31+
async function(newVersion: SemVer, builtPackages: BuiltPackage[]) {
32+
await assertValidNpmPackageOutput(builtPackages, newVersion);
33+
34+
return await _origVerifyFn.apply(this, arguments);
35+
};
36+
37+
/**
38+
* Packages that will be published as part of the project.
39+
*
40+
* Note: The order of packages here will control how sections
41+
* appear in the changelog.
42+
*/
43+
export const releasePackages = [
44+
'cdk',
45+
'material',
46+
'google-maps',
47+
'youtube-player',
48+
'cdk-experimental',
49+
'material-experimental',
50+
'material-moment-adapter',
51+
'material-luxon-adapter',
52+
'material-date-fns-adapter',
53+
];
554

655
/** Configuration for the `ng-dev release` command. */
756
export const release: ReleaseConfig = {
8-
publishRegistry: 'https://wombat-dressing-room.appspot.com',
57+
releaseNotes: {useReleaseTitle: true, groupOrder: releasePackages},
58+
// publishRegistry: 'https://wombat-dressing-room.appspot.com',
959
npmPackages: releasePackages.map(pkg => `@angular/${pkg}`),
1060
buildPackages: async () => {
11-
// The performNpmReleaseBuild function is loaded at runtime as the loading the script causes an
12-
// invocation of bazel.
13-
const {performNpmReleaseBuild} = require(join(__dirname, '../scripts/build-packages-dist'));
61+
// The `performNpmReleaseBuild` function is loaded at runtime as loading of the
62+
// script results in an invocation of Bazel for any `yarn ng-dev` command.
63+
const {performNpmReleaseBuild} = await import('../scripts/build-packages-dist');
1464
return performNpmReleaseBuild();
15-
},
16-
// TODO: This can be removed once there is an org-wide tool for changelog generation.
17-
generateReleaseNotesForHead: async () => {
18-
await promptAndGenerateChangelog(join(__dirname, '../CHANGELOG.md'));
19-
},
65+
}
2066
};

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
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": "node ./scripts/build-packages-dist.js",
18+
"build": "ts-node --project scripts/tsconfig.json ./scripts/build-packages-dist.js",
19+
"build-and-check-release-output": "ts-node --project scripts/tsconfig.json scripts/build-and-check-release-output.ts",
1920
"build-docs-content": "node ./scripts/build-docs-content.js",
2021
"dev-app": "ibazel run //src/dev-app:devserver",
2122
"test": "node ./scripts/run-component-tests.js",
@@ -26,10 +27,9 @@
2627
"deploy-dev-app": "node ./scripts/deploy-dev-app.js",
2728
"breaking-changes": "ts-node --project scripts/tsconfig.json scripts/breaking-changes.ts",
2829
"gulp": "gulp",
29-
"stage-release": "ts-node --project tools/release/tsconfig.json tools/release/stage-release.ts",
30-
"publish-release": "ts-node --project tools/release/tsconfig.json tools/release/publish-release.ts",
30+
"~~stage-release": "ts-node --project tools/legacy-release/tsconfig.json tools/legacy-release/stage-release.ts",
31+
"~~publish-release": "ts-node --project tools/legacy-release/tsconfig.json tools/legacy-release/publish-release.ts",
3132
"check-entry-point-setup": "node ./scripts/check-entry-point-setup.js",
32-
"check-release-output": "ts-node --project tools/release/tsconfig.json tools/release/check-release-output.ts",
3333
"check-rollup-globals": "ts-node --project scripts/tsconfig.json scripts/check-rollup-globals.ts",
3434
"changelog": "ts-node --project tools/release/tsconfig.json tools/release/changelog.ts",
3535
"format": "yarn ng-dev format changed",
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Script that builds the NPM release output for all packages
3+
* and runs sanity checks against the NPM package output.
4+
*/
5+
6+
import {performNpmReleaseBuild} from './build-packages-dist';
7+
import {assertValidNpmPackageOutput} from '../tools/release-checks/npm-package-output';
8+
import * as semver from 'semver';
9+
10+
const {version} = require('../package.json');
11+
12+
async function main() {
13+
// Build the NPM package artifacts.
14+
const builtPackages = performNpmReleaseBuild();
15+
16+
// Run the release output validation checks.
17+
await assertValidNpmPackageOutput(builtPackages, semver.parse(version)!);
18+
}
19+
20+
main().catch(e => {
21+
console.error(e);
22+
process.exit(1);
23+
});
24+
25+

scripts/build-packages-dist.js renamed to scripts/build-packages-dist.ts

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
* distribution folder within the project.
77
*/
88

9-
const {execSync} = require('child_process');
10-
const {join} = require('path');
11-
const {chmod, cp, mkdir, rm, set, test} = require('shelljs');
9+
import {execSync} from 'child_process';
10+
import {join} from 'path';
11+
import {BuiltPackage} from '@angular/dev-infra-private/release/config';
12+
import {chmod, cp, mkdir, rm, set, test} from 'shelljs';
1213

1314
// ShellJS should exit if a command fails.
1415
set('-e');
@@ -20,7 +21,7 @@ const releaseTargetTag = 'release-package';
2021
const projectDir = join(__dirname, '../');
2122

2223
/** Command that runs Bazel. */
23-
const bazelCmd = process.env.BAZEL_COMMAND || `yarn -s bazel`;
24+
const bazelCmd = process.env.BAZEL_COMMAND || `bazel`;
2425

2526
/** Command that queries Bazel for all release package targets. */
2627
const queryPackagesCmd =
@@ -43,23 +44,23 @@ if (module === require.main) {
4344
}
4445

4546
/** Builds the release packages for NPM. */
46-
function performNpmReleaseBuild() {
47+
export function performNpmReleaseBuild(): BuiltPackage[] {
4748
return buildReleasePackages(false, defaultDistPath, /* isSnapshotBuild */ false);
4849
}
4950

5051
/**
5152
* Builds the release packages as snapshot build. This means that the current
5253
* Git HEAD SHA is included in the version (for easier debugging and back tracing).
5354
*/
54-
function performDefaultSnapshotBuild() {
55+
export function performDefaultSnapshotBuild(): BuiltPackage[] {
5556
return buildReleasePackages(false, defaultDistPath, /* isSnapshotBuild */ true);
5657
}
5758

5859
/**
5960
* Builds the release packages with the given compile mode and copies
6061
* the package output into the given directory.
6162
*/
62-
function buildReleasePackages(useIvy, distPath, isSnapshotBuild) {
63+
function buildReleasePackages(useIvy, distPath, isSnapshotBuild): BuiltPackage[] {
6364
console.log('######################################');
6465
console.log(' Building release packages...');
6566
console.log(` Compiling with Ivy: ${useIvy}`);
@@ -109,15 +110,15 @@ function buildReleasePackages(useIvy, distPath, isSnapshotBuild) {
109110
return {
110111
name: `@angular/${pkg}`,
111112
outputPath
112-
}
113-
})
113+
};
114+
});
114115
}
115116

116117
/**
117118
* Gets the package names of the specified Bazel targets.
118-
* e.g. //src/material:npm_package -> material
119+
* e.g. //src/material:npm_package = material
119120
*/
120-
function getPackageNamesOfTargets(targets) {
121+
function getPackageNamesOfTargets(targets: string[]): string[] {
121122
return targets.map(targetName => {
122123
const matches = targetName.match(/\/\/src\/(.*):npm_package/);
123124
if (matches === null) {
@@ -128,13 +129,11 @@ function getPackageNamesOfTargets(targets) {
128129
});
129130
}
130131

131-
/**
132-
* Executes the given command in the project directory.
133-
* @param {string} command The command to run
134-
* @param {boolean=} captureStdout Whether the stdout should be captured and
135-
* returned.
136-
*/
137-
function exec(command, captureStdout) {
132+
/** Executes the given command in the project directory. */
133+
function exec(command: string): void;
134+
/** Executes the given command in the project directory and returns its stdout. */
135+
function exec(command: string, captureStdout: true): string;
136+
function exec(command: string, captureStdout?: boolean) {
138137
const stdout = execSync(command, {
139138
cwd: projectDir,
140139
stdio: ['inherit', captureStdout ? 'pipe' : 'inherit', 'inherit'],

tools/bazel-stamp-vars.js

Lines changed: 0 additions & 57 deletions
This file was deleted.

tools/release/changelog.ts renamed to tools/legacy-release/changelog.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ const orderedChangelogPackages = [
3232
'google-maps',
3333
'youtube-player',
3434
'material-moment-adapter',
35-
'material-luxon-adapter',
36-
'material-date-fns-adapter',
3735
'cdk-experimental',
3836
'material-experimental',
3937
];

tools/release/check-release-output.ts renamed to tools/legacy-release/check-release-output.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as chalk from 'chalk';
22
import {join} from 'path';
3-
import {checkReleasePackage} from './release-output/check-package';
4-
import {releasePackages} from './release-output/release-packages';
3+
import {checkReleasePackage} from '../release-checks/npm-package-output/check-package';
4+
import {releasePackages} from '../../.ng-dev/release';
55

66
/**
77
* Checks the release output by running the release-output validations for each

tools/release/publish-release.ts renamed to tools/legacy-release/publish-release.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,10 @@ import {getGithubNewReleaseUrl} from './git/github-urls';
1010
import {npmPublish} from './npm/npm-client';
1111
import {promptForNpmDistTag} from './prompt/npm-dist-tag-prompt';
1212
import {promptForUpstreamRemote} from './prompt/upstream-remote-prompt';
13-
import {releasePackages} from './release-output/release-packages';
1413
import {CHANGELOG_FILE_NAME} from './stage-release';
1514
import {parseVersionName, Version} from './version-name/parse-version';
16-
17-
// The package builder script is not written in TypeScript and needs to
18-
// be imported through a CommonJS import.
19-
const {performNpmReleaseBuild} = require('../../scripts/build-packages-dist');
15+
import {performNpmReleaseBuild} from '../../scripts/build-packages-dist';
16+
import {releasePackages} from '../../.ng-dev/release';
2017

2118
/**
2219
* Class that can be instantiated in order to create a new release. The tasks requires user
@@ -36,9 +33,6 @@ class PublishReleaseTask extends BaseReleaseTask {
3633
/** Path to the release output of the project. */
3734
releaseOutputPath: string;
3835

39-
/** Instance of a wrapper that can execute Git commands. */
40-
git: GitClient;
41-
4236
constructor(public projectDir: string,
4337
public repositoryOwner: string,
4438
public repositoryName: string) {

tools/release/stage-release.ts renamed to tools/legacy-release/stage-release.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import {promptAndGenerateChangelog} from './changelog';
77
import {GitClient} from './git/git-client';
88
import {getGithubBranchCommitsUrl} from './git/github-urls';
99
import {promptForNewVersion} from './prompt/new-version-prompt';
10-
import {checkPackageJsonMigrations} from './release-output/output-validations';
11-
import {releasePackages} from './release-output/release-packages';
1210
import {parseVersionName, Version} from './version-name/parse-version';
11+
import {releasePackages} from '../../.ng-dev/release';
12+
import {checkPackageJsonMigrations} from '../release-checks/check-migration-collections';
13+
import * as semver from 'semver';
1314

1415
/** Default filename for the changelog. */
1516
export const CHANGELOG_FILE_NAME = 'CHANGELOG.md';
@@ -46,9 +47,6 @@ class StageReleaseTask extends BaseReleaseTask {
4647
/** Parsed current version of the project. */
4748
currentVersion: Version;
4849

49-
/** Instance of a wrapper that can execute Git commands. */
50-
git: GitClient;
51-
5250
/** Octokit API instance that can be used to make Github API calls. */
5351
githubApi: Octokit;
5452

@@ -253,8 +251,8 @@ class StageReleaseTask extends BaseReleaseTask {
253251
const failures: string[] = [];
254252
releasePackages.forEach(packageName => {
255253
failures.push(...checkPackageJsonMigrations(
256-
join(this.packagesDir, packageName, 'package.json'), newVersion)
257-
.map(f => chalk.yellow(` ⮑ ${chalk.bold(packageName)}: ${f}`)));
254+
join(this.packagesDir, packageName, 'package.json'), semver.parse(newVersion.format())!)
255+
.map(f => chalk.yellow(` ⮑ ${chalk.bold(packageName)}: ${f}`)));
258256
});
259257
if (failures.length) {
260258
console.error(chalk.red(` ✘ Failures in ng-update migration collection detected:`));

tools/legacy-release/tsconfig.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"compilerOptions": {
3+
"outDir": "../../dist/tools/release",
4+
"target": "esnext",
5+
"module": "commonjs",
6+
"moduleResolution": "node",
7+
"lib": ["es2016"],
8+
"types": ["node"],
9+
"strictNullChecks": true,
10+
"skipLibCheck": true
11+
}
12+
}

0 commit comments

Comments
 (0)