forked from tensorflow/tfjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease-tfjs.ts
131 lines (107 loc) · 4.36 KB
/
release-tfjs.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env node
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
/**
* This script creates pull requests to make releases for all the TensorFlow.js
* packages.
*
* This script requires hub to be installed: https://hub.github.com/
*/
import * as argparse from 'argparse';
import chalk from 'chalk';
import * as fs from 'fs';
import * as shell from 'shelljs';
import {TMP_DIR, $, question, makeReleaseDir, createPR, TFJS_RELEASE_UNIT, updateTFJSDependencyVersions} from './release-util';
const parser = new argparse.ArgumentParser();
parser.addArgument('--git-protocol', {
action: 'storeTrue',
help: 'Use the git protocol rather than the http protocol when cloning repos.'
});
// Computes the default updated version (does a minor version update).
function getMinorUpdateVersion(version: string): string {
const versionSplit = version.split('.');
return [versionSplit[0], +versionSplit[1] + 1, '0'].join('.');
}
async function main() {
const args = parser.parseArgs();
const urlBase = args.git_protocol ? 'git@github.com:' : 'https://github.com/';
const dir = `${TMP_DIR}/tfjs`;
makeReleaseDir(dir);
// Guess release version from tfjs-core's latest version, with a minor update.
const latestVersion = $(`npm view @tensorflow/tfjs-core dist-tags.latest`);
const minorUpdateVersion = getMinorUpdateVersion(latestVersion);
let newVersion = minorUpdateVersion;
newVersion =
await question(`New version (leave empty for ${minorUpdateVersion}): `);
if (newVersion === '') {
newVersion = minorUpdateVersion;
}
// Get release candidate commit.
const commit = await question(
'Commit of release candidate (the last ' +
'successful nightly build): ');
if (commit === '') {
console.log(chalk.red('Commit cannot be empty.'));
process.exit(1);
}
// Create a release branch in remote.
$(`git clone ${urlBase}tensorflow/tfjs ${dir}`);
shell.cd(dir);
const releaseBranch = `tfjs_${newVersion}`;
console.log(chalk.magenta.bold(
`~~~ Creating new release branch ${releaseBranch} ~~~`));
$(`git checkout -b ${releaseBranch} ${commit}`);
$(`git push origin ${releaseBranch}`);
// Update version.
const phases = TFJS_RELEASE_UNIT.phases;
for (let i = 0; i < phases.length; i++) {
const packages = phases[i].packages;
const deps = phases[i].deps || [];
for (let i = 0; i < packages.length; i++) {
const packageName = packages[i];
shell.cd(packageName);
// Update the version.
const packageJsonPath = `${dir}/${packageName}/package.json`;
let pkg = `${fs.readFileSync(packageJsonPath)}`;
const parsedPkg = JSON.parse(`${pkg}`);
console.log(chalk.magenta.bold(`~~~ Processing ${packageName} ~~~`));
pkg = `${pkg}`.replace(
`"version": "${parsedPkg.version}"`, `"version": "${newVersion}"`);
pkg = updateTFJSDependencyVersions(deps, pkg, parsedPkg, newVersion);
fs.writeFileSync(packageJsonPath, pkg);
shell.cd('..');
// Make version for all packages other than tfjs-node-gpu.
if (packageName !== 'tfjs-node-gpu') {
$(`./scripts/make-version.js ${packageName}`);
}
}
}
// Use dev prefix to avoid branch being locked.
const devBranchName = `dev_${releaseBranch}`;
const message = `Update monorepo to ${newVersion}.`;
createPR(devBranchName, releaseBranch, message);
console.log(
'Done. FYI, this script does not publish to NPM. ' +
'Please publish by running ' +
'YARN_REGISTRY="https://registry.npmjs.org/" yarn publish-npm ' +
'after you merge the PR.' +
'Remember to delete the dev branch once PR is merged.' +
'Please remeber to update the website once you have released ' +
'a new package version.');
process.exit(0);
}
main();