2019-12-30 02:41:09 -05:00
|
|
|
#!/usr/bin/env node
|
|
|
|
"use strict";
|
|
|
|
|
2020-01-03 01:45:28 -05:00
|
|
|
const {readFileSync, writeFileSync} = require('fs');
|
|
|
|
const {spawnSync} = require('child_process');
|
|
|
|
const {join} = require('path');
|
2019-12-30 02:41:09 -05:00
|
|
|
|
|
|
|
const NEW_VERSION = process.argv[2];
|
|
|
|
|
2020-01-03 01:45:28 -05:00
|
|
|
const cmd = (...cfg) => {
|
|
|
|
const command = cfg[0];
|
|
|
|
const args = cfg.slice(1);
|
|
|
|
const {
|
|
|
|
workingDir,
|
|
|
|
throwOnBadStatus = true,
|
|
|
|
throwOnSignal = true,
|
|
|
|
captureStdio = false,
|
|
|
|
throwOnStdErr = false,
|
|
|
|
} = typeof args[args.length - 1] == "object" ? args.pop() : {};
|
|
|
|
|
|
|
|
const throwErr = msg => {
|
|
|
|
throw new Error(`${msg}\n ${command} ${args.join(' ')}`);
|
|
|
|
};
|
|
|
|
|
|
|
|
const {status, signal, error, stdout, stderr} = spawnSync(command, args.map(String), {
|
|
|
|
cwd: workingDir,
|
|
|
|
stdio: ['ignore', captureStdio ? 'pipe' : 'inherit', captureStdio || throwOnStdErr ? 'pipe' : 'inherit'],
|
|
|
|
encoding: 'utf8',
|
|
|
|
});
|
2020-01-01 05:01:55 -05:00
|
|
|
if (error) {
|
2020-01-03 01:45:28 -05:00
|
|
|
throwErr(error.message);
|
|
|
|
}
|
|
|
|
if (throwOnSignal && signal) {
|
|
|
|
throwErr(`Command exited with signal ${signal}`);
|
2020-01-01 05:01:55 -05:00
|
|
|
}
|
2020-01-03 01:45:28 -05:00
|
|
|
if (throwOnBadStatus && status !== 0) {
|
|
|
|
throwErr(`Command exited with status ${status}`);
|
2020-01-01 05:01:55 -05:00
|
|
|
}
|
2020-01-03 01:45:28 -05:00
|
|
|
if (throwOnStdErr && stderr) {
|
|
|
|
throwErr(`stderr: ${stderr}`);
|
|
|
|
}
|
|
|
|
return {status, signal, stdout, stderr};
|
2020-01-01 05:01:55 -05:00
|
|
|
};
|
|
|
|
|
2019-12-30 02:41:09 -05:00
|
|
|
const replaceInFile = (path, pattern, replacement) => writeFileSync(path, readFileSync(path, "utf8").replace(pattern, replacement));
|
|
|
|
|
2020-01-03 01:48:02 -05:00
|
|
|
if (cmd('git', 'status', '--porcelain', {throwOnStderr: true, captureStdio: true}).stdout) {
|
2020-01-03 01:45:28 -05:00
|
|
|
throw new Error(`Working directory not clean`);
|
|
|
|
}
|
|
|
|
|
2020-01-19 03:19:33 -05:00
|
|
|
for (const f of ["Cargo.toml", "nodejs/native/Cargo.toml", "java/Cargo.toml", "python/Cargo.toml", "ruby/Cargo.toml"]) {
|
2020-01-01 05:01:55 -05:00
|
|
|
replaceInFile(f, /^version = "\d+\.\d+\.\d+"\s*$/m, `version = "${NEW_VERSION}"`);
|
2019-12-30 02:41:09 -05:00
|
|
|
}
|
|
|
|
|
2020-01-19 03:19:33 -05:00
|
|
|
for (const f of ["README.md", "nodejs/native/Cargo.toml", "java/Cargo.toml", "python/Cargo.toml", "ruby/Cargo.toml"]) {
|
2020-01-01 05:01:55 -05:00
|
|
|
replaceInFile(f, /^hyperbuild = "\d+\.\d+\.\d+"\s*$/m, `hyperbuild = "${NEW_VERSION}"`);
|
2019-12-30 02:41:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
for (const f of ["nodejs/package.json"]) {
|
2020-01-01 05:01:55 -05:00
|
|
|
replaceInFile(f, /^(\s*)"version": "\d+\.\d+\.\d+",\s*$/m, `$1"version": "${NEW_VERSION}",`);
|
2019-12-30 02:41:09 -05:00
|
|
|
}
|
2020-01-01 04:47:49 -05:00
|
|
|
|
2020-01-19 03:19:33 -05:00
|
|
|
for (const f of ["ruby/hyperbuild.gemspec"]) {
|
|
|
|
replaceInFile(f, /^(\s*spec\.version\s*=\s*)"\d+\.\d+\.\d+"\s*$/m, `$1"${NEW_VERSION}",`);
|
|
|
|
}
|
|
|
|
|
2020-01-18 00:54:52 -05:00
|
|
|
for (const f of ["java/pom.xml"]) {
|
|
|
|
replaceInFile(f, /(<artifactId>hyperbuild<\/artifactId>\s*<version>)\d+\.\d+\.\d+(<\/version>)/, `$1${NEW_VERSION}$2`);
|
|
|
|
}
|
|
|
|
|
2020-01-01 04:47:49 -05:00
|
|
|
for (const f of ["README.md"]) {
|
2020-01-01 05:01:55 -05:00
|
|
|
replaceInFile(f, /(wilsonl\.in\/hyperbuild\/bin\/)\d+\.\d+\.\d+/g, `$1${NEW_VERSION}`);
|
2020-01-01 04:47:49 -05:00
|
|
|
}
|
2020-01-01 05:01:55 -05:00
|
|
|
|
|
|
|
cmd('cargo', 'generate-lockfile');
|
2020-01-03 01:45:28 -05:00
|
|
|
cmd('git', 'add', '-A');
|
|
|
|
cmd('git', 'commit', '-m', NEW_VERSION);
|
|
|
|
cmd('git', 'tag', '-a', `v${NEW_VERSION}`, '-m', '');
|
|
|
|
cmd('cargo', 'publish');
|
|
|
|
cmd('npm', 'publish', {workingDir: join(__dirname, 'nodejs')});
|
2020-01-15 07:05:13 -05:00
|
|
|
cmd('git', 'push', '--follow-tags');
|