From 440cebc19d9dcbeba6efc43259871f58d1fc9a97 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Tue, 14 Jul 2026 11:14:59 +0100 Subject: [PATCH] Add `getCurrentVersion` --- pr-checks/config.ts | 3 +++ pr-checks/update-release-branch.ts | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/pr-checks/config.ts b/pr-checks/config.ts index 75cd0a151..9458ef780 100644 --- a/pr-checks/config.ts +++ b/pr-checks/config.ts @@ -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"); diff --git a/pr-checks/update-release-branch.ts b/pr-checks/update-release-branch.ts index 00c7c4f72..dcfec68bc 100755 --- a/pr-checks/update-release-branch.ts +++ b/pr-checks/update-release-branch.ts @@ -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 { 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.