Skip to content

build: switch to release tool from dev-infra #23333

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 3 commits into from
Aug 11, 2021
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
4 changes: 2 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ test --test_output=errors

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

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

################################
Expand Down
12 changes: 2 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -386,16 +386,8 @@ jobs:
- *yarn_install
- *setup_bazel_binary

- run: yarn build
- run:
name: Checking release output
command: |
pkg_json_version=$(node -pe "require('./package.json').version")
expected_version="${pkg_json_version}-sha-$(git rev-parse --short HEAD)"
yarn check-release-output ${expected_version}
- run:
name: Checking tooling scripts
command: yarn check-tools
- run: yarn build-and-check-release-output
- run: yarn check-tools

# TODO(devversion): replace this with bazel tests that run Madge. This is
# cumbersome and doesn't guarantee no circular deps for other entry-points.
Expand Down
70 changes: 58 additions & 12 deletions .ng-dev/release.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,66 @@
import {join} from 'path';
import {ReleaseConfig} from '@angular/dev-infra-private/release/config';
import {releasePackages} from '../tools/release/release-output/release-packages';
import {promptAndGenerateChangelog} from '../tools/release/changelog';
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';

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

// 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);

return await _origStageFn.apply(this, arguments);
};

// Patches the `@angular/dev-infra-private` release tool to perform sanity
// checks of the NPM package output, before publishing to NPM.
actionProto._verifyPackageVersions =
async function(newVersion: SemVer, builtPackages: BuiltPackage[]) {
await assertValidNpmPackageOutput(builtPackages, newVersion);

return await _origVerifyFn.apply(this, arguments);
};

/**
* Packages that will be published as part of the project.
*
* Note: The order of packages here will control how sections
* appear in the changelog.
*/
export const releasePackages = [
'cdk',
'material',
'google-maps',
'youtube-player',
'cdk-experimental',
'material-experimental',
'material-moment-adapter',
'material-luxon-adapter',
'material-date-fns-adapter',
];

/** Configuration for the `ng-dev release` command. */
export const release: ReleaseConfig = {
releaseNotes: {useReleaseTitle: true, groupOrder: releasePackages},
publishRegistry: 'https://wombat-dressing-room.appspot.com',
npmPackages: releasePackages.map(pkg => `@angular/${pkg}`),
buildPackages: async () => {
// The performNpmReleaseBuild function is loaded at runtime as the loading the script causes an
// invocation of bazel.
const {performNpmReleaseBuild} = require(join(__dirname, '../scripts/build-packages-dist'));
// The `performNpmReleaseBuild` function is loaded at runtime as loading of the
// script results in an invocation of Bazel for any `yarn ng-dev` command.
const {performNpmReleaseBuild} = await import('../scripts/build-packages-dist');
return performNpmReleaseBuild();
},
// TODO: This can be removed once there is an org-wide tool for changelog generation.
generateReleaseNotesForHead: async () => {
await promptAndGenerateChangelog(join(__dirname, '../CHANGELOG.md'));
},
}
};
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
},
"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": "node ./scripts/build-packages-dist.js",
"build": "ts-node --project scripts/tsconfig.json ./scripts/build-packages-dist.js",
"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",
"test": "node ./scripts/run-component-tests.js",
Expand All @@ -26,10 +27,9 @@
"deploy-dev-app": "node ./scripts/deploy-dev-app.js",
"breaking-changes": "ts-node --project scripts/tsconfig.json scripts/breaking-changes.ts",
"gulp": "gulp",
"stage-release": "ts-node --project tools/release/tsconfig.json tools/release/stage-release.ts",
"publish-release": "ts-node --project tools/release/tsconfig.json tools/release/publish-release.ts",
"~~stage-release": "ts-node --project tools/legacy-release/tsconfig.json tools/legacy-release/stage-release.ts",
"~~publish-release": "ts-node --project tools/legacy-release/tsconfig.json tools/legacy-release/publish-release.ts",
"check-entry-point-setup": "node ./scripts/check-entry-point-setup.js",
"check-release-output": "ts-node --project tools/release/tsconfig.json tools/release/check-release-output.ts",
"check-rollup-globals": "ts-node --project scripts/tsconfig.json scripts/check-rollup-globals.ts",
"changelog": "ts-node --project tools/release/tsconfig.json tools/release/changelog.ts",
"format": "yarn ng-dev format changed",
Expand Down
25 changes: 25 additions & 0 deletions scripts/build-and-check-release-output.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Script that builds the NPM release output for all packages
* and runs sanity checks against the NPM package output.
*/

import {performNpmReleaseBuild} from './build-packages-dist';
import {assertValidNpmPackageOutput} from '../tools/release-checks/npm-package-output';
import * as semver from 'semver';

const {version} = require('../package.json');

async function main() {
// Build the NPM package artifacts.
const builtPackages = performNpmReleaseBuild();

// Run the release output validation checks.
await assertValidNpmPackageOutput(builtPackages, semver.parse(version)!);
}

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


37 changes: 19 additions & 18 deletions scripts/build-packages-dist.js → scripts/build-packages-dist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
* distribution folder within the project.
*/

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

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

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

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

/** Builds the release packages for NPM. */
function performNpmReleaseBuild() {
export function performNpmReleaseBuild(): BuiltPackage[] {
return buildReleasePackages(false, defaultDistPath, /* isSnapshotBuild */ false);
}

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

/**
* Builds the release packages with the given compile mode and copies
* the package output into the given directory.
*/
function buildReleasePackages(useIvy, distPath, isSnapshotBuild) {
function buildReleasePackages(useIvy: boolean, distPath: string,
isSnapshotBuild: boolean): BuiltPackage[] {

console.log('######################################');
console.log(' Building release packages...');
console.log(` Compiling with Ivy: ${useIvy}`);
Expand Down Expand Up @@ -109,15 +112,15 @@ function buildReleasePackages(useIvy, distPath, isSnapshotBuild) {
return {
name: `@angular/${pkg}`,
outputPath
}
})
};
});
}

/**
* Gets the package names of the specified Bazel targets.
* e.g. //src/material:npm_package -> material
* e.g. //src/material:npm_package = material
*/
function getPackageNamesOfTargets(targets) {
function getPackageNamesOfTargets(targets: string[]): string[] {
return targets.map(targetName => {
const matches = targetName.match(/\/\/src\/(.*):npm_package/);
if (matches === null) {
Expand All @@ -128,13 +131,11 @@ function getPackageNamesOfTargets(targets) {
});
}

/**
* Executes the given command in the project directory.
* @param {string} command The command to run
* @param {boolean=} captureStdout Whether the stdout should be captured and
* returned.
*/
function exec(command, captureStdout) {
/** Executes the given command in the project directory. */
function exec(command: string): void;
/** Executes the given command in the project directory and returns its stdout. */
function exec(command: string, captureStdout: true): string;
function exec(command: string, captureStdout?: true) {
const stdout = execSync(command, {
cwd: projectDir,
stdio: ['inherit', captureStdout ? 'pipe' : 'inherit', 'inherit'],
Expand Down
5 changes: 1 addition & 4 deletions src/cdk-experimental/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,5 @@
"dependencies": {
"tslib": "0.0.0-TSLIB"
},
"sideEffects": false,
"publishConfig":{
"registry":"https://wombat-dressing-room.appspot.com"
}
"sideEffects": false
}
5 changes: 1 addition & 4 deletions src/cdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,5 @@
"ng-update": {
"migrations": "./schematics/migration.json"
},
"sideEffects": false,
"publishConfig":{
"registry":"https://wombat-dressing-room.appspot.com"
}
"sideEffects": false
}
3 changes: 0 additions & 3 deletions src/google-maps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,5 @@
"rxjs": "0.0.0-RXJS"
},
"sideEffects": false,
"publishConfig": {
"registry": "https://wombat-dressing-room.appspot.com"
},
"ng-update": {}
}
5 changes: 1 addition & 4 deletions src/material-date-fns-adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,5 @@
"@angular/material-date-fns-adapter"
]
},
"sideEffects": false,
"publishConfig": {
"registry":"https://wombat-dressing-room.appspot.com"
}
"sideEffects": false
}
5 changes: 1 addition & 4 deletions src/material-experimental/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,5 @@
"dependencies": {
"tslib": "0.0.0-TSLIB"
},
"sideEffects": false,
"publishConfig":{
"registry":"https://wombat-dressing-room.appspot.com"
}
"sideEffects": false
}
5 changes: 1 addition & 4 deletions src/material-luxon-adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,5 @@
"@angular/material-luxon-adapter"
]
},
"sideEffects": false,
"publishConfig": {
"registry":"https://wombat-dressing-room.appspot.com"
}
"sideEffects": false
}
5 changes: 1 addition & 4 deletions src/material-moment-adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,5 @@
"@angular/material-moment-adapter"
]
},
"sideEffects": false,
"publishConfig":{
"registry":"https://wombat-dressing-room.appspot.com"
}
"sideEffects": false
}
5 changes: 1 addition & 4 deletions src/material/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@
"@angular/material-date-fns-adapter"
]
},
"sideEffects": false,
"publishConfig":{
"registry":"https://wombat-dressing-room.appspot.com"
}
"sideEffects": false
}

3 changes: 0 additions & 3 deletions src/youtube-player/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,5 @@
"rxjs": "0.0.0-RXJS"
},
"sideEffects": false,
"publishConfig":{
"registry":"https://wombat-dressing-room.appspot.com"
},
"ng-update": {}
}
57 changes: 0 additions & 57 deletions tools/bazel-stamp-vars.js

This file was deleted.

File renamed without changes.
Loading