forked from Vonage/vonage-dotnet-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bump_version.js
executable file
·91 lines (80 loc) · 3.17 KB
/
bump_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
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
const os = require("os"),
fileSystem = require("fs"),
xmlBuilder = require("xml2js"),
parseString = require("xml2js").parseString,
spawnSync = require("child_process").spawnSync;
class VersionUpgrade {
projectFile = "Vonage/Vonage.csproj";
_runRelease() {
console.log("Reading project file...");
fileSystem.readFile(this.projectFile, "utf-8", (err, data) => {
if (err) {
console.log(err);
return;
}
console.log("Parsing project data...");
parseString(data, (err, result) => {
if (err) {
console.log(err);
return;
}
console.log("Parsing successful");
this.UpdateProjectData(result);
console.log("Project data updated");
fileSystem.writeFile(this.projectFile, new xmlBuilder.Builder().buildObject(result), (err, res) => {
if (err) {
console.log(err);
return;
}
console.log("Successfully wrote project data");
this._executeCommand(`git add ${this.projectFile}`);
this._executeCommandWithArgs(`git`, ["commit", "-m", `docs: bump version to ${this.tag}`]);
this._executeCommand(`git tag -f ${this.tag}`);
this._executeCommand(`git cliff -o CHANGELOG.md`);
this._executeCommand(`git add CHANGELOG.md`);
this._executeCommandWithArgs(`git`, ["commit", "-m", `docs: generate changelog for ${this.tag}`]);
this._executeCommand(`git push`);
this._executeCommand(`git push origin ${this.tag} --force`);
});
});
})
}
UpdateProjectData(result) {
result.Project.PropertyGroup[0].Version[0] = this.version;
result.Project.PropertyGroup[0].PackageReleaseNotes[0] = `https://github.com/Vonage/vonage-dotnet-sdk/releases/tag/` + this.tag
}
_executeCommand(cmd, options) {
console.log(`executing: [${cmd}]`)
let ops = {
cwd: process.cwd(),
env: process.env,
stdio: 'pipe',
encoding: 'utf-8'
};
const INPUT = cmd.split(" "), TOOL = INPUT[0], ARGS = INPUT.slice(1)
console.log(String(spawnSync(TOOL, ARGS, ops).output));
}
_executeCommandWithArgs(cmd, args) {
console.log(`executing: [${cmd}]`)
let ops = {
cwd: process.cwd(),
env: process.env,
stdio: 'pipe',
encoding: 'utf-8'
};
console.log(String(spawnSync(cmd, args, ops).output));
}
upgrade(argv) {
console.log("Upgrading version...");
if (argv.length <= 2) {
console.log("The 'version' argument is missing.");
return;
}
this.version = argv[2];
this.tag = "v" + this.version;
console.log("Bumping version to " + this.version);
console.log("Bumping tag to " + this.tag);
this._runRelease();
}
}
new VersionUpgrade().upgrade(process.argv);