mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-16 06:18:42 +02:00
Add tool to bump version & create PR
This includes a tool to update the various files in the repo that need to change when a version increments. It also includes a workflow to trigger the action manually, passing it a version & a changelog url. It'll update the values, build the app, build the doc, make a commit in a branch, and create a pull request to merge this stuff back into dev.
This commit is contained in:
@@ -34,3 +34,15 @@ npm install
|
||||
export GITHUB_API_TOKEN=tokenhere # this could go into your .bashrc or .profile etc.
|
||||
node index.js --from=31ebdbb139981a604bd0e8fc1e364916762e11b9 > ../bump-version/changes.md
|
||||
```
|
||||
|
||||
## Bump Version
|
||||
|
||||
Used to update the game's various version identifier.
|
||||
Requires pandoc installed to convert .md to .rst
|
||||
|
||||
**Usage**
|
||||
```sh
|
||||
cd ./tools/bump-version
|
||||
npm install
|
||||
node index.js --version=1.10.3 --versionNumber=10 < changes.md
|
||||
```
|
||||
|
||||
2
tools/bump-version/.gitignore
vendored
Normal file
2
tools/bump-version/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
node_modules
|
||||
*.md
|
||||
118
tools/bump-version/index.js
Normal file
118
tools/bump-version/index.js
Normal file
@@ -0,0 +1,118 @@
|
||||
// import { Octokit } from "@octokit/rest";
|
||||
import commandLineArgs from "command-line-args";
|
||||
|
||||
import fs from 'fs/promises';
|
||||
import { readFileSync } from 'fs';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import pandoc from 'node-pandoc';
|
||||
|
||||
// https://github.com/75lb/command-line-args
|
||||
const optionDefinitions = [
|
||||
{ name: 'version', alias: 'v', type: String, required: true },
|
||||
{ name: 'versionNumber', alias: 'n', type: Number },
|
||||
{ name: 'versionDescription', alias: 'd', type: String },
|
||||
{ name: 'changelog', alias: 'l', type: String },
|
||||
];
|
||||
|
||||
const cliArgs = commandLineArgs(optionDefinitions);
|
||||
|
||||
const appPaths = {};
|
||||
appPaths.root = path.join(path.dirname(fileURLToPath(import.meta.url)), "../..");
|
||||
appPaths.mainPackage = path.join(appPaths.root, "./package.json");
|
||||
appPaths.electronPackage = path.join(appPaths.root, "./electron/package.json");
|
||||
appPaths.constants = path.join(appPaths.root, "./src/Constants.ts");
|
||||
appPaths.sphinxConf = path.join(appPaths.root, "./doc/source/conf.py");
|
||||
appPaths.sphinxChangelog = path.join(appPaths.root, "./doc/source/changelog.rst");
|
||||
|
||||
async function main(version, versionNumber, changelog) {
|
||||
console.log(`Updating app files to match v${version}`);
|
||||
|
||||
const [ major, minor ]= version.split('.');
|
||||
const shortVersion = `${major}.${minor}`;
|
||||
const modifiedMainPackage = (await fs.readFile(appPaths.mainPackage, 'utf8')).
|
||||
replace(/(^\s*"version":\s)"(.*)",$/m, `$1"${version}",`);
|
||||
await fs.writeFile(appPaths.mainPackage, modifiedMainPackage);
|
||||
console.log(`Modified ${appPaths.mainPackage}`);
|
||||
|
||||
const modifiedElectronPackage = (await fs.readFile(appPaths.electronPackage, 'utf8')).
|
||||
replace(/(^\s*"version":\s)"(.*)",$/m, `$1"${version}",`);
|
||||
await fs.writeFile(appPaths.electronPackage, modifiedElectronPackage);
|
||||
console.log(`Modified ${appPaths.electronPackage}`);
|
||||
|
||||
let modifiedConstants = (await fs.readFile(appPaths.constants, 'utf8')).
|
||||
replace(/(^\s*?VersionString:\s)"(.*)",/m, `$1"${version}",`);
|
||||
modifiedConstants = modifiedConstants.
|
||||
replace(/(^\s*?VersionNumber:\s)(.*),/m, `$1${versionNumber},`);
|
||||
|
||||
if (changelog.trim() !== '') {
|
||||
let htmlChangelog = '';
|
||||
try {
|
||||
htmlChangelog = await transform(changelog, 'html');
|
||||
console.log('Converted markdown changelog to html')
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
const paddedChangelog = htmlChangelog.split('\n').
|
||||
map((line) => (line.trim() !== '' ? ' ' + line : '')).
|
||||
join('\n').replaceAll('`', '\\`');
|
||||
|
||||
modifiedConstants = modifiedConstants.
|
||||
replace(/(^\s*?LatestUpdate:\s`\n)(.*)`,$/ms, `$1${paddedChangelog}\n` + "`,");
|
||||
}
|
||||
await fs.writeFile(appPaths.constants, modifiedConstants);
|
||||
console.log(`Modified ${appPaths.constants}`);
|
||||
|
||||
let modifiedSphinxConfig = (await fs.readFile(appPaths.sphinxConf, 'utf8')).
|
||||
replace(/(^version = ')(.*)'$/m, `$1${shortVersion}'`);
|
||||
modifiedSphinxConfig = modifiedSphinxConfig.
|
||||
replace(/(^release = ')(.*)'$/m, `$1${version}'`);
|
||||
await fs.writeFile(appPaths.sphinxConf, modifiedSphinxConfig);
|
||||
console.log(`Modified ${appPaths.sphinxConf}`);
|
||||
|
||||
if (changelog.trim() !== '') {
|
||||
let modifiedSphinxChangelog = await fs.readFile(appPaths.sphinxChangelog, 'utf8');
|
||||
const lines = modifiedSphinxChangelog.split('\n');
|
||||
let rstChangelog = '';
|
||||
try {
|
||||
rstChangelog = await transform(changelog, 'rst');
|
||||
console.log('Converted markdown changelog to rst')
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
lines.splice(5, 0, rstChangelog);
|
||||
modifiedSphinxChangelog = lines.join('\n');
|
||||
await fs.writeFile(appPaths.sphinxChangelog, modifiedSphinxChangelog);
|
||||
console.log(`Modified ${appPaths.sphinxChangelog}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function transform(markdown, format) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const args = `-f markdown -t ${format}`;
|
||||
pandoc(markdown, args, (error, rst) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
resolve(rst);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function getChangelog() {
|
||||
// Read from stdin
|
||||
// https://stackoverflow.com/a/56012724
|
||||
try {
|
||||
return readFileSync(0, 'utf-8').replace('\r\n', '\n');
|
||||
} catch (error) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
getChangelog().then((changes) => {
|
||||
main(cliArgs.version, cliArgs.versionNumber, changes).then(() => console.log('Done'));
|
||||
})
|
||||
|
||||
109
tools/bump-version/package-lock.json
generated
Normal file
109
tools/bump-version/package-lock.json
generated
Normal file
@@ -0,0 +1,109 @@
|
||||
{
|
||||
"name": "update-version",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "update-version",
|
||||
"version": "1.0.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"command-line-args": "^5.2.0",
|
||||
"node-pandoc": "^0.3.0"
|
||||
}
|
||||
},
|
||||
"node_modules/array-back": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/array-back/-/array-back-3.1.0.tgz",
|
||||
"integrity": "sha512-TkuxA4UCOvxuDK6NZYXCalszEzj+TLszyASooky+i742l9TqsOdYCMJJupxRic61hwquNtppB3hgcuq9SVSH1Q==",
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/command-line-args": {
|
||||
"version": "5.2.0",
|
||||
"resolved": "https://registry.npmjs.org/command-line-args/-/command-line-args-5.2.0.tgz",
|
||||
"integrity": "sha512-4zqtU1hYsSJzcJBOcNZIbW5Fbk9BkjCp1pZVhQKoRaWL5J7N4XphDLwo8aWwdQpTugxwu+jf9u2ZhkXiqp5Z6A==",
|
||||
"dependencies": {
|
||||
"array-back": "^3.1.0",
|
||||
"find-replace": "^3.0.0",
|
||||
"lodash.camelcase": "^4.3.0",
|
||||
"typical": "^4.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/find-replace": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/find-replace/-/find-replace-3.0.0.tgz",
|
||||
"integrity": "sha512-6Tb2myMioCAgv5kfvP5/PkZZ/ntTpVK39fHY7WkWBgvbeE+VHd/tZuZ4mrC+bxh4cfOZeYKVPaJIZtZXV7GNCQ==",
|
||||
"dependencies": {
|
||||
"array-back": "^3.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/lodash.camelcase": {
|
||||
"version": "4.3.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz",
|
||||
"integrity": "sha1-soqmKIorn8ZRA1x3EfZathkDMaY="
|
||||
},
|
||||
"node_modules/node-pandoc": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/node-pandoc/-/node-pandoc-0.3.0.tgz",
|
||||
"integrity": "sha1-1GV3zQpyr0FTU/y4oBF622JC+cg="
|
||||
},
|
||||
"node_modules/typical": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/typical/-/typical-4.0.0.tgz",
|
||||
"integrity": "sha512-VAH4IvQ7BDFYglMd7BPRDfLgxZZX4O4TFcRDA6EN5X7erNJJq+McIEp8np9aVtxrCJ6qx4GTYVfOWNjcqwZgRw==",
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"array-back": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/array-back/-/array-back-3.1.0.tgz",
|
||||
"integrity": "sha512-TkuxA4UCOvxuDK6NZYXCalszEzj+TLszyASooky+i742l9TqsOdYCMJJupxRic61hwquNtppB3hgcuq9SVSH1Q=="
|
||||
},
|
||||
"command-line-args": {
|
||||
"version": "5.2.0",
|
||||
"resolved": "https://registry.npmjs.org/command-line-args/-/command-line-args-5.2.0.tgz",
|
||||
"integrity": "sha512-4zqtU1hYsSJzcJBOcNZIbW5Fbk9BkjCp1pZVhQKoRaWL5J7N4XphDLwo8aWwdQpTugxwu+jf9u2ZhkXiqp5Z6A==",
|
||||
"requires": {
|
||||
"array-back": "^3.1.0",
|
||||
"find-replace": "^3.0.0",
|
||||
"lodash.camelcase": "^4.3.0",
|
||||
"typical": "^4.0.0"
|
||||
}
|
||||
},
|
||||
"find-replace": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/find-replace/-/find-replace-3.0.0.tgz",
|
||||
"integrity": "sha512-6Tb2myMioCAgv5kfvP5/PkZZ/ntTpVK39fHY7WkWBgvbeE+VHd/tZuZ4mrC+bxh4cfOZeYKVPaJIZtZXV7GNCQ==",
|
||||
"requires": {
|
||||
"array-back": "^3.0.1"
|
||||
}
|
||||
},
|
||||
"lodash.camelcase": {
|
||||
"version": "4.3.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz",
|
||||
"integrity": "sha1-soqmKIorn8ZRA1x3EfZathkDMaY="
|
||||
},
|
||||
"node-pandoc": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/node-pandoc/-/node-pandoc-0.3.0.tgz",
|
||||
"integrity": "sha1-1GV3zQpyr0FTU/y4oBF622JC+cg="
|
||||
},
|
||||
"typical": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/typical/-/typical-4.0.0.tgz",
|
||||
"integrity": "sha512-VAH4IvQ7BDFYglMd7BPRDfLgxZZX4O4TFcRDA6EN5X7erNJJq+McIEp8np9aVtxrCJ6qx4GTYVfOWNjcqwZgRw=="
|
||||
}
|
||||
}
|
||||
}
|
||||
16
tools/bump-version/package.json
Normal file
16
tools/bump-version/package.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "update-version",
|
||||
"version": "1.0.0",
|
||||
"type": "module",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"command-line-args": "^5.2.0",
|
||||
"node-pandoc": "^0.3.0"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user