From 69809a0266ecbc67326288db517dcc4bb3a2b7b6 Mon Sep 17 00:00:00 2001 From: TED Vortex Date: Wed, 11 Nov 2026 21:34:09 +0200 Subject: [PATCH 1/4] fix: a release no longer fails when the version file already holds its version (EAI-475) --- release.config.js | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/release.config.js b/release.config.js index ec267cf..e4a388f 100644 --- a/release.config.js +++ b/release.config.js @@ -1,4 +1,4 @@ -const { existsSync } = require("node:fs"); +const { existsSync, readFileSync } = require("node:fs"); const { execSync } = require('node:child_process'); const log = require("npmlog"); @@ -131,42 +131,37 @@ if (pkgExists && SR_DISABLE_NPM === undefined) { }); } +const oneVersionLine = (file, pattern) => { + const found = (readFileSync(file, "utf8").match(new RegExp(pattern, "gm")) || []).length; + if (found !== 1) { + throw new Error(`${file} needs exactly one version line, found ${found}`); + } +}; + const denoExists = existsSync("./deno.json"); if (denoExists && SR_DISABLE_DENO === undefined) { + oneVersionLine("deno.json", `"version":.*".*"`); addPlugin("semantic-release-replace-plugin", { "replacements": [{ "files": [ "deno.json" ], "from": `"version":.*".*"`, - "to": `"version": "\${nextRelease.version}"`, - "results": [{ - "file": "deno.json", - "hasChanged": true, - "numMatches": 1, - "numReplacements": 1 - }], - "countMatches": true + "to": `"version": "\${nextRelease.version}"` }] }); } const pythonExists = existsSync("./pyproject.toml"); if (pythonExists && SR_DISABLE_PYTHON === undefined) { + oneVersionLine("pyproject.toml", `^version.*=.*".*"$`); addPlugin("semantic-release-replace-plugin", { "replacements": [{ "files": [ "pyproject.toml" ], "from": `^version.*=.*".*"$`, - "to": `version = "\${nextRelease.version}"`, - "results": [{ - "file": "pyproject.toml", - "hasChanged": true, - "numMatches": 1, - "numReplacements": 1 - }], - "countMatches": true + "to": `version = "\${nextRelease.version}"` }] }); From 0fcf65fb14e1889193a10a2b7b14afd86f706541 Mon Sep 17 00:00:00 2001 From: TED Vortex Date: Wed, 11 Nov 2026 21:39:26 +0200 Subject: [PATCH 2/4] fix: no version-line check at load, only the dropped results check (EAI-475) --- release.config.js | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/release.config.js b/release.config.js index e4a388f..0a87f7a 100644 --- a/release.config.js +++ b/release.config.js @@ -1,4 +1,4 @@ -const { existsSync, readFileSync } = require("node:fs"); +const { existsSync } = require("node:fs"); const { execSync } = require('node:child_process'); const log = require("npmlog"); @@ -131,16 +131,8 @@ if (pkgExists && SR_DISABLE_NPM === undefined) { }); } -const oneVersionLine = (file, pattern) => { - const found = (readFileSync(file, "utf8").match(new RegExp(pattern, "gm")) || []).length; - if (found !== 1) { - throw new Error(`${file} needs exactly one version line, found ${found}`); - } -}; - const denoExists = existsSync("./deno.json"); if (denoExists && SR_DISABLE_DENO === undefined) { - oneVersionLine("deno.json", `"version":.*".*"`); addPlugin("semantic-release-replace-plugin", { "replacements": [{ "files": [ @@ -154,7 +146,6 @@ if (denoExists && SR_DISABLE_DENO === undefined) { const pythonExists = existsSync("./pyproject.toml"); if (pythonExists && SR_DISABLE_PYTHON === undefined) { - oneVersionLine("pyproject.toml", `^version.*=.*".*"$`); addPlugin("semantic-release-replace-plugin", { "replacements": [{ "files": [ From 99f309e4a2a3d4b0ba05a269a40995c5b610765c Mon Sep 17 00:00:00 2001 From: TED Vortex Date: Wed, 11 Nov 2026 21:47:57 +0200 Subject: [PATCH 3/4] fix: check for the version line and warn without it, then replace the version (EAI-475) --- release.config.js | 131 +++++++++++++++++++++++++--------------------- 1 file changed, 71 insertions(+), 60 deletions(-) diff --git a/release.config.js b/release.config.js index 0a87f7a..b63a428 100644 --- a/release.config.js +++ b/release.config.js @@ -1,4 +1,4 @@ -const { existsSync } = require("node:fs"); +const { existsSync, readFileSync } = require("node:fs"); const { execSync } = require('node:child_process'); const log = require("npmlog"); @@ -131,73 +131,84 @@ if (pkgExists && SR_DISABLE_NPM === undefined) { }); } +const hasVersionLine = (file, pattern) => + (readFileSync(file, "utf8").match(new RegExp(pattern, "gm")) || []).length === 1; + const denoExists = existsSync("./deno.json"); if (denoExists && SR_DISABLE_DENO === undefined) { - addPlugin("semantic-release-replace-plugin", { - "replacements": [{ - "files": [ - "deno.json" - ], - "from": `"version":.*".*"`, - "to": `"version": "\${nextRelease.version}"` - }] - }); + if (!hasVersionLine("deno.json", `"version":.*".*"`)) { + log.warn(`deno.json has no single "version" line, so its version is not updated`); + } else { + addPlugin("semantic-release-replace-plugin", { + "replacements": [{ + "files": [ + "deno.json" + ], + "from": `"version":.*".*"`, + "to": `"version": "\${nextRelease.version}"` + }] + }); + } } const pythonExists = existsSync("./pyproject.toml"); if (pythonExists && SR_DISABLE_PYTHON === undefined) { - addPlugin("semantic-release-replace-plugin", { - "replacements": [{ - "files": [ - "pyproject.toml" - ], - "from": `^version.*=.*".*"$`, - "to": `version = "\${nextRelease.version}"` - }] - }); + if (!hasVersionLine("pyproject.toml", `^version.*=.*".*"$`)) { + log.warn(`pyproject.toml has no single version line, so its version is not updated`); + } else { + addPlugin("semantic-release-replace-plugin", { + "replacements": [{ + "files": [ + "pyproject.toml" + ], + "from": `^version.*=.*".*"$`, + "to": `version = "\${nextRelease.version}"` + }] + }); - const uvLockExists = existsSync("./uv.lock"); - if (uvLockExists) { - let pyProjectName; - try { - const pyproject = execSync(`cat pyproject.toml`, { encoding: "utf8", stdio: "pipe" }); - const projectTable = pyproject.match(/\[project\]([\s\S]*?)(?=\n\[|$)/); - const nameMatch = projectTable && projectTable[1].match(/\n\s*name\s*=\s*"([^"]+)"/); - pyProjectName = nameMatch && nameMatch[1]; - } catch (e) { - log.warn(`Unable to read package name from pyproject.toml`); - log.error(e); - } + const uvLockExists = existsSync("./uv.lock"); + if (uvLockExists) { + let pyProjectName; + try { + const pyproject = execSync(`cat pyproject.toml`, { encoding: "utf8", stdio: "pipe" }); + const projectTable = pyproject.match(/\[project\]([\s\S]*?)(?=\n\[|$)/); + const nameMatch = projectTable && projectTable[1].match(/\n\s*name\s*=\s*"([^"]+)"/); + pyProjectName = nameMatch && nameMatch[1]; + } catch (e) { + log.warn(`Unable to read package name from pyproject.toml`); + log.error(e); + } - if (!pyProjectName) { - log.warn(`No package name found in pyproject.toml [project] table, skipping uv.lock update`); - } else { - log.info(`uv.lock update enabled for package "${pyProjectName}"`); - const escapedName = pyProjectName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); - addPlugin("semantic-release-replace-plugin", { - "replacements": [{ - "files": [ - "uv.lock" - ], - "from": `(\\[\\[package\\]\\]\\nname = "${escapedName}"\\nversion = ")[^"]*(")`, - "to": (...args) => { - const context = args[args.length - 1]; - const [, prefix, suffix] = args; - const pep440 = context.nextRelease.version.replace( - /-(alpha|beta|rc)\.?(\d*)/i, - (_m, label, num) => ({ alpha: "a", beta: "b", rc: "rc" })[label.toLowerCase()] + (num || "0") - ); - return `${prefix}${pep440}${suffix}`; - }, - "results": [{ - "file": "uv.lock", - "hasChanged": true, - "numMatches": 1, - "numReplacements": 1 - }], - "countMatches": true - }] - }); + if (!pyProjectName) { + log.warn(`No package name found in pyproject.toml [project] table, skipping uv.lock update`); + } else { + log.info(`uv.lock update enabled for package "${pyProjectName}"`); + const escapedName = pyProjectName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); + addPlugin("semantic-release-replace-plugin", { + "replacements": [{ + "files": [ + "uv.lock" + ], + "from": `(\\[\\[package\\]\\]\\nname = "${escapedName}"\\nversion = ")[^"]*(")`, + "to": (...args) => { + const context = args[args.length - 1]; + const [, prefix, suffix] = args; + const pep440 = context.nextRelease.version.replace( + /-(alpha|beta|rc)\.?(\d*)/i, + (_m, label, num) => ({ alpha: "a", beta: "b", rc: "rc" })[label.toLowerCase()] + (num || "0") + ); + return `${prefix}${pep440}${suffix}`; + }, + "results": [{ + "file": "uv.lock", + "hasChanged": true, + "numMatches": 1, + "numReplacements": 1 + }], + "countMatches": true + }] + }); + } } } } From 6491d8b3331bf67455643cf136d26d1d3fc38f5a Mon Sep 17 00:00:00 2001 From: TED Vortex Date: Wed, 11 Nov 2026 21:51:45 +0200 Subject: [PATCH 4/4] fix: only the pyproject.toml version replacement waits on its version line (EAI-475) --- release.config.js | 84 +++++++++++++++++++++++------------------------ 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/release.config.js b/release.config.js index b63a428..3b179b4 100644 --- a/release.config.js +++ b/release.config.js @@ -165,50 +165,50 @@ if (pythonExists && SR_DISABLE_PYTHON === undefined) { "to": `version = "\${nextRelease.version}"` }] }); + } - const uvLockExists = existsSync("./uv.lock"); - if (uvLockExists) { - let pyProjectName; - try { - const pyproject = execSync(`cat pyproject.toml`, { encoding: "utf8", stdio: "pipe" }); - const projectTable = pyproject.match(/\[project\]([\s\S]*?)(?=\n\[|$)/); - const nameMatch = projectTable && projectTable[1].match(/\n\s*name\s*=\s*"([^"]+)"/); - pyProjectName = nameMatch && nameMatch[1]; - } catch (e) { - log.warn(`Unable to read package name from pyproject.toml`); - log.error(e); - } + const uvLockExists = existsSync("./uv.lock"); + if (uvLockExists) { + let pyProjectName; + try { + const pyproject = execSync(`cat pyproject.toml`, { encoding: "utf8", stdio: "pipe" }); + const projectTable = pyproject.match(/\[project\]([\s\S]*?)(?=\n\[|$)/); + const nameMatch = projectTable && projectTable[1].match(/\n\s*name\s*=\s*"([^"]+)"/); + pyProjectName = nameMatch && nameMatch[1]; + } catch (e) { + log.warn(`Unable to read package name from pyproject.toml`); + log.error(e); + } - if (!pyProjectName) { - log.warn(`No package name found in pyproject.toml [project] table, skipping uv.lock update`); - } else { - log.info(`uv.lock update enabled for package "${pyProjectName}"`); - const escapedName = pyProjectName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); - addPlugin("semantic-release-replace-plugin", { - "replacements": [{ - "files": [ - "uv.lock" - ], - "from": `(\\[\\[package\\]\\]\\nname = "${escapedName}"\\nversion = ")[^"]*(")`, - "to": (...args) => { - const context = args[args.length - 1]; - const [, prefix, suffix] = args; - const pep440 = context.nextRelease.version.replace( - /-(alpha|beta|rc)\.?(\d*)/i, - (_m, label, num) => ({ alpha: "a", beta: "b", rc: "rc" })[label.toLowerCase()] + (num || "0") - ); - return `${prefix}${pep440}${suffix}`; - }, - "results": [{ - "file": "uv.lock", - "hasChanged": true, - "numMatches": 1, - "numReplacements": 1 - }], - "countMatches": true - }] - }); - } + if (!pyProjectName) { + log.warn(`No package name found in pyproject.toml [project] table, skipping uv.lock update`); + } else { + log.info(`uv.lock update enabled for package "${pyProjectName}"`); + const escapedName = pyProjectName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); + addPlugin("semantic-release-replace-plugin", { + "replacements": [{ + "files": [ + "uv.lock" + ], + "from": `(\\[\\[package\\]\\]\\nname = "${escapedName}"\\nversion = ")[^"]*(")`, + "to": (...args) => { + const context = args[args.length - 1]; + const [, prefix, suffix] = args; + const pep440 = context.nextRelease.version.replace( + /-(alpha|beta|rc)\.?(\d*)/i, + (_m, label, num) => ({ alpha: "a", beta: "b", rc: "rc" })[label.toLowerCase()] + (num || "0") + ); + return `${prefix}${pep440}${suffix}`; + }, + "results": [{ + "file": "uv.lock", + "hasChanged": true, + "numMatches": 1, + "numReplacements": 1 + }], + "countMatches": true + }] + }); } } }