-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
release-bump.ts
138 lines (119 loc) · 3.88 KB
/
release-bump.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
132
133
134
135
136
137
138
/* -----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/
/**
* Inspired by: https://github.com/jupyterlab/jupyterlab/blob/master/buildutils/src/bumpversion.ts
*/
import * as utils from '@jupyterlab/buildutils';
import commander from 'commander';
import { getPythonVersion, postbump } from './utils';
// Specify the program signature.
commander
.description('Update the version')
.option('--dry-run', 'Dry run')
.option('--force', 'Force the upgrade')
.option('--skip-commit', 'Whether to skip commit changes')
.arguments('<spec>')
.action((spec: any, opts: any) => {
// Get the previous version.
const prev = getPythonVersion();
const isFinal = /\d+\.\d+\.\d+$/.test(prev);
// Whether to commit after bumping
const commit = opts.skipCommit !== true;
// for "next", determine whether to use "patch" or "build"
if (spec === 'next') {
spec = isFinal ? 'patch' : 'build';
}
// For patch, defer to `patch:release` command
if (spec === 'patch') {
let cmd = 'jlpm run release:patch';
if (opts.force) {
cmd += ' --force';
}
if (!commit) {
cmd += ' --skip-commit';
}
utils.run(cmd);
process.exit(0);
}
// 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 (isFinal && 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) {
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(`hatch version ${spec}`);
// Run the post-bump script.
postbump(commit);
return;
}
// Determine the version spec to use for lerna.
let lernaVersion = 'preminor';
if (spec === 'build') {
lernaVersion = 'prerelease';
// a -> b
} else if (spec === 'release' && prev.indexOf('a') !== -1) {
lernaVersion = 'prerelease --preid=beta';
// b -> rc
} else if (spec === 'release' && prev.indexOf('b') !== -1) {
lernaVersion = 'prerelease --preid=rc';
// rc -> final
} else if (spec === 'release' && prev.indexOf('rc') !== -1) {
lernaVersion = 'patch';
}
if (lernaVersion === 'preminor') {
lernaVersion += ' --preid=alpha';
}
let cmd = `jlpm run lerna version --force-publish --no-push --no-git-tag-version ${lernaVersion}`;
if (opts.force) {
cmd += ' --yes';
}
// For a preminor release, we bump 10 minor versions so that we do
// not conflict with versions during minor releases of the top
// level package.
if (lernaVersion === 'preminor') {
for (let i = 0; i < 10; i++) {
utils.run(cmd);
}
} else {
utils.run(cmd);
}
// Bump the version.
let pySpec = spec;
if (spec === 'release') {
if (prev.indexOf('a') !== -1) {
pySpec = 'beta';
} else if (prev.indexOf('b') !== -1) {
pySpec = 'rc';
} else if (prev.indexOf('rc') !== -1) {
pySpec = 'patch';
} else {
pySpec = 'alpha';
}
} else if (spec === 'build') {
if (prev.indexOf('a') !== -1) {
pySpec = 'a';
} else if (prev.indexOf('b') !== -1) {
pySpec = 'b';
} else if (prev.indexOf('rc') !== -1) {
pySpec = 'rc';
}
}
utils.run(`hatch version ${pySpec}`);
// Run the post-bump script.
postbump(commit);
});
commander.parse(process.argv);