Skip to content

Commit 8c2d9e0

Browse files
authored
Move core to its own folder and enable Monorepo Build (#1876)
Move core to its own folder `tfjs-core` and enable Monorepo build system where each package build runs only if the PR touches a file in that package folder. DEV
1 parent f135c5a commit 8c2d9e0

File tree

369 files changed

+5389
-5093
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

369 files changed

+5389
-5093
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ bazel-out/
1313
yalc.lock
1414
.rpt2_cache/
1515
package/
16+
*/diff
1617

1718
tfjs-backend-wasm/dist
1819
tfjs-backend-wasm/wasm-out

cloudbuild.yml

+25-76
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,34 @@
11
steps:
2-
#
3-
# Core tests
4-
#
5-
# install dependencies
2+
# Install top-level deps.
63
- name: 'node:10'
74
entrypoint: 'yarn'
85
id: 'yarn'
96
args: ['install']
10-
# build
11-
- name: 'node:10'
12-
entrypoint: 'yarn'
13-
id: 'build'
14-
args: ['build-ci']
15-
waitFor: ['yarn']
16-
# run unit tests
17-
- name: 'node:10'
18-
entrypoint: 'yarn'
19-
id: 'test'
20-
args: ['test-ci']
21-
waitFor: ['build']
22-
env: ['BROWSERSTACK_USERNAME=deeplearnjs1']
23-
secretEnv: ['BROWSERSTACK_KEY']
24-
# Run integration tests of other packages against core
25-
- name: 'node:10'
26-
entrypoint: 'yarn'
27-
id: 'test-integration'
28-
args: ['test-integration']
29-
waitFor: ['build']
30-
env: ['BROWSERSTACK_USERNAME=deeplearnjs1', 'NIGHTLY=$_NIGHTLY']
31-
secretEnv: ['BROWSERSTACK_KEY']
32-
# bundle size check
33-
- name: 'node:10'
34-
entrypoint: 'yarn'
35-
id: 'test-bundle-size'
36-
args: ['test-bundle-size']
37-
waitFor: ['yarn']
38-
# test doc snippets
39-
- name: 'node:10'
40-
entrypoint: 'yarn'
41-
args: ['test-snippets']
42-
id: 'test-snippets'
43-
waitFor: ['yarn']
44-
# test Async backends
45-
- name: 'node:10'
46-
entrypoint: 'yarn'
47-
id: 'test-async-backends'
48-
args: ['test-async-backends-ci']
49-
waitFor: ['build']
50-
#
51-
# WebGPU tests
52-
#
53-
- name: 'node:10'
54-
entrypoint: 'yarn'
55-
id: 'test-webgpu'
56-
dir: 'tfjs-webgpu/'
57-
args: ['test-ci']
58-
# Wait for parent because subfolders look at parent node_modules.
59-
waitFor: ['yarn']
60-
#
61-
# React-Native tests
62-
#
7+
8+
# Run diff to find modified files in each folder.
639
- name: 'node:10'
6410
entrypoint: 'yarn'
65-
id: 'test-react-native'
66-
dir: 'tfjs-react-native/'
67-
args: ['test-ci']
68-
# Wait for parent because subfolders look at parent node_modules.
11+
id: 'diff'
12+
args: ['diff']
6913
waitFor: ['yarn']
70-
env: ['BROWSERSTACK_USERNAME=deeplearnjs1']
71-
secretEnv: ['BROWSERSTACK_KEY']
7214

73-
# General configuration
74-
secrets:
75-
- kmsKeyName: projects/learnjs-174218/locations/global/keyRings/tfjs/cryptoKeys/enc
76-
secretEnv:
77-
BROWSERSTACK_KEY: CiQAkwyoIW0LcnxymzotLwaH4udVTQFBEN4AEA5CA+a3+yflL2ASPQAD8BdZnGARf78MhH5T9rQqyz9HNODwVjVIj64CTkFlUCGrP1B2HX9LXHWHLmtKutEGTeFFX9XhuBzNExA=
78-
timeout: 1800s
79-
logsBucket: 'gs://tfjs-build-logs'
80-
substitutions:
81-
_NIGHTLY: ''
82-
options:
83-
logStreamingOption: 'STREAM_ON'
84-
machineType: 'N1_HIGHCPU_8'
85-
substitution_option: 'ALLOW_LOOSE'
15+
# Core.
16+
- name: 'gcr.io/cloud-builders/gcloud'
17+
entrypoint: 'bash'
18+
id: 'core'
19+
args: ['./scripts/run-build.sh', 'tfjs-core']
20+
waitFor: ['diff']
21+
22+
# WebGPU.
23+
- name: 'gcr.io/cloud-builders/gcloud'
24+
entrypoint: 'bash'
25+
id: 'webgpu'
26+
args: ['./scripts/run-build.sh', 'tfjs-webgpu']
27+
waitFor: ['diff']
28+
29+
# React Native.
30+
- name: 'gcr.io/cloud-builders/gcloud'
31+
entrypoint: 'bash'
32+
id: 'react-native'
33+
args: ['./scripts/run-build.sh', 'tfjs-react-native']
34+
waitFor: ['diff']

package.json

+2-83
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,9 @@
11
{
2-
"name": "@tensorflow/tfjs-core",
3-
"version": "1.2.7",
4-
"description": "Hardware-accelerated JavaScript library for machine intelligence",
5-
"private": false,
6-
"main": "dist/index.js",
7-
"jsdelivr": "dist/tf-core.min.js",
8-
"unpkg": "dist/tf-core.min.js",
9-
"types": "dist/index.d.ts",
10-
"jsnext:main": "dist/tf-core.esm.js",
11-
"module": "dist/tf-core.esm.js",
12-
"miniprogram": "dist/miniprogram",
13-
"engines": {
14-
"yarn": ">= 1.3.2"
15-
},
16-
"repository": {
17-
"type": "git",
18-
"url": "https://github.com/tensorflow/tfjs-core.git"
19-
},
20-
"license": "Apache-2.0",
212
"devDependencies": {
22-
"@bazel/bazel": "^0.24.0",
23-
"@bazel/typescript": "^0.27.8",
24-
"@types/jasmine": "~2.5.53",
25-
"@types/node": "~9.6.0",
26-
"@types/node-fetch": "~2.1.2",
27-
"browserify": "~16.2.3",
283
"clang-format": "~1.2.4",
29-
"jasmine": "~3.1.0",
30-
"jasmine-core": "~3.1.0",
31-
"karma": "~4.2.0",
32-
"karma-browserify": "~6.0.0",
33-
"karma-browserstack-launcher": "~1.4.0",
34-
"karma-chrome-launcher": "~2.2.0",
35-
"karma-jasmine": "~1.1.0",
36-
"karma-typescript": "~4.1.1",
37-
"npm-run-all": "~4.1.3",
38-
"rimraf": "~2.6.2",
39-
"rollup": "~1.9.0",
40-
"rollup-plugin-commonjs": "~9.3.4",
41-
"rollup-plugin-node-resolve": "~3.4.0",
42-
"rollup-plugin-terser": "~4.0.4",
43-
"rollup-plugin-typescript2": "~0.20.1",
44-
"rollup-plugin-visualizer": "~1.1.1",
45-
"shelljs": "~0.8.3",
46-
"ts-node": "~7.0.0",
47-
"tslint": "~5.11.0",
48-
"tslint-no-circular-imports": "~0.5.0",
49-
"typescript": "3.3.3333",
50-
"watchify": "~3.11.1",
51-
"yalc": "~1.0.0-pre.21",
52-
"yargs": "~13.2.2"
4+
"shelljs": "~0.8.3"
535
},
546
"scripts": {
55-
"build-ci": "./scripts/enumerate-tests.js --ci && tsc",
56-
"build": "./scripts/enumerate-tests.js && tsc",
57-
"build:bazel": "bazel build //...",
58-
"build-npm": "./scripts/build-npm.sh",
59-
"build-test-snippets": "yarn tsc --project ./scripts/test_snippets/tsconfig.json",
60-
"format-all": "clang-format -i -style=Google --glob=src/**/*.ts",
61-
"link-local": "yalc link",
62-
"publish-local": "rimraf dist/ && yarn build && rollup -c && yalc push",
63-
"lint": "tslint -p . -t verbose",
64-
"coverage": "KARMA_COVERAGE=1 karma start --browsers='Chrome' --singleRun",
65-
"test": "karma start",
66-
"test-webworker": "karma start --worker",
67-
"run-browserstack": "karma start --browserstack",
68-
"test-bundle-size": "./scripts/test-bundle-size.js",
69-
"test-node": "rimraf dist/ && tsc && node dist/test_node.js",
70-
"test-node-ci": "node dist/test_node.js",
71-
"test-async-backends": "rimraf dist/ && tsc && node dist/test_async_backends.js",
72-
"test-async-backends-ci": "node dist/test_async_backends.js",
73-
"test-integration": "./scripts/test-integration.js",
74-
"test-ci": "./scripts/test-ci.sh",
75-
"test-snippets": "ts-node ./scripts/test_snippets/test_snippets.ts"
76-
},
77-
"dependencies": {
78-
"@types/offscreencanvas": "~2019.3.0",
79-
"@types/seedrandom": "2.4.27",
80-
"@types/webgl-ext": "0.0.30",
81-
"@types/webgl2": "0.0.4",
82-
"node-fetch": "~2.1.2",
83-
"seedrandom": "2.4.3"
84-
},
85-
"browser": {
86-
"node-fetch": false,
87-
"util": false,
88-
"crypto": false
7+
"diff": "./scripts/diff.js"
898
}
909
}

scripts/diff.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env node
2+
// Copyright 2019 Google LLC. All Rights Reserved.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
// =============================================================================
16+
17+
const {exec} = require('./test-util');
18+
const {readdirSync, statSync, writeFileSync} = require('fs');
19+
const {join} = require('path');
20+
21+
const CLONE_PATH = 'clone';
22+
23+
const dirs = readdirSync('.').filter(f => {
24+
return f !== 'node_modules' && f !== '.git' && statSync(f).isDirectory();
25+
});
26+
27+
exec(
28+
`git clone --depth=1 --single-branch ` +
29+
`https://github.com/tensorflow/tfjs-core.git ${CLONE_PATH}`);
30+
31+
32+
dirs.forEach(dir => {
33+
const diffCmd = `diff -rq ${CLONE_PATH}/${dir}/ ./${dir}/`;
34+
const diffOutput = exec(diffCmd, {silent: true}, true).stdout.trim();
35+
36+
if (diffOutput !== '') {
37+
console.log(`${dir} has modified files.`);
38+
writeFileSync(join(dir, 'diff'), diffOutput);
39+
} else {
40+
console.log(`No modified files found in ${dir}`);
41+
}
42+
});

scripts/run-build.sh

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2019 Google LLC. All Rights Reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
# =============================================================================
16+
17+
set -e
18+
19+
DIR=$1
20+
if test -f "$DIR/diff"; then
21+
gcloud builds submit . --config=$DIR/cloudbuild.yml
22+
fi
File renamed without changes.

.bazelrc tfjs-core/.bazelrc

File renamed without changes.

.npmignore tfjs-core/.npmignore

File renamed without changes.

.npmrc tfjs-core/.npmrc

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

BUILD.bazel tfjs-core/BUILD.bazel

File renamed without changes.

README.md tfjs-core/README.md

File renamed without changes.
File renamed without changes.

tfjs-core/cloudbuild.yml

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
steps:
2+
# Install common dependencies.
3+
- name: 'node:10'
4+
id: 'yarn-common'
5+
entrypoint: 'yarn'
6+
args: ['install']
7+
8+
# Install tfjs-core dependencies.
9+
- name: 'node:10'
10+
dir: 'tfjs-core'
11+
id: 'yarn'
12+
entrypoint: 'yarn'
13+
args: ['install']
14+
waitFor: ['yarn-common']
15+
16+
# Build
17+
- name: 'node:10'
18+
dir: 'tfjs-core'
19+
id: 'build'
20+
entrypoint: 'yarn'
21+
args: ['build-ci']
22+
waitFor: ['yarn']
23+
24+
# Run unit tests.
25+
- name: 'node:10'
26+
dir: 'tfjs-core'
27+
id: 'test'
28+
entrypoint: 'yarn'
29+
args: ['test-ci']
30+
waitFor: ['build']
31+
env: ['BROWSERSTACK_USERNAME=deeplearnjs1']
32+
secretEnv: ['BROWSERSTACK_KEY']
33+
34+
# Run integration tests of other packages against core.
35+
- name: 'node:10'
36+
dir: 'tfjs-core'
37+
id: 'test-integration'
38+
entrypoint: 'yarn'
39+
args: ['test-integration']
40+
waitFor: ['build']
41+
env: ['BROWSERSTACK_USERNAME=deeplearnjs1', 'NIGHTLY=$_NIGHTLY']
42+
secretEnv: ['BROWSERSTACK_KEY']
43+
44+
# bundle size check
45+
- name: 'node:10'
46+
dir: 'tfjs-core'
47+
id: 'test-bundle-size'
48+
entrypoint: 'yarn'
49+
args: ['test-bundle-size']
50+
waitFor: ['yarn']
51+
52+
# test doc snippets
53+
- name: 'node:10'
54+
dir: 'tfjs-core'
55+
id: 'test-snippets'
56+
entrypoint: 'yarn'
57+
args: ['test-snippets']
58+
waitFor: ['yarn']
59+
60+
# test Async backends
61+
- name: 'node:10'
62+
dir: 'tfjs-core'
63+
id: 'test-async-backends'
64+
entrypoint: 'yarn'
65+
args: ['test-async-backends-ci']
66+
waitFor: ['build']
67+
68+
# General configuration
69+
secrets:
70+
- kmsKeyName: projects/learnjs-174218/locations/global/keyRings/tfjs/cryptoKeys/enc
71+
secretEnv:
72+
BROWSERSTACK_KEY: CiQAkwyoIW0LcnxymzotLwaH4udVTQFBEN4AEA5CA+a3+yflL2ASPQAD8BdZnGARf78MhH5T9rQqyz9HNODwVjVIj64CTkFlUCGrP1B2HX9LXHWHLmtKutEGTeFFX9XhuBzNExA=
73+
timeout: 1800s
74+
logsBucket: 'gs://tfjs-build-logs'
75+
substitutions:
76+
_NIGHTLY: ''
77+
options:
78+
logStreamingOption: 'STREAM_ON'
79+
machineType: 'N1_HIGHCPU_8'
80+
substitution_option: 'ALLOW_LOOSE'
File renamed without changes.

0 commit comments

Comments
 (0)