Skip to content

Commit 0936b23

Browse files
committed
Support multiple scan dirs { run: , scan [ { dir: }, { dir: } ] }
Closes gh-57
1 parent 818f5c5 commit 0936b23

2 files changed

Lines changed: 68 additions & 7 deletions

File tree

lib/inject-collector-cache-config-extension.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,17 @@ module.exports.register = function ({ playbook, config = {} }) {
7373
const normalizedCollectorConfig = Array.isArray(collectorConfig) ? collectorConfig : [collectorConfig]
7474
origin.descriptor.ext.collector = cachedConfig
7575
normalizedCollectorConfig.forEach((collector) => {
76-
const { scan: scanConfig = [] } = collector
77-
// cache the output of the build
78-
const scanDir = expandPath(scanConfig.dir, expandPathContext)
79-
logger.info(`Configuring collector to cache '${scanDir}' at '${cacheDir}'`)
80-
const cachedCollectorConfig = createCachedCollectorConfig(scanDir, cacheDir)
8176
cachedConfig.push(collector)
82-
cachedConfig.push.apply(cachedConfig, cachedCollectorConfig)
77+
const { scan: scanConfig = [] } = collector
78+
const normalizedScanConfigs = Array.isArray(scanConfig) ? scanConfig : [scanConfig]
79+
normalizedScanConfigs.forEach((normalizedScanConfig) => {
80+
// cache the output of the build
81+
const scanDirExpandedPath = expandPath(normalizedScanConfig.dir, expandPathContext)
82+
logger.info(`Configuring collector to cache '${scanDirExpandedPath}' at '${cacheDir}'`)
83+
const cachedCollectorConfig = createCachedCollectorConfig(scanDirExpandedPath, cacheDir)
84+
85+
cachedConfig.push.apply(cachedConfig, cachedCollectorConfig)
86+
})
8387
})
8488
// add the zip of cache to be published
8589
zipInfo.push({ cacheDir, zipCacheFile })

test/inject-collector-cache-config-extension-test.js

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ describe('inject-collector-cache-config-extension', () => {
200200
expect(fs.existsSync(zipFileName)).to.eql(true)
201201
})
202202

203-
it('cache not found multiple scans', async () => {
203+
it('cache not with multiple scan [{ scan: { dir: }, { scan: dir: } ]', async () => {
204204
const tag = createTag('1.0.0')
205205
tag.origins[0].refhash = tag.origins[0].refhash.split('').reverse().join('')
206206
// make multiple scan dirs
@@ -255,6 +255,63 @@ describe('inject-collector-cache-config-extension', () => {
255255
await generatorContext.beforePublish()
256256
expect(fs.existsSync(zipFileName)).to.eql(true)
257257
})
258+
259+
it('cache not found with multiple scan dirs { run: , scan [ { dir: }, { dir: } ] }', async () => {
260+
const tag = createTag('1.0.0')
261+
tag.origins[0].refhash = tag.origins[0].refhash.split('').reverse().join('')
262+
// make multiple scan dirs
263+
tag.origins[0].descriptor = {
264+
ext: {
265+
collector: [
266+
{
267+
run: { command: './mvnw -B validate process-resources dependency:unpack -am -Pantora-process-resources' },
268+
scan: [{ dir: 'target/classes/antora-resources/' }, { dir: 'target/antora/' }],
269+
},
270+
],
271+
},
272+
}
273+
contentAggregate = [tag]
274+
ext.register.call(generatorContext, { playbook })
275+
await generatorContext.contentAggregated({ playbook, contentAggregate })
276+
expect(fs.existsSync(ospath.join(cacheDir, 'collector-cache/spring-security'))).to.equal(true)
277+
const actual = contentAggregate[0].origins[0].descriptor.ext
278+
const scan = ospath.join(cacheDir, 'collector/spring-security/target/classes/antora-resources')
279+
const scan2 = ospath.join(cacheDir, 'collector/spring-security/target/antora')
280+
const cache = ospath.join(cacheDir, 'collector-cache/spring-security/2c4fb2f-1.0.0')
281+
const zipFileName = ospath.join(
282+
playbookDir,
283+
'build/antora/inject-collector-cache-config-extension/.cache/2c4fb2f-1.0.0.zip'
284+
)
285+
const expected = {
286+
collector: [
287+
{
288+
run: {
289+
command: './mvnw -B validate process-resources dependency:unpack -am -Pantora-process-resources',
290+
},
291+
scan: [{ dir: 'target/classes/antora-resources/' }, { dir: 'target/antora/' }],
292+
},
293+
{
294+
run: {
295+
command: `node '${resolvedCacheScanDirIndexJs}' '${scan}' '${cache}'`,
296+
},
297+
},
298+
{
299+
run: {
300+
command: `node '${resolvedCacheScanDirIndexJs}' '${scan2}' '${cache}'`,
301+
},
302+
},
303+
],
304+
}
305+
expect(actual).to.eql(expected)
306+
expect(generatorContext.messages).to.eql([
307+
`Unable to restore cache from ${httpServerUrl}/.cache/2c4fb2f-1.0.0.zip`,
308+
`Configuring collector to cache '${scan}' at '${cache}'`,
309+
`Configuring collector to cache '${scan2}' at '${cache}'`,
310+
])
311+
expect(fs.existsSync(zipFileName)).to.eql(false)
312+
await generatorContext.beforePublish()
313+
expect(fs.existsSync(zipFileName)).to.eql(true)
314+
})
258315
it('cache downloaded', async () => {
259316
const zipFileName = ospath.join(
260317
playbookDir,

0 commit comments

Comments
 (0)