Skip to content

Commit 2e29f98

Browse files
authored
Setup release e2e infra. (#3632)
1 parent 038522b commit 2e29f98

File tree

10 files changed

+129
-12
lines changed

10 files changed

+129
-12
lines changed

cloudbuild.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ steps:
129129
id: 'e2e'
130130
args: ['./scripts/run-build.sh', 'e2e']
131131
waitFor: ['find-affected-packages']
132-
env: ['NIGHTLY=$_NIGHTLY']
132+
env: ['NIGHTLY=$_NIGHTLY','RELEASE=$_RELEASE']
133133

134134
# Inference API
135135
- name: 'gcr.io/cloud-builders/gcloud'

e2e/cloudbuild.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ steps:
66
entrypoint: 'bash'
77
id: 'verdaccio'
88
args: ['./scripts/start-verdaccio.sh']
9+
env: ['RELEASE=$_RELEASE']
910

1011
# Install packages.
1112
- name: 'node:10'

e2e/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@
6060
"lint": "tslint -p . -t verbose",
6161
"run-browserstack": "karma start --browserstack",
6262
"test": "./scripts/test.sh",
63-
"test-ci": "./scripts/test-ci.sh"
63+
"test-ci": "./scripts/test-ci.sh",
64+
"update-dependency": "ts-node ./scripts/update-dependency.ts"
6465
},
6566
"license": "Apache-2.0",
6667
"engines": {

e2e/scripts/publish-monorepo-ci.sh renamed to e2e/scripts/publish-tfjs-ci.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ set -x
3939

4040
# Go to root
4141
cd ../../
42-
root_path=$PWD
4342

4443
# Yarn in the top-level
4544
yarn
@@ -79,3 +78,8 @@ do
7978

8079
cd ..
8180
done
81+
82+
# Update e2e's package.json's all tfjs related packages to locally published
83+
# version.
84+
cd e2e
85+
yarn update-dependency --version=$RELEASE_VERSION

e2e/scripts/start-verdaccio.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,9 @@ if [[ "$RELEASE" = true ]]; then
7777
# Start the local NPM registry
7878
startLocalRegistry "$e2e_root_path"/scripts/verdaccio.yaml
7979

80-
# Publish the monorepo
81-
"$e2e_root_path"/scripts/publish-monorepo-ci.sh
82-
83-
# Todo(linazhao): Revise package.json to use the published version.
80+
# Publish the monorepo and update package.json tfjs dependency to the
81+
# published version.
82+
"$e2e_root_path"/scripts/publish-tfjs-ci.sh
8483

8584
# Cleanup
8685
cleanup

e2e/scripts/update-dependency.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright 2020 Google LLC. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
// =============================================================================
15+
16+
// Run this script from the e2e root directory:
17+
// yarn update-dependency --version=VERSION
18+
// Where VERSION is the pinned version to update to for tfjs package
19+
// dependencies.
20+
21+
import * as argparse from 'argparse';
22+
import * as fs from 'fs';
23+
24+
import {updateTFJSDependencyVersions} from '../../scripts/release-util';
25+
26+
const parser = new argparse.ArgumentParser();
27+
parser.addArgument('--version', {
28+
required: true,
29+
help: 'Use the git protocal rather than the http protocol when cloning repos.'
30+
});
31+
32+
const DEPENDENCY_LIST = [
33+
'tfjs-core', 'tfjs-converter', 'tfjs-layers', 'tfjs-backend-cpu',
34+
'tfjs-backend-webgl', 'tfjs-data', 'tfjs', 'tfjs-node'
35+
];
36+
37+
function main() {
38+
const args = parser.parseArgs();
39+
const latestVersion = args.version;
40+
41+
if (!latestVersion) {
42+
console.log('Please pass a valid version.');
43+
process.exit(1);
44+
}
45+
46+
const packageJsonFile = './package.json';
47+
if (!fs.existsSync(packageJsonFile)) {
48+
console.log(
49+
packageJsonFile,
50+
'does not exist. Please call this script from the e2e root directory.');
51+
process.exit(1);
52+
}
53+
54+
// Update the version.
55+
let pkg = fs.readFileSync(packageJsonFile, 'utf8');
56+
const parsedPkg = JSON.parse(pkg);
57+
58+
pkg = updateTFJSDependencyVersions(
59+
DEPENDENCY_LIST, pkg, parsedPkg, latestVersion);
60+
61+
fs.writeFileSync(packageJsonFile, pkg);
62+
63+
process.exit(0);
64+
}
65+
66+
main();

e2e/scripts/verdaccio.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
# path to a directory with all packages
1+
# Path to a directory with all packages.
22
storage: ./storage
3+
4+
# Maximum body size for a JSON document.
5+
max_body_size: 1000mb
6+
37
auth:
48
htpasswd:
59
file: ./htpasswd

scripts/release-tfjs.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ async function main() {
101101
}
102102
}
103103
}
104+
// Insert an empty release file at the root level, so that CI can use it to
105+
// set RELEASE flag.
106+
fs.writeFileSync('release', '');
104107

105108
// Use dev prefix to avoid branch being locked.
106109
const devBranchName = `dev_${releaseBranch}`;

scripts/release-util.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
1+
#!/usr/bin/env node
2+
/**
3+
* @license
4+
* Copyright 2020 Google LLC. All Rights Reserved.
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
* =============================================================================
17+
*/
18+
119
import chalk from 'chalk';
2-
import * as mkdirp from 'mkdirp';
20+
import mkdirp from 'mkdirp';
321
import * as readline from 'readline';
422
import * as shell from 'shelljs';
523

scripts/run-build.sh

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,31 @@
1414
# limitations under the License.
1515
# =============================================================================
1616

17+
# Echo every command being executed
18+
set -x
19+
20+
# Exit the script on any command with non 0 return code
1721
set -e
1822

23+
# Use the top level empty release file as a RELEASE flag.
24+
RELEASE=false
25+
if [[ -f "release" ]]; then
26+
$RELEASE=true
27+
fi
28+
1929
DIR=$1
20-
if [[ -f "$DIR/run-ci" || "$NIGHTLY" = true || $DIR == "e2e" ]]; then
21-
gcloud builds submit . --config=$DIR/cloudbuild.yml \
22-
--substitutions _NIGHTLY=$NIGHTLY
30+
if [[ $RELEASE = true ]]; then
31+
# Release flow: Only run e2e release test, ignore unit tests in all other
32+
# directories.
33+
if [[ $DIR = "e2e" ]]; then
34+
gcloud build submit . --config=$DIR/cloudbuild.yml \
35+
--substitutions _RELEASE=$RELEASE
36+
fi
37+
else
38+
# Regular flow: Only run changed packages plus e2e regular test.
39+
# Nightly flow: Run everything.
40+
if [[ -f "$DIR/run-ci" || $DIR == "e2e" || $NIGHTLY = true ]]; then
41+
gcloud builds submit . --config=$DIR/cloudbuild.yml \
42+
--substitutions _NIGHTLY=$NIGHTLY
43+
fi
2344
fi

0 commit comments

Comments
 (0)