forked from Vonage/vonage-dotnet-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: add bump_version script to increase the version and generate a…
… changelog
- Loading branch information
Showing
3 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |