From e3d5e7bbf9edafc1a780bda0ba3ab1ae467687fb Mon Sep 17 00:00:00 2001 From: Fabrizio Balliano Date: Thu, 29 May 2025 23:19:04 +0100 Subject: [PATCH] Fix: Convert branch names to valid Composer dev-branch format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When building nightly packages, branch names like "develop" or "master" were being used directly as version strings, causing Satis to fail with "Invalid version string" errors. This fix ensures all branch names are converted to Composer's dev-branch format (e.g., "develop" → "dev-develop"). Changes: - package-modules.js: Update chooseNameAndVersion() to convert branch names from composer.json files or git refs to dev-branch format - package-modules.js: Update createComposerJsonOnlyPackage() to convert branch refs to dev-branch format for package filenames - release-branch-build-tools.js: Remove early conversion of branch refs that was causing issues with version determination The fix handles multiple scenarios: 1. When version comes from composer.json containing a branch name 2. When no version exists and git ref is a branch 3. When creating package filenames from branch refs This ensures compatibility with Composer's version constraints and allows Satis to properly process packages from development branches. --- src/package-modules.js | 41 +++++++++++++++++++++++++++++-- src/release-branch-build-tools.js | 10 ++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/package-modules.js b/src/package-modules.js index 680a747..ef70f28 100644 --- a/src/package-modules.js +++ b/src/package-modules.js @@ -94,6 +94,18 @@ function chooseNameAndVersion(magentoName, composerJson, ref, givenVersion) { const composerConfig = JSON.parse(composerJson); let {version, name} = composerConfig; version = givenVersion || version; + + // If no version is found and ref looks like a branch name, convert to dev-branch format + if (!version && ref && !ref.match(/^v?\d+\.\d+/)) { + version = `dev-${ref}`; + } + + // ALWAYS convert invalid version strings that are branch names to dev-branch format + // This catches cases where composer.json itself contains "develop" as version + if (version && !version.match(/^v?\d+\.\d+/) && !version.startsWith('dev-') && version.match(/^[a-zA-Z][a-zA-Z0-9_-]*$/)) { + version = `dev-${version}`; + } + if (!name) { throw { kind: 'NAME_UNKNOWN', @@ -166,7 +178,11 @@ async function determinePackageForRef(url, moduleDir, ref, options) { // Some refs do not have a version in the composer.json (e.g. the base package or the magento-composer-installer 0.4.0-beta1= // For those we use the ref as the version. This might be a problem, so for now we leave it as is. if (exception.kind === 'VERSION_UNKNOWN') { - return {[exception.name]: exception.ref} + // For branch names, convert to Composer dev- format + const version = exception.ref.match(/^v?(?:\d+\.){0,3}\d+(?:-[a-z]\w*|)$/i) + ? exception.ref + : `dev-${exception.ref}`; + return {[exception.name]: version} } console.log(`Unable to determine name and/or version for ${magentoName || url} in ${ref}: ${exception.message || exception}`); return {}; @@ -375,7 +391,18 @@ async function createComposerJsonOnlyPackage(url, ref, name, transform, release) isExecutable: false, }]; - const packageFilepath = archiveFilePath(name, release || ref); + // Convert branch names to proper dev-branch format for Composer + let versionForFilename = release || ref; + if (!release && ref && !ref.match(/^v?\d+\.\d+/)) { + versionForFilename = `dev-${ref}`; + } + + // Also check if versionForFilename looks like a branch name and convert it + if (versionForFilename && !versionForFilename.match(/^v?\d+\.\d+/) && !versionForFilename.startsWith('dev-')) { + versionForFilename = `dev-${versionForFilename}`; + } + + const packageFilepath = archiveFilePath(name, versionForFilename); return {packageFilepath, files} } @@ -587,6 +614,11 @@ async function determineMetaPackageFromRepoDir(url, dir, ref, release) { throw {message: `Unable find package name and in composer.json for metapackage ${ref} in ${dir}`} } version = release || version || ref; + + // If no version is found and ref looks like a branch name, convert to dev-branch format + if (!release && !composerConfig.version && ref && !ref.match(/^v?\d+\.\d+/)) { + version = `dev-${ref}`; + } return {[name]: version} } @@ -613,6 +645,11 @@ async function createMetaPackageFromRepoDir(url, dir, ref, options) { throw {message: `Unable find package name and in composer.json for metapackage ${ref} in ${dir}`} } version = release || dependencyVersions[name] || version || ref; + + // If no version is found and ref looks like a branch name, convert to dev-branch format + if (!release && !dependencyVersions[name] && !composerConfig.version && ref && !ref.match(/^v?\d+\.\d+/)) { + version = `dev-${ref}`; + } // Ensure version is set on composer config because not all repos provide the version in composer.json (e.g. // page-builder) and it is required by satis to be able to use artifact repositories. diff --git a/src/release-branch-build-tools.js b/src/release-branch-build-tools.js index 1c1c71c..2923107 100644 --- a/src/release-branch-build-tools.js +++ b/src/release-branch-build-tools.js @@ -81,6 +81,11 @@ async function getPackageVersionsForBuildInstructions(buildInstructions, suffix) } function addSuffixToVersion(version, buildSuffix) { + // Don't add suffix to dev- branch versions + if (version.startsWith('dev-')) { + return version; + } + const match = version.match(/(?(?:[\d]+\.?){1,4})(?-[^+]+)?(?\+.+)?/) if (match) { return `${match.groups.versions}-a${buildSuffix}${match.groups.legacy ? match.groups.legacy : ''}` @@ -100,6 +105,11 @@ function transformVersionsToNightlyBuildVersion(baseVersion, buildSuffix) { } function calcNightlyBuildPackageBaseVersion(version) { + // Handle dev- branch versions (e.g., dev-develop, dev-master) + if (version.startsWith('dev-')) { + return version; // Return as-is, it's already a valid Composer branch version + } + if (! version.match(/^v?(?:\d+\.){0,3}\d+(?:-[a-z]\w*|)$/i)) { throw Error(`Unable to determine branch release version for input version "${version}"`) }