1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/packages/bump-version-for-cron/src/index.ts
Janne Savolainen b5e2deffc2
Fix command line argument not being passed to lerna (#7210)
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
2023-02-22 14:13:13 +02:00

57 lines
1.3 KiB
TypeScript

import * as child_process from "child_process";
import { readFile, writeFile } from "fs/promises";
import semver from "semver";
import { promisify } from "util";
import arg from "arg";
const { SemVer } = semver;
const exec = promisify(child_process.exec);
const args = arg({
"--path": String,
});
const versionJsonPath = args["--path"];
if (!versionJsonPath) {
throw new Error("Missing required '--path'");
}
try {
const packageJson = JSON.parse(await readFile(versionJsonPath, "utf-8"));
const { stdout: gitRevParseOutput } = await exec("git rev-parse --short HEAD");
const currentHash = gitRevParseOutput.trim();
const currentVersion = new SemVer(packageJson.version);
const partialVersion = `${currentVersion.major}.${currentVersion.minor}.${currentVersion.patch}`;
const prereleasePart = `cron.${currentHash}`;
const newVersion = `${partialVersion}-${prereleasePart}`;
await writeFile(
versionJsonPath,
JSON.stringify(
{
...packageJson,
version: newVersion,
},
null,
2,
),
);
if (process.env.GITHUB_OUTPUT) {
await writeFile(process.env.GITHUB_OUTPUT, `VERSION=${newVersion}`, {
flag: "a+",
});
}
await exec(`npm run bump-version ${newVersion} -- --yes`);
} catch (error) {
console.error(error);
process.exit(1);
}