Skip to content

Commit e3d5e7b

Browse files
committed
Fix: Convert branch names to valid Composer dev-branch format
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.
1 parent f9cec98 commit e3d5e7b

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

src/package-modules.js

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,18 @@ function chooseNameAndVersion(magentoName, composerJson, ref, givenVersion) {
9494
const composerConfig = JSON.parse(composerJson);
9595
let {version, name} = composerConfig;
9696
version = givenVersion || version;
97+
98+
// If no version is found and ref looks like a branch name, convert to dev-branch format
99+
if (!version && ref && !ref.match(/^v?\d+\.\d+/)) {
100+
version = `dev-${ref}`;
101+
}
102+
103+
// ALWAYS convert invalid version strings that are branch names to dev-branch format
104+
// This catches cases where composer.json itself contains "develop" as version
105+
if (version && !version.match(/^v?\d+\.\d+/) && !version.startsWith('dev-') && version.match(/^[a-zA-Z][a-zA-Z0-9_-]*$/)) {
106+
version = `dev-${version}`;
107+
}
108+
97109
if (!name) {
98110
throw {
99111
kind: 'NAME_UNKNOWN',
@@ -166,7 +178,11 @@ async function determinePackageForRef(url, moduleDir, ref, options) {
166178
// 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=
167179
// For those we use the ref as the version. This might be a problem, so for now we leave it as is.
168180
if (exception.kind === 'VERSION_UNKNOWN') {
169-
return {[exception.name]: exception.ref}
181+
// For branch names, convert to Composer dev- format
182+
const version = exception.ref.match(/^v?(?:\d+\.){0,3}\d+(?:-[a-z]\w*|)$/i)
183+
? exception.ref
184+
: `dev-${exception.ref}`;
185+
return {[exception.name]: version}
170186
}
171187
console.log(`Unable to determine name and/or version for ${magentoName || url} in ${ref}: ${exception.message || exception}`);
172188
return {};
@@ -375,7 +391,18 @@ async function createComposerJsonOnlyPackage(url, ref, name, transform, release)
375391
isExecutable: false,
376392
}];
377393

378-
const packageFilepath = archiveFilePath(name, release || ref);
394+
// Convert branch names to proper dev-branch format for Composer
395+
let versionForFilename = release || ref;
396+
if (!release && ref && !ref.match(/^v?\d+\.\d+/)) {
397+
versionForFilename = `dev-${ref}`;
398+
}
399+
400+
// Also check if versionForFilename looks like a branch name and convert it
401+
if (versionForFilename && !versionForFilename.match(/^v?\d+\.\d+/) && !versionForFilename.startsWith('dev-')) {
402+
versionForFilename = `dev-${versionForFilename}`;
403+
}
404+
405+
const packageFilepath = archiveFilePath(name, versionForFilename);
379406
return {packageFilepath, files}
380407
}
381408

@@ -587,6 +614,11 @@ async function determineMetaPackageFromRepoDir(url, dir, ref, release) {
587614
throw {message: `Unable find package name and in composer.json for metapackage ${ref} in ${dir}`}
588615
}
589616
version = release || version || ref;
617+
618+
// If no version is found and ref looks like a branch name, convert to dev-branch format
619+
if (!release && !composerConfig.version && ref && !ref.match(/^v?\d+\.\d+/)) {
620+
version = `dev-${ref}`;
621+
}
590622

591623
return {[name]: version}
592624
}
@@ -613,6 +645,11 @@ async function createMetaPackageFromRepoDir(url, dir, ref, options) {
613645
throw {message: `Unable find package name and in composer.json for metapackage ${ref} in ${dir}`}
614646
}
615647
version = release || dependencyVersions[name] || version || ref;
648+
649+
// If no version is found and ref looks like a branch name, convert to dev-branch format
650+
if (!release && !dependencyVersions[name] && !composerConfig.version && ref && !ref.match(/^v?\d+\.\d+/)) {
651+
version = `dev-${ref}`;
652+
}
616653

617654
// Ensure version is set on composer config because not all repos provide the version in composer.json (e.g.
618655
// page-builder) and it is required by satis to be able to use artifact repositories.

src/release-branch-build-tools.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ async function getPackageVersionsForBuildInstructions(buildInstructions, suffix)
8181
}
8282

8383
function addSuffixToVersion(version, buildSuffix) {
84+
// Don't add suffix to dev- branch versions
85+
if (version.startsWith('dev-')) {
86+
return version;
87+
}
88+
8489
const match = version.match(/(?<versions>(?:[\d]+\.?){1,4})(?<suffix>-[^+]+)?(?<legacy>\+.+)?/)
8590
if (match) {
8691
return `${match.groups.versions}-a${buildSuffix}${match.groups.legacy ? match.groups.legacy : ''}`
@@ -100,6 +105,11 @@ function transformVersionsToNightlyBuildVersion(baseVersion, buildSuffix) {
100105
}
101106

102107
function calcNightlyBuildPackageBaseVersion(version) {
108+
// Handle dev- branch versions (e.g., dev-develop, dev-master)
109+
if (version.startsWith('dev-')) {
110+
return version; // Return as-is, it's already a valid Composer branch version
111+
}
112+
103113
if (! version.match(/^v?(?:\d+\.){0,3}\d+(?:-[a-z]\w*|)$/i)) {
104114
throw Error(`Unable to determine branch release version for input version "${version}"`)
105115
}

0 commit comments

Comments
 (0)