Add getCurrentVersion

This commit is contained in:
Michael B. Gale
2026-07-14 11:14:59 +01:00
parent 1b146d1b6a
commit 440cebc19d
2 changed files with 23 additions and 0 deletions

View File

@@ -12,6 +12,9 @@ export const REPO_ROOT = path.join(PR_CHECKS_DIR, "..");
/** The path of the file configuring which checks shouldn't be required. */
export const PR_CHECK_EXCLUDED_FILE = path.join(PR_CHECKS_DIR, "excluded.yml");
/** The path of the main `package.json`. */
export const PACKAGE_JSON = path.join(REPO_ROOT, "package.json");
/** The path to the esbuild metadata file. */
export const BUNDLE_METADATA_FILE = path.join(REPO_ROOT, "meta.json");

View File

@@ -1,7 +1,10 @@
#!/usr/bin/env npx tsx
import * as fs from "node:fs";
import { parseArgs } from "node:util";
import { PACKAGE_JSON } from "./config";
/** Placeholder changelog content for a new release. */
const EMPTY_CHANGELOG = `# CodeQL Action Changelog
@@ -46,6 +49,14 @@ export function getGitHubToken(): string {
throw new Error("Missing GitHub token. Set GITHUB_TOKEN or GH_TOKEN.");
}
/** Reads the current version from `package.json`. */
export function getCurrentVersion(): string | undefined {
const pkg: { version: string } = JSON.parse(
fs.readFileSync(PACKAGE_JSON, "utf8"),
);
return pkg.version;
}
interface MainOptions {
repositoryNwo: string;
sourceBranch: string;
@@ -102,6 +113,15 @@ async function main(): Promise<void> {
RELEASE_BRANCH_PREFIX,
"",
);
const currentVersion = getCurrentVersion();
if (!currentVersion) {
throw new Error("Failed to read current version from package.json");
}
const [, vMinor, vPatch] = currentVersion.split(".");
const version = `${targetBranchMajorVersion}.${vMinor}.${vPatch}`;
}
// Only call `main` if this script was run directly.