forked from jupyterlab/jupyterlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bumpversion.ts
105 lines (92 loc) · 2.82 KB
/
bumpversion.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
/*-----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/
import commander from 'commander';
import * as utils from './utils';
// Specify the program signature.
commander
.description('Update the version and publish')
.option('--dry-run', 'Dry run')
.option('--force', 'Force the upgrade')
.arguments('<spec>')
.action((spec: any, opts: any) => {
// Get the previous version.
const prev = utils.getPythonVersion();
// Make sure we have a valid version spec.
const options = ['major', 'minor', 'release', 'build'];
if (options.indexOf(spec) === -1) {
throw new Error(`Version spec must be one of: ${options}`);
}
if (
prev.indexOf('a') === -1 &&
prev.indexOf('rc') === -1 &&
spec === 'release'
) {
throw new Error('Use "major" or "minor" to switch back to alpha release');
}
if (
prev.indexOf('a') === -1 &&
prev.indexOf('rc') === -1 &&
spec === 'build'
) {
throw new Error('Cannot increment a build on a final release');
}
// Run pre-bump script.
utils.prebump();
// Handle dry runs.
if (opts.dryRun) {
utils.run(`bumpversion --dry-run --verbose ${spec}`);
return;
}
// If this is a major release during the alpha cycle, bump
// just the Python version.
if (prev.indexOf('a') !== -1 && spec === 'major') {
// Bump the version.
utils.run(`bumpversion ${spec}`);
// Run the post-bump script.
utils.postbump();
return;
}
// Determine the version spec to use for lerna.
let lernaVersion = 'preminor';
if (spec === 'build') {
lernaVersion = 'prerelease';
// a -> rc
} else if (spec === 'release' && prev.indexOf('a') !== -1) {
lernaVersion = 'prerelease --preid=rc';
// rc -> final
} else if (spec === 'release' && prev.indexOf('rc') !== -1) {
lernaVersion = 'patch';
}
let cmd = `lerna version -m \"New version\" --force-publish=* --no-push ${lernaVersion}`;
if (opts.force) {
cmd += ' --yes';
}
let oldVersion = utils.run(
'git rev-parse HEAD',
{
stdio: 'pipe',
encoding: 'utf8'
},
true
);
utils.run(cmd);
let newVersion = utils.run(
'git rev-parse HEAD',
{
stdio: 'pipe',
encoding: 'utf8'
},
true
);
if (oldVersion === newVersion) {
// lerna didn't version anything, so we assume the user aborted
throw new Error('Lerna aborted');
}
// Bump the version.
utils.run(`bumpversion ${spec}`);
// Run the post-bump script.
utils.postbump();
});
commander.parse(process.argv);