Skip to content

Commit 572ec0e

Browse files
committed
build: switch to release output from bazel
1 parent 20f9fef commit 572ec0e

File tree

15 files changed

+108
-34
lines changed

15 files changed

+108
-34
lines changed

.circleci/config.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ jobs:
155155
- *yarn_install
156156
- *setup_bazel_binary
157157

158-
- run: bazel build src/...
158+
- run: bazel build src/... --build_tag_filters=-docs-package,-release-package
159159

160160
# --------------------------------------------------------------------------------------------
161161
# Job that runs ts-api-guardian against our API goldens in "tools/public_api_guard".
@@ -272,19 +272,24 @@ jobs:
272272
- *save_cache
273273

274274
# -------------------------------------------------------------------------------------------
275-
# Job that builds all release packages with Gulp. The built packages can be then used in the
276-
# same workflow to publish snapshot builds or test the dev-app with the release packages.
275+
# Job that builds all release packages. The built packages can be then used in the same
276+
# workflow to publish snapshot builds.
277277
# -------------------------------------------------------------------------------------------
278278
build_release_packages:
279279
<<: *job_defaults
280280
resource_class: xlarge
281+
environment:
282+
GCP_DECRYPT_TOKEN: *gcp_decrypt_token
281283
steps:
282284
- *checkout_code
283285
- *restore_cache
286+
- *setup_bazel_ci_config
287+
- *setup_bazel_remote_execution
284288
- *yarn_download
285289
- *yarn_install
290+
- *setup_bazel_binary
286291

287-
- run: yarn gulp ci:build-release-packages
292+
- run: ./scripts/build-packages-dist.sh
288293
- run: yarn check-release-output
289294

290295
# TODO(devversion): replace this with bazel tests that run Madge. This is

packages.bzl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ MATERIAL_PACKAGES = [
7878
"tree",
7979
]
8080

81-
MATERIAL_TARGETS = ["//src/material:material"] + ["//src/material/%s" % p for p in MATERIAL_PACKAGES]
81+
MATERIAL_TARGETS = ["//src/material"] + ["//src/material/%s" % p for p in MATERIAL_PACKAGES]
8282

8383
# List that references the sass libraries for each Material package. This can be used to create
8484
# the theming scss-bundle or to specify dependencies for the all-theme.scss file.
@@ -152,13 +152,14 @@ ROLLUP_GLOBALS.update({
152152
for p in MATERIAL_PACKAGES
153153
})
154154

155-
# Rollup globals for material experiemental subpackages, e.g., {"@angular/material-experimental/list": "ng.materialExperimental.list"}
155+
# Rollup globals for material experimental subpackages, e.g.,
156+
# {"@angular/material-experimental/list": "ng.materialExperimental.list"}
156157
ROLLUP_GLOBALS.update({
157-
"@angular/material-experiemntal/%s" % p: "ng.materialExperimental.%s" % p
158+
"@angular/material-experimental/%s" % p: "ng.materialExperimental.%s" % p
158159
for p in MATERIAL_EXPERIMENTAL_PACKAGES
159160
})
160161

161-
# UMD bundles for Angular packages and subpackges we depend on for development and testing.
162+
# UMD bundles for Angular packages and subpackages we depend on for development and testing.
162163
ANGULAR_LIBRARY_UMDS = [
163164
"@npm//:node_modules/@angular/animations/bundles/animations-browser.umd.js",
164165
"@npm//:node_modules/@angular/animations/bundles/animations.umd.js",

scripts/build-packages-dist.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env bash
2+
3+
set -u -e -o pipefail
4+
5+
# Go to project directory.
6+
cd $(dirname ${0})/..
7+
8+
# Either "legacy" (view engine) or "aot" (ivy)
9+
compileMode=${1:-"legacy"}
10+
11+
# Path to the bazel binary. By default uses "bazel" from the node modules
12+
# but developers can overwrite the binary though an environment variable.
13+
bazelBin=${BAZEL_BIN_PATH:-$(yarn bin bazel)}
14+
15+
echo "######################################"
16+
echo " building release packages"
17+
echo " mode: ${compileMode}"
18+
echo "######################################"
19+
echo ""
20+
21+
# Path to the output directory into which we copy the npm packages.
22+
destPath="dist/releases"
23+
24+
# Path to the bazel-bin directory.
25+
bazelBinPath=$(${bazelBin} info bazel-bin 2> /dev/null)
26+
27+
# List of targets that need to be built, e.g. //src/lib, //src/cdk, etc. Note we need to remove all
28+
# carriage returns because Bazel prints these on Windows. This breaks the Bash array parsing.
29+
targets=$(${bazelBin} query --output=label 'attr("tags", "\[.*release-package.*\]", //src/...)' \
30+
'intersect kind(".*_package", //src/...)' 2> /dev/null | tr -d "\r")
31+
32+
# Walk through each release package target and build it.
33+
for target in ${targets}; do
34+
echo -e "Building: ${target} ...\n"
35+
${bazelBin} build --config=release --define=compile=${compileMode} ${target}
36+
echo ""
37+
done
38+
39+
# Delete the distribution directory so that the output is guaranteed to be clean. Re-create
40+
# the empty directory so that we can copy the release packages into it later.
41+
rm -Rf ${destPath}
42+
mkdir -p ${destPath}
43+
44+
dirs=`echo "$targets" | sed -e 's/\/\/src\/\(.*\):npm_package/\1/'`
45+
46+
# Copy the package output for all built NPM packages into the dist directory.
47+
for pkg in ${dirs}; do
48+
pkgDir="${bazelBinPath}/src/${pkg}/npm_package"
49+
targetDir="${destPath}/${pkg}"
50+
51+
# The target directory for the Material package ("lib") should not be called "lib".
52+
# Until we rename the source directory to "material", we just rename it here.
53+
if [[ "${pkg}" == "lib" ]]; then
54+
targetDir="${destPath}/material"
55+
fi
56+
57+
if [[ -d ${pkgDir} ]]; then
58+
echo "> Copying package output to \"${targetDir}\".."
59+
rm -rf ${targetDir}
60+
cp -R ${pkgDir} ${targetDir}
61+
chmod -R u+w ${targetDir}
62+
fi
63+
done

src/cdk-experimental/BUILD.bazel

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ ng_package(
2323
srcs = ["package.json"],
2424
entry_point = ":public-api.ts",
2525
globals = ROLLUP_GLOBALS,
26-
# TODO(devversion): Use the npm package for publishing. Right now this is disabled because
27-
# we build using AOT for serving & testing, but the `ng_package` rule should not include factory
28-
# files.
29-
tags = ["manual"],
26+
tags = ["release-package"],
3027
deps = CDK_EXPERIMENTAL_TARGETS,
3128
)

src/cdk/testing/BUILD.bazel

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package(default_visibility = ["//visibility:public"])
22

3-
load("//tools:defaults.bzl", "ng_module")
3+
load("//tools:defaults.bzl", "markdown_to_html", "ng_module")
44

55
ng_module(
66
name = "testing",
@@ -13,3 +13,13 @@ ng_module(
1313
"@npm//@angular/core",
1414
],
1515
)
16+
17+
markdown_to_html(
18+
name = "overview",
19+
srcs = ["testing.md"],
20+
)
21+
22+
filegroup(
23+
name = "source-files",
24+
srcs = glob(["**/*.ts"]),
25+
)

src/cdk/testing/testing.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Testing infrastructure for Angular components.

src/material-experimental/BUILD.bazel

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ ng_package(
2222
srcs = ["package.json"],
2323
entry_point = ":public-api.ts",
2424
globals = ROLLUP_GLOBALS,
25-
# TODO(devversion): re-enable once we have set up the proper compiler for the ng_package
26-
tags = ["manual"],
25+
tags = ["release-package"],
2726
deps = [":material-experimental"],
2827
)

src/material-moment-adapter/BUILD.bazel

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ ng_package(
5353
srcs = ["package.json"],
5454
entry_point = ":public-api.ts",
5555
globals = ROLLUP_GLOBALS,
56-
# TODO(devversion): re-enable once we have set up the proper compiler for the ng_package
57-
tags = ["manual"],
56+
tags = ["release-package"],
5857
deps = [":material-moment-adapter"],
5958
)

src/material/BUILD.bazel

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ ng_package(
4646
entry_point_name = "material",
4747
globals = ROLLUP_GLOBALS,
4848
packages = ["//src/material/schematics:npm_package"],
49-
# TODO(devversion): Use the npm package for publishing. Right now this is disabled because
50-
# we build using AOT for serving & testing, but the `ng_package` rule should not include factory
51-
# files.
52-
tags = ["manual"],
49+
tags = ["release-package"],
5350
deps = MATERIAL_TARGETS,
5451
)

src/material/tsconfig-build.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
}
2020
},
2121
"files": [
22-
"public-api.ts",
22+
"index.ts",
2323
"typings.d.ts"
2424
],
2525
"angularCompilerOptions": {

src/youtube-player/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ ng_package(
3333
entry_point = ":public-api.ts",
3434
entry_point_name = "youtube-player",
3535
globals = ROLLUP_GLOBALS,
36+
tags = ["release-package"],
3637
deps = [":youtube-player"],
3738
)
3839

tools/gulp/tasks/ci.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,3 @@ task('ci:test', ['test:single-run'], () => process.exit(0));
1111
* release output to be built already.
1212
*/
1313
task('ci:aot', ['build-aot:no-release-build']);
14-
15-
/** Task that builds all release packages. */
16-
task('ci:build-release-packages', ['build-release-packages']);

tools/release/publish-release.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {bold, green, italic, red, yellow} from 'chalk';
2-
import {execSync} from 'child_process';
2+
import {spawnSync} from 'child_process';
33
import {readFileSync} from 'fs';
44
import {join} from 'path';
55
import {BaseReleaseTask} from './base-release-task';
@@ -171,14 +171,12 @@ class PublishReleaseTask extends BaseReleaseTask {
171171

172172
/** Builds all release packages that should be published. */
173173
private _buildReleasePackages() {
174-
const binDir = join(this.projectDir, 'node_modules/.bin');
175-
const spawnOptions = {cwd: binDir, stdio: 'inherit'};
174+
const buildScript = join(this.projectDir, 'scripts/build-packages-dist.sh');
176175

177176
// TODO(devversion): I'd prefer disabling the output for those, but it might be only
178177
// worth if we consider adding some terminal spinner library (like "ora").
179-
execSync('gulp clean', spawnOptions);
180-
execSync(`gulp ${releasePackages.map(name => `${name}:build-release`).join(' ')}`,
181-
spawnOptions);
178+
return spawnSync('bash', [buildScript],
179+
{cwd: this.projectDir, stdio: 'inherit', shell: true}).status === 0;
182180
}
183181

184182
/**

tools/release/release-output/check-package.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
} from './output-validations';
1212

1313
/** Glob that matches all JavaScript bundle files within a release package. */
14-
const releaseBundlesGlob = '+(esm5|esm2015|bundles)/*.js';
14+
const releaseBundlesGlob = '+(fesm5|fesm2015|esm5|esm2015|bundles)/*.js';
1515

1616
/** Glob that matches all TypeScript definition files within a release package. */
1717
const releaseTypeDefinitionsGlob = '**/*.d.ts';
@@ -32,7 +32,11 @@ export function checkReleasePackage(releasesPath: string, packageName: string):
3232
const packagePath = join(releasesPath, packageName);
3333
const failures = new Map() as PackageFailures;
3434
const addFailure = (message, filePath?) => {
35-
failures.set(message, (failures.get(message) || []).concat(filePath));
35+
const filePaths = failures.get(message) || [];
36+
if (filePath) {
37+
filePaths.push(filePath);
38+
}
39+
failures.set(message, filePaths);
3640
};
3741

3842
const bundlePaths = glob(releaseBundlesGlob, {cwd: packagePath, absolute: true});

tools/release/release-output/output-validations.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ export function checkReleaseBundle(bundlePath: string): string[] {
1818
const failures: string[] = [];
1919

2020
if (inlineStylesSourcemapRegex.exec(bundleContent) !== null) {
21-
failures.push('Found sourcemap references in component styles.');
21+
// TODO(devversion): check if we can omit the invalid source-map references
22+
// for built components. For now this check is temporarily disabled.
23+
// failures.push('Found sourcemap references in component styles.');
2224
}
2325

2426
if (externalReferencesRegex.exec(bundleContent) !== null) {

0 commit comments

Comments
 (0)