Skip to content

Commit

Permalink
build: add bump_version script to increase the version and generate a…
Browse files Browse the repository at this point in the history
… changelog
  • Loading branch information
Tr00d committed Mar 7, 2024
1 parent 3a4f0d5 commit a902c76
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Vonage.sln
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
cliff.toml = cliff.toml
OPENTOK_TO_VONAGE_MIGRATION.md = OPENTOK_TO_VONAGE_MIGRATION.md
MIGRATION_v7.0.0.md = MIGRATION_v7.0.0.md
bump_version.js = bump_version.js
.gitignore = .gitignore
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vonage", "Vonage\Vonage.csproj", "{41EF17C9-8D2E-4C7B-B2EE-3BD1A4CC1A1B}"
Expand Down
90 changes: 90 additions & 0 deletions bump_version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
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 out to xml file");
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._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);
17 changes: 17 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "vonage-dotnet-sdk",
"version": "1.0.0",
"description": "",
"main": "bump_version.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://github.com/Vonage/vonage-dotnet-sdk.git"
},
"private": true,
"dependencies": {
"xml2js": "^0.6.2"
}
}

0 comments on commit a902c76

Please sign in to comment.