-
Notifications
You must be signed in to change notification settings - Fork 0
/
tag-release.js
73 lines (67 loc) · 2.15 KB
/
tag-release.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const
promisify = require("util").promisify,
mkdirp = require("mkdirp").sync,
path = require("path"),
exec = promisify(require("child_process").exec);
async function createZip(version, baseFolder, runtime, append) {
let src = path.join(baseFolder, runtime, "publish", "bitsplat");
if (append) {
src += append;
}
const zip = `bitsplat-${runtime}-${version}.zip`;
console.log(`create release zip: ${zip}`);
await exec(`zip -j -9 release/${zip} "${src}"`);
}
class Version {
constructor(tag) {
const parts = tag.replace(/^v/, "").split(".");
this.tag = tag;
this.major = parseInt(parts[0]);
this.minor = parseInt(parts[1] || 0);
this.patch = parseInt(parts[2] || 0);
}
compare(otherVersion) {
return ["major", "minor", "patch"].reduce(
(acc, cur) => acc || this._comparePart(cur, otherVersion),
0
);
}
_comparePart(partName, otherVersion) {
return this[partName] - otherVersion[partName];
}
}
(async function () {
const
execResult = await exec("git tag"),
lines = execResult.stdout.trim().split("\n").map(l => l.trim()).sort(),
versions = lines.map(line => new Version(line)),
latestVersion = versions.sort((a, b) => b.compare(a))[0],
major = latestVersion.major,
minor = latestVersion.minor,
next = `${major}.${minor + 1}`,
cmd1 = `git add -A :/`,
cmd2 = `git commit -m ":bookmark: release v${next}"`,
cmd3 = `git tag v${next}`;
mkdirp("release");
try {
// TODO: should update the .csproj version
// TODO: switch to simple-git instead of running commands
if (!process.env.SKIP_COMMIT) {
console.log(`commit release v${next}`);
await exec(cmd1);
await exec(cmd2);
}
console.log(`tagging at v${next}`);
await exec(cmd3);
console.log(`pushing...`);
await exec("git push");
await exec("git push --tags");
const baseFolder = path.join("src", "bitsplat", "bin", "Release", "netcoreapp3.1");
await createZip(next, baseFolder, "linux-x64");
await createZip(next, baseFolder, "osx-x64");
await createZip(next, baseFolder, "win-x64", ".exe");
} catch (e) {
console.error(e);
process.exit(1)
}
})();