generated from actions/javascript-action
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.js
28 lines (27 loc) · 884 Bytes
/
version.js
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
let bumpVersion = async function (version, bump) {
if (typeof version !== 'string') {
throw new Error('version not a string');
}
if (bump !== 'major' && bump !== 'minor' && bump !== 'patch' && bump !== 'none') {
throw new Error("bump must be either 'major', 'minor', or 'patch'");
}
let versionParts = version.split('.');
if (versionParts.length < 3) {
throw new Error('version must be in the format x.y.z');
}
let major = parseInt(versionParts[0]);
let minor = parseInt(versionParts[1]);
let patch = parseInt(versionParts[2]);
if (bump === 'major') {
major++;
minor = 0;
patch = 0;
} else if (bump === 'minor') {
minor++;
patch = 0;
} else if (bump === 'patch') {
patch++;
}
return major + '.' + minor + '.' + patch;
};
module.exports = bumpVersion;