Skip to content

Commit

Permalink
aio app pack fixes (#702)
Browse files Browse the repository at this point in the history
* fix missing annotation key

* fix sub config includes

* fix windows test

* resolve review comments

---------

Co-authored-by: Shazron Abdullah <[email protected]>
  • Loading branch information
moritzraho and shazron authored Aug 8, 2023
1 parent a7189d4 commit 2b07a9a
Show file tree
Hide file tree
Showing 9 changed files with 437 additions and 20 deletions.
60 changes: 41 additions & 19 deletions src/commands/app/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,28 +252,50 @@ class Pack extends BaseCommand {
* @param {object} appConfig the app's configuration file
*/
async addCodeDownloadAnnotation (appConfig) {
// get the configFiles that have runtime manifests
const configFiles = []
for (const [, value] of Object.entries(appConfig.includeIndex)) {
const { key } = value
if (key === 'runtimeManifest' || key === 'application.runtimeManifest') {
configFiles.push(value)
}
}

// for each configFile, we modify each action to have the "code-download: false" annotation
for (const configFile of configFiles) {
const configFilePath = path.join(DEFAULTS.ARTIFACTS_FOLDER, configFile.file)
// get each annotation key relative to the file it is defined in
/// iterate only over extensions that have actions defined
const fileToAnnotationKey = {}
Object.entries(appConfig.all)
.filter(([_, extConf]) => extConf.manifest?.full?.packages)
.forEach(([ext, extConf]) => {
Object.entries(extConf.manifest.full.packages)
.filter(([pkg, pkgConf]) => pkgConf.actions)
.forEach(([pkg, pkgConf]) => {
Object.entries(pkgConf.actions).forEach(([action, actionConf]) => {
const baseFullKey = ext === 'application'
? `application.runtimeManifest.packages.${pkg}.actions.${action}`
: `extensions.${ext}.runtimeManifest.packages.${pkg}.actions.${action}`

let index
if (actionConf.annotations) {
index = appConfig.includeIndex[`${baseFullKey}.annotations`]
} else {
// the annotation object is not defined, take the parent key
index = appConfig.includeIndex[baseFullKey]
}
if (!fileToAnnotationKey[index.file]) {
fileToAnnotationKey[index.file] = []
}
fileToAnnotationKey[index.file].push(index.key) // index.key is relative to the file
})
})
})

// rewrite config files
for (const [file, keys] of Object.entries(fileToAnnotationKey)) {
const configFilePath = path.join(DEFAULTS.ARTIFACTS_FOLDER, file)
const { values } = loadConfigFile(configFilePath)

const runtimeManifest = getObjectValue(values, configFile.key)
for (const [, pkgManifest] of Object.entries(runtimeManifest.packages)) {
// key is the package name (unused), value is the package manifest. we iterate through each package's "actions"
for (const [, actionManifest] of Object.entries(pkgManifest.actions)) {
// key is the action name (unused), value is the action manifest. we add the "code-download: false" annotation
actionManifest.annotations['code-download'] = false
keys.forEach(key => {
const object = getObjectValue(values, key)
if (key.endsWith('.annotations') || key === 'annotations') {
// object is the annotations object
object['code-download'] = false
} else {
// annotation object is not defined, the object is the action object
object.annotations = { 'code-download': false }
}
}
})

// write back the modified manifest to disk
await writeFile(configFilePath, yaml.dump(values), { overwrite: true })
Expand Down
247 changes: 247 additions & 0 deletions test/__fixtures__/pack/5.all.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
{
"all": {
"application": {
"manifest": {
"src": "manifest.yml",
"full": {
"packages": {
"emptypackage": {},
"mypackage": {
"actions": {
"generic3": {
"function": "src\\dx-excshell-1\\actions\\generic\\index.js",
"runtime": "nodejs:16"
}
}
}
}
}
}
},
"empty/extension": {},
"dx/excshell/1": {
"app": {
"hasBackend": true,
"hasFrontend": true,
"dist": "dist\\dx-excshell-1",
"defaultHostname": "adobeio-static.net",
"hostname": "adobeio-static.net",
"htmlCacheDuration": "60",
"jsCacheDuration": "604800",
"cssCacheDuration": "604800",
"imageCacheDuration": "604800",
"name": "my-app",
"version": "0.0.1"
},
"manifest": {
"src": "manifest.yml",
"full": {
"packages": {
"dx-excshell-1": {
"license": "Apache-2.0",
"actions": {
"generic": {
"function": "src\\dx-excshell-1\\actions\\generic\\index.js",
"web": "yes",
"runtime": "nodejs:16",
"inputs": {
"LOG_LEVEL": "debug"
},
"annotations": {
"require-adobe-auth": true,
"final": true
}
},
"generic2": {
"function": "src\\dx-excshell-1\\actions\\generic\\index.js",
"runtime": "nodejs:16",
"annotations": {}
},
"generic4": {
"function": "src\\dx-excshell-1\\actions\\generic\\index.js",
"runtime": "nodejs:16",
"annotations": {}
}
}
}
}
},
"packagePlaceholder": "__APP_PACKAGE__"
}
}
},
"implements": [
"application",
"dx/excshell/1"
],
"includeIndex": {
"application": {
"file": "app.config.yaml",
"key": "application"
},
"application.runtimeManifest": {
"file": "app.config.yaml",
"key": "application.runtimeManifest"
},
"application.runtimeManifest.packages": {
"file": "app.config.yaml",
"key": "application.runtimeManifest.packages"
},
"application.runtimeManifest.packages.mypackage": {
"file": "app.config.yaml",
"key": "application.runtimeManifest.packages.mypackage"
},
"application.runtimeManifest.packages.emptypackage": {
"file": "app.config.yaml",
"key": "application.runtimeManifest.packages.emptypackage"
},
"application.runtimeManifest.packages.mypackage.actions": {
"file": "app.config.yaml",
"key": "application.runtimeManifest.packages.mypackage.actions"
},
"application.runtimeManifest.packages.mypackage.actions.generic3": {
"file": "app.config.yaml",
"key": "application.runtimeManifest.packages.mypackage.actions.generic3"
},
"application.runtimeManifest.packages.mypackage.actions.generic3.function": {
"file": "app.config.yaml",
"key": "application.runtimeManifest.packages.mypackage.actions.generic3.function"
},
"application.runtimeManifest.packages.mypackage.actions.generic3.runtime": {
"file": "app.config.yaml",
"key": "application.runtimeManifest.packages.mypackage.actions.generic3.runtime"
},
"extensions": {
"file": "app.config.yaml",
"key": "extensions"
},
"extensions.empty/extension": {
"file": "app.config.yaml",
"key": "extensions.empty/extension"
},
"extensions.dx/excshell/1": {
"file": "app.config.yaml",
"key": "extensions.dx/excshell/1"
},
"extensions.dx/excshell/1.$include": {
"file": "app.config.yaml",
"key": "extensions.dx/excshell/1.$include"
},
"extensions.dx/excshell/1.runtimeManifest": {
"file": "src/dx-excshell-1/ext.config.yaml",
"key": "runtimeManifest"
},
"extensions.dx/excshell/1.runtimeManifest.packages": {
"file": "src/dx-excshell-1/ext.config.yaml",
"key": "runtimeManifest.packages"
},
"extensions.dx/excshell/1.runtimeManifest.packages.dx-excshell-1": {
"file": "src/dx-excshell-1/ext.config.yaml",
"key": "runtimeManifest.packages.dx-excshell-1"
},
"extensions.dx/excshell/1.runtimeManifest.packages.dx-excshell-1.actions": {
"file": "src/dx-excshell-1/ext.config.yaml",
"key": "runtimeManifest.packages.dx-excshell-1.actions"
},
"extensions.dx/excshell/1.runtimeManifest.packages.dx-excshell-1.actions.generic2": {
"file": "src/dx-excshell-1/ext.config.yaml",
"key": "runtimeManifest.packages.dx-excshell-1.actions.generic2"
},
"extensions.dx/excshell/1.runtimeManifest.packages.dx-excshell-1.actions.generic2.runtime": {
"file": "src/dx-excshell-1/ext.config.yaml",
"key": "runtimeManifest.packages.dx-excshell-1.actions.generic2.runtime"
},
"extensions.dx/excshell/1.runtimeManifest.packages.dx-excshell-1.actions.generic2.function": {
"file": "src/dx-excshell-1/ext.config.yaml",
"key": "runtimeManifest.packages.dx-excshell-1.actions.generic2.function"
},
"extensions.dx/excshell/1.runtimeManifest.packages.dx-excshell-1.actions.generic2.annotations": {
"file": "src/sub2.config.yaml",
"key": "annotations"
},
"extensions.dx/excshell/1.runtimeManifest.packages.dx-excshell-1.actions.generic": {
"file": "sub1.config.yaml",
"key": "generic"
},
"extensions.dx/excshell/1.runtimeManifest.packages.dx-excshell-1.actions.generic.annotations": {
"file": "sub1.config.yaml",
"key": "generic.annotations"
},
"extensions.dx/excshell/1.runtimeManifest.packages.dx-excshell-1.actions.generic.annotations.final": {
"file": "sub1.config.yaml",
"key": "generic.annotations.final"
},
"extensions.dx/excshell/1.runtimeManifest.packages.dx-excshell-1.actions.generic.annotations.require-adobe-auth": {
"file": "sub1.config.yaml",
"key": "generic.annotations.require-adobe-auth"
},
"extensions.dx/excshell/1.runtimeManifest.packages.dx-excshell-1.actions.generic.inputs": {
"file": "sub1.config.yaml",
"key": "generic.inputs"
},
"extensions.dx/excshell/1.runtimeManifest.packages.dx-excshell-1.actions.generic.inputs.LOG_LEVEL": {
"file": "sub1.config.yaml",
"key": "generic.inputs.LOG_LEVEL"
},
"extensions.dx/excshell/1.runtimeManifest.packages.dx-excshell-1.actions.generic.runtime": {
"file": "sub1.config.yaml",
"key": "generic.runtime"
},
"extensions.dx/excshell/1.runtimeManifest.packages.dx-excshell-1.actions.generic.web": {
"file": "sub1.config.yaml",
"key": "generic.web"
},
"extensions.dx/excshell/1.runtimeManifest.packages.dx-excshell-1.actions.generic.function": {
"file": "sub1.config.yaml",
"key": "generic.function"
},
"extensions.dx/excshell/1.runtimeManifest.packages.dx-excshell-1.actions.generic4": {
"file": "sub1.config.yaml",
"key": "generic4"
},
"extensions.dx/excshell/1.runtimeManifest.packages.dx-excshell-1.actions.generic4.function": {
"file": "sub1.config.yaml",
"key": "generic4.function"
},
"extensions.dx/excshell/1.runtimeManifest.packages.dx-excshell-1.actions.generic4.runtime": {
"file": "sub1.config.yaml",
"key": "generic4.runtime"
},
"extensions.dx/excshell/1.runtimeManifest.packages.dx-excshell-1.actions.generic4.annotations": {
"file": "sub1.config.yaml",
"key": "generic4.annotations"
},
"extensions.dx/excshell/1.runtimeManifest.packages.dx-excshell-1.license": {
"file": "src/dx-excshell-1/ext.config.yaml",
"key": "runtimeManifest.packages.dx-excshell-1.license"
},
"extensions.dx/excshell/1.web": {
"file": "src/dx-excshell-1/ext.config.yaml",
"key": "web"
},
"extensions.dx/excshell/1.actions": {
"file": "src/dx-excshell-1/ext.config.yaml",
"key": "actions"
},
"extensions.dx/excshell/1.operations": {
"file": "src/dx-excshell-1/ext.config.yaml",
"key": "operations"
},
"extensions.dx/excshell/1.operations.view": {
"file": "src/dx-excshell-1/ext.config.yaml",
"key": "operations.view"
},
"extensions.dx/excshell/1.operations.view.0": {
"file": "src/dx-excshell-1/ext.config.yaml",
"key": "operations.view.0"
},
"extensions.dx/excshell/1.operations.view.0.impl": {
"file": "src/dx-excshell-1/ext.config.yaml",
"key": "operations.view.0.impl"
},
"extensions.dx/excshell/1.operations.view.0.type": {
"file": "src/dx-excshell-1/ext.config.yaml",
"key": "operations.view.0.type"
}
}
}
19 changes: 19 additions & 0 deletions test/__fixtures__/pack/5.app.annotation-added.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"application": {
"runtimeManifest": {
"packages": {
"mypackage": {
"actions": {
"generic3": {
"function": "actions/generic/index.js",
"runtime": "nodejs:16",
"annotations": {
"code-download": false
}
}
}
}
}
}
}
}
18 changes: 18 additions & 0 deletions test/__fixtures__/pack/5.app.config-loaded.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"values": {
"application": {
"runtimeManifest": {
"packages": {
"mypackage": {
"actions": {
"generic3": {
"function": "actions/generic/index.js",
"runtime": "nodejs:16"
}
}
}
}
}
}
}
}
22 changes: 22 additions & 0 deletions test/__fixtures__/pack/5.sub1.annotation-added.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"generic": {
"function": "actions/generic/index.js",
"web": "yes",
"runtime": "nodejs:16",
"inputs": {
"LOG_LEVEL": "debug"
},
"annotations": {
"require-adobe-auth": true,
"final": true,
"code-download": false
}
},
"generic4": {
"function": "actions/generic/index.js",
"runtime": "nodejs:16",
"annotations": {
"code-download": false
}
}
}
Loading

0 comments on commit 2b07a9a

Please sign in to comment.