From f91819d2e75879fd3a505113b27228ab97430a33 Mon Sep 17 00:00:00 2001 From: Vinai Kopp Date: Sun, 19 Nov 2023 15:18:10 +0100 Subject: [PATCH] Fix vendor name for releases --- src/determine-dependencies.js | 2 +- src/make/mageos-release.js | 2 +- src/package-modules.js | 41 +++++++++++++++++++++++------------ src/release-build-tools.js | 24 ++++++++++++++------ src/repository/shell-git.js | 4 +++- 5 files changed, 49 insertions(+), 24 deletions(-) diff --git a/src/determine-dependencies.js b/src/determine-dependencies.js index 702bc0a..1480435 100644 --- a/src/determine-dependencies.js +++ b/src/determine-dependencies.js @@ -48,7 +48,7 @@ module.exports = { async determineSourceDependencies(dir, files) { const prevCwd = cwd(); try { - console.log(`Determining dependencies for package being built...`); + console.log(`Determining dependencies...`); const hash = createHash('md5').update(dir).digest('hex'); const workDir = `${tmpdir()}/workdir-${hash}`; await setupWorkDir(dir, workDir); diff --git a/src/make/mageos-release.js b/src/make/mageos-release.js index db5335c..6094997 100644 --- a/src/make/mageos-release.js +++ b/src/make/mageos-release.js @@ -91,7 +91,7 @@ if (upstreamRelease && ! mageosRelease) { await repo.addUpdated(instruction.repoUrl, `'*composer.json'`) await repo.commit(instruction.repoUrl, workBranch, `Release ${mageosRelease}`) await repo.createTagForRef(instruction.repoUrl, workBranch, mageosRelease, '') - await processBuildInstructions(mageosRelease, mageosVendor, instruction, upstreamVersionMap) + await processBuildInstructions(mageosRelease, mageosVendor, {...instruction, ref: mageosRelease, origRef: instruction.ref}, upstreamVersionMap) } } } catch (exception) { diff --git a/src/package-modules.js b/src/package-modules.js index b8c929d..cf47df6 100644 --- a/src/package-modules.js +++ b/src/package-modules.js @@ -114,19 +114,19 @@ function chooseNameAndVersion(magentoName, composerJson, ref, givenVersion) { } /** - * @param {{'require':{}, 'require-dev':{}}} composerConfig + * @param {{'require':{}, 'require-dev':{}, 'suggest':{}}} composerConfig * @param {{}} dependencyVersions composer package:version dependency map. Dependencies for packages in the map will be set to the given versions */ -function setDependencyVersions(composerConfig, dependencyVersions) { +function setDependencyVersions(composerConfig, dependencyVersions, vendor) { for (const dependencyType of ['require', 'require-dev', 'suggest']) { for (const dep in (composerConfig[dependencyType] || {})) { - if (dependencyVersions[dep]) { + if (dependencyVersions[dep] || (vendor && dep.startsWith(vendor) && dependencyVersions['*'])) { // The "Sample Data version:" prefix is used by sampledata:deploy to identify packages to require. // See \Magento\SampleData\Model\Dependency::getSampleDataPackages // Package names are for example magento/module-catalog-sample-data or magento/magento/sample-data-media composerConfig[dependencyType][dep] = dependencyType === 'suggest' && (dep.endsWith('-sample-data') || dep.startsWith('sample-data-')) - ? `Sample Data version: ${dependencyVersions[dep]}` - : dependencyVersions[dep]; + ? `Sample Data version: ${dependencyVersions[dep] || dependencyVersions['*']}` + : dependencyVersions[dep] || dependencyVersions['*']; } } } @@ -227,7 +227,9 @@ async function createPackageForRef(url, moduleDir, ref, options) { emptyDirsToAdd, dependencyVersions, fallbackVersion, - transform + transform, + origRef, + vendor } = Object.assign(defaults, (options || {})); if (!excludes.includes('composer.json')) excludes.push('composer.json'); @@ -260,7 +262,11 @@ async function createPackageForRef(url, moduleDir, ref, options) { * * 4. nightly build, previously unreleased version: * dependencyVersions: undefined, composer.json version: undefined - * => use fallbackVersion + * => use fallbackVersions + * + * 5. mageos release + * dependencyVersions: set as {'*': releaseVersion} + * => use dependencyVersions */ ({ name, @@ -294,12 +300,19 @@ async function createPackageForRef(url, moduleDir, ref, options) { composerConfig.version = version; if ((composerJsonPath || '').endsWith('template.json')) { - const dir = await (repo.checkout(url, ref)); + // the origRef that ref is based on needs to be checked out for composer isntall, because only magento/* packages are available through the mirror repo + const dir = await repo.checkout(url, origRef || ref); const deps = await determineSourceDependencies(dir, files); + origRef && await repo.checkout(url, ref); composerConfig.require = {}; - Object.keys(deps).sort().forEach(dependency => composerConfig.require[dependency] = deps[dependency]); + Object.keys(deps).sort().forEach(dependency => { + const dependencyName = vendor && dependency.startsWith('magento/') + ? dependency.replace(/^magento\//, vendor + '/') + : dependency + composerConfig.require[dependencyName] = deps[dependency] + }); } - setDependencyVersions(composerConfig, dependencyVersions); + setDependencyVersions(composerConfig, dependencyVersions, vendor); composerConfig = (transform && transform[name] || []).reduce((config, transformFn) => transformFn(config), composerConfig); @@ -482,7 +495,7 @@ async function createMagentoCommunityEditionMetapackage(url, ref, options) { for (const k of ['autoload', 'autoload-dev', 'config', 'conflict', 'extra', 'minimum-stability', 'replace', 'require-dev', 'suggest']) { delete composerConfig[k]; } - setDependencyVersions(composerConfig, dependencyVersions); + setDependencyVersions(composerConfig, dependencyVersions, vendor); return (transform && transform[packageName] || []).reduce((config, transformFn) => transformFn(config), composerConfig); }, release || version); @@ -535,7 +548,7 @@ async function createMagentoCommunityEditionProject(url, ref, options) { for (const k of ['replace', 'suggest']) { delete composerConfig[k]; } - setDependencyVersions(composerConfig, dependencyVersions); + setDependencyVersions(composerConfig, dependencyVersions, vendor); return (transform && transform[name] || []).reduce((config, transformFn) => transformFn(config), composerConfig) }, version); @@ -588,7 +601,7 @@ async function determineMetaPackageFromRepoDir(url, dir, ref, release) { * @returns {Promise<{}>} */ async function createMetaPackageFromRepoDir(url, dir, ref, options) { - const {release, dependencyVersions, transform} = Object.assign({ + const {release, dependencyVersions, transform, vendor} = Object.assign({ release: undefined, dependencyVersions: {} }, (options || {})); @@ -602,7 +615,7 @@ async function createMetaPackageFromRepoDir(url, dir, ref, options) { // 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. composerConfig.version = version; - setDependencyVersions(composerConfig, dependencyVersions); + setDependencyVersions(composerConfig, dependencyVersions, vendor); composerConfig = (transform && transform[name] || []).reduce((config, transformFn) => transformFn(config), composerConfig); diff --git a/src/release-build-tools.js b/src/release-build-tools.js index a52f659..f2c110c 100644 --- a/src/release-build-tools.js +++ b/src/release-build-tools.js @@ -129,7 +129,7 @@ function updateMapFromMagentoToMageOs(obj, vendor) { function updateComposerDepsFromMagentoToMageOs(composerConfig, vendor) { composerConfig.name = setMageOsVendor(composerConfig.name, vendor) - for (const dependencyType of ['require', 'require-dev', 'suggest']) { + for (const dependencyType of ['require', 'require-dev', 'suggest', 'replace']) { composerConfig[dependencyType] && (composerConfig[dependencyType] = updateMapFromMagentoToMageOs(composerConfig[dependencyType], vendor)) } } @@ -163,15 +163,21 @@ function updateComposerPluginConfigForMageOs(composerConfig, vendor) { } } +/** + * Replace all occurrences of the magento vendor name with the given vendor in a composer.json + * + * This also happens for the "replace" section, before the given replaceVersionMap is merged. + */ function updateComposerConfigFromMagentoToMageOs(composerConfig, releaseVersion, replaceVersionMap, vendor) { composerConfig.version = releaseVersion - if (replaceVersionMap[composerConfig.name]) { - composerConfig.replace = {[composerConfig.name]: replaceVersionMap[composerConfig.name]} - } composerConfig.name = setMageOsVendor(composerConfig.name, vendor) updateComposerDepsFromMagentoToMageOs(composerConfig, vendor) updateComposerDepsVersionForMageOs(composerConfig, releaseVersion, vendor) updateComposerPluginConfigForMageOs(composerConfig, vendor) + + if (replaceVersionMap[composerConfig.name]) { + composerConfig.replace = {[composerConfig.name]: replaceVersionMap[composerConfig.name]} + } } async function prepPackageForRelease({label, dir}, repoUrl, ref, releaseVersion, vendor, replaceVersionMap, workingCopyPath) { @@ -308,7 +314,7 @@ module.exports = { const packages = {} // record generated packages with versions - const {repoUrl, transform, ref} = instruction + const {repoUrl, transform, ref, origRef} = instruction for (const packageDir of (instruction.packageDirs || [])) { const {label, dir, excludes} = Object.assign({excludes: []}, packageDir) @@ -318,7 +324,9 @@ module.exports = { mageosRelease, fallbackVersion, dependencyVersions, - transform + transform, + origRef, + vendor }) Object.assign(packages, built) } @@ -335,7 +343,9 @@ module.exports = { mageosRelease, fallbackVersion, dependencyVersions, - transform + transform, + origRef, + vendor }) Object.assign(packages, built) } diff --git a/src/repository/shell-git.js b/src/repository/shell-git.js index 212e48b..59a0fad 100644 --- a/src/repository/shell-git.js +++ b/src/repository/shell-git.js @@ -73,7 +73,7 @@ async function exec(cmd, options) { const bufferBytes = 4 * 1024 * 1024; // 4M childProcess.exec(cmd, {maxBuffer: bufferBytes, ...(options || {})}, (error, stdout, stderr) => { if (error) { - reject(`Error executing command${options?.cwd ? ` in ${options.cwd}` : ''}: ${error.message}`) + reject(`Error executing command${options?.cwd ? ` in ${options.cwd}` : ''}: ${error.message}\n${stdout}`) } if (stderr) { reject(`[error] ${stderr}`); @@ -83,6 +83,8 @@ async function exec(cmd, options) { }); } + + /* * Relaxing permissions is required to work around issues when running in docker with a mounted dir: * fatal: detected dubious ownership in repository at '...'