forked from finos/perspective
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version_python.js
56 lines (50 loc) · 1.9 KB
/
version_python.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
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
/******************************************************************************
*
* Copyright (c) 2019, the Perspective Authors.
*
* This file is part of the Perspective library, distributed under the terms of
* the Apache License 2.0. The full license can be found in the LICENSE file.
*
*/
const resolve = require("path").resolve;
const execute = require("./script_utils").execute;
const VERSION = require("../packages/perspective/package.json").version;
const ENDINGS = ["alpha", "beta", "rc"];
/**
* Converts a npm-spec version string into a bumpversion-spec version string.
*
* Example:
* - "1.0.0" => "1, 0, 0"
* - "0.3.0-alpha.1" => "0, 3, 0, alpha, 1"
* - "0.3.5-rc.3" => "0, 3, 5, rc, 3"
*
* @param {string} version
*/
const parse_version = function(version) {
let release_level = "final";
let serial = 0;
let has_ending = false;
for (let e of ENDINGS) {
if (version.includes(e)) {
has_ending = true;
}
}
// "0.3.0-rc.1" => ["0", "3", "0-rc", "1"]
let split = version.split(".");
let patch = split[2];
// remove dash from alpha/beta/rc
if (has_ending) {
let optional_versions = split[split.length - 2].split("-");
patch = optional_versions[0];
release_level = optional_versions[1];
if (release_level === "rc") {
release_level = "candidate"; // 'candidate' maps into bumpversion, 'rc' does not
}
serial = split[split.length - 1];
}
return `${split[0]}, ${split[1]}, ${patch}, '${release_level}', ${serial}`;
};
console.log(`Bumping \`perspective-python\` version to ${VERSION}`);
const python_path = resolve(__dirname, "..", "python", "perspective");
const version_path = resolve(__dirname, "..", "python", "perspective", "perspective", "core", "_version.py");
execute(`cd ${python_path} && bumpversion --allow-dirty --new-version "${parse_version(VERSION)}" ${version_path}`);