Skip to content

Commit

Permalink
#706: ensure metadata is fully copied with all its extracted code blo…
Browse files Browse the repository at this point in the history
…cks when --filter is used
  • Loading branch information
JoernBerkefeld committed Feb 21, 2023
1 parent 2cc2900 commit d5280d2
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 6 deletions.
12 changes: 9 additions & 3 deletions docs/dist/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -5665,7 +5665,8 @@ DevOps helper class
* [DevOps](#DevOps)
* [.getDeltaList(properties, [range], [saveToDeployDir], [filterPaths])](#DevOps.getDeltaList) ⇒ <code>Promise.&lt;Array.&lt;TYPE.DeltaPkgItem&gt;&gt;</code>
* [~delta](#DevOps.getDeltaList..delta) : <code>Array.&lt;TYPE.DeltaPkgItem&gt;</code>
* [~copied](#DevOps.getDeltaList..copied) : <code>TYPE.DeltaPkgItem</code>
* [~buObjects](#DevOps.getDeltaList..buObjects) : <code>Object.&lt;string, TYPE.BuObject&gt;</code>
* [~copied](#DevOps.getDeltaList..copied) : <code>Array.&lt;TYPE.DeltaPkgItem&gt;</code>
* [.buildDeltaDefinitions(properties, range, [diffArr])](#DevOps.buildDeltaDefinitions) ⇒ <code>Promise.&lt;Array.&lt;TYPE.DeltaPkgItem&gt;&gt;</code>
* [~deltaDeployAll](#DevOps.buildDeltaDefinitions..deltaDeployAll) : <code>Array.&lt;TYPE.DeltaPkgItem&gt;</code>
* [.document(directory, jsonReport)](#DevOps.document) ⇒ <code>void</code>
Expand All @@ -5690,15 +5691,20 @@ Interactive commit selection if no commits are passed.

* [.getDeltaList(properties, [range], [saveToDeployDir], [filterPaths])](#DevOps.getDeltaList) ⇒ <code>Promise.&lt;Array.&lt;TYPE.DeltaPkgItem&gt;&gt;</code>
* [~delta](#DevOps.getDeltaList..delta) : <code>Array.&lt;TYPE.DeltaPkgItem&gt;</code>
* [~copied](#DevOps.getDeltaList..copied) : <code>TYPE.DeltaPkgItem</code>
* [~buObjects](#DevOps.getDeltaList..buObjects) : <code>Object.&lt;string, TYPE.BuObject&gt;</code>
* [~copied](#DevOps.getDeltaList..copied) : <code>Array.&lt;TYPE.DeltaPkgItem&gt;</code>

<a name="DevOps.getDeltaList..delta"></a>

#### getDeltaList~delta : <code>Array.&lt;TYPE.DeltaPkgItem&gt;</code>
**Kind**: inner constant of [<code>getDeltaList</code>](#DevOps.getDeltaList)
<a name="DevOps.getDeltaList..buObjects"></a>

#### getDeltaList~buObjects : <code>Object.&lt;string, TYPE.BuObject&gt;</code>
**Kind**: inner constant of [<code>getDeltaList</code>](#DevOps.getDeltaList)
<a name="DevOps.getDeltaList..copied"></a>

#### getDeltaList~copied : <code>TYPE.DeltaPkgItem</code>
#### getDeltaList~copied : <code>Array.&lt;TYPE.DeltaPkgItem&gt;</code>
**Kind**: inner constant of [<code>getDeltaList</code>](#DevOps.getDeltaList)
<a name="DevOps.buildDeltaDefinitions"></a>

Expand Down
89 changes: 86 additions & 3 deletions lib/util/devops.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const File = require('./file');
const path = require('node:path');
const inquirer = require('inquirer');
const Util = require('./util');
const Cli = require('./cli');
const git = require('simple-git')();
const Builder = require('../Builder');
const MetadataType = require('../MetadataTypeInfo');
Expand Down Expand Up @@ -104,7 +105,7 @@ const DevOps = {
}

// get metadata type from file name
file.type = path.basename(file.file).split('.')[1].split('-').shift();
file.type = file.file.split('/')[3];

return file;
})
Expand All @@ -130,7 +131,14 @@ const DevOps = {
file.externalKey = null;
file.name = path.basename(file.file).split('.').shift();
} else {
file.externalKey = path.basename(file.file).split('.').shift();
// find the key in paths like:
// - retrieve/cred/bu/asset/block/016aecc7-7063-4b78-93f4-aa119ea933c7.asset-block-meta.html
// - retrieve/cred/bu/asset/message/003c1ef5-f538-473a-91da-26942024a64a/blocks/views.html.slots.[bottom-8frq7iw2k99].asset-message-meta.html
// - retrieve/cred/bu/query/03efd5f1-ba1f-487a-9c9a-36aeb2ae5192.query-meta.sql
file.externalKey =
file.type === 'asset'
? file.file.split('/')[5].split('.')[0] // assets have an additional folder level for their subtype
: file.file.split('/')[4].split('.')[0];
file.name = null;
}

Expand Down Expand Up @@ -207,8 +215,83 @@ const DevOps = {
Util.logger.info(`Saved report in ${path.join(directoryDeltaPkg, 'delta_package.md')}`);

// Copy filtered list of files into deploy directory
// only do that if we do not use templating
if (saveToDeployDir) {
/** @type {TYPE.DeltaPkgItem} */
// if templating is not used, we need to add related files to the delta package
const typeKeysMap = {};
/** @type {Object.<string, TYPE.BuObject>} */
const buObjects = {};
for (const file of delta) {
if (file.gitAction === 'delete' || file.type === 'folder') {
continue;
}
if (typeKeysMap[file.type]) {
typeKeysMap[file.type].push(file.externalKey);
} else {
typeKeysMap[file.type] = [file.externalKey];
}
if (!buObjects[`${file._credential}/${file._businessUnit}`]) {
buObjects[`${file._credential}/${file._businessUnit}`] =
await Cli.getCredentialObject(
properties,
`${file._credential}/${file._businessUnit}`
);
}
}
// a bit crude but works for now
for (const buObject of Object.values(buObjects)) {
for (const type in typeKeysMap) {
MetadataType[type].buObject = buObject;
MetadataType[type].properties = properties;
const additionalFiles = await MetadataType[type].getFilesToCommit(
typeKeysMap[type]
);
if (additionalFiles?.length) {
delta.push(
...additionalFiles
.map((filePath) => ({
file: path.normalize(filePath).split('\\').join('/'),
type,
gitAction: 'add/update',
}))
.filter(
// avoid adding files that we already have in the list
(addFile) =>
!delta.find((existFile) => existFile.file === addFile.file)
)
);
}
}
}

let responses;
if (!Util.skipInteraction) {
// deploy folder is in targets for definition creation
// recommend to purge their content first
responses = await inquirer.prompt([
{
type: 'confirm',
name: 'isPurgeDeployFolder',
message:
'Do you want to empty the deploy folder (ensures no files from previous deployments remain)?',
default: true,
},
]);
}
if (Util.skipInteraction || responses.isPurgeDeployFolder) {
// Clear output folder structure for selected sub-type
for (const buObject of Object.values(buObjects)) {
await File.remove(
File.normalizePath([
properties.directories.deploy,
buObject.credential,
buObject.businessUnit,
])
);
}
}

/** @type {TYPE.DeltaPkgItem[]} */
const copied = delta.map((file) =>
File.copyFile(
file.file,
Expand Down

0 comments on commit d5280d2

Please sign in to comment.