Skip to content

Commit

Permalink
Merge pull request #154 from Vinai/develop
Browse files Browse the repository at this point in the history
Fix vendor name for releases
  • Loading branch information
mage-os-ci authored Nov 19, 2023
2 parents faca984 + f91819d commit 6f45798
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/determine-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/make/mageos-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
41 changes: 27 additions & 14 deletions src/package-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -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['*'];
}
}
}
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 || {}));
Expand All @@ -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);

Expand Down
24 changes: 17 additions & 7 deletions src/release-build-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand All @@ -318,7 +324,9 @@ module.exports = {
mageosRelease,
fallbackVersion,
dependencyVersions,
transform
transform,
origRef,
vendor
})
Object.assign(packages, built)
}
Expand All @@ -335,7 +343,9 @@ module.exports = {
mageosRelease,
fallbackVersion,
dependencyVersions,
transform
transform,
origRef,
vendor
})
Object.assign(packages, built)
}
Expand Down
4 changes: 3 additions & 1 deletion src/repository/shell-git.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand All @@ -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 '...'
Expand Down

0 comments on commit 6f45798

Please sign in to comment.