Skip to content

Commit

Permalink
Cache Collector scan dir right after run command
Browse files Browse the repository at this point in the history
Rather than cache after all run commands, it should be cached immediately
after the run command that procuces the scan dir so that if additional runs
change the output of previous runs the modified output isn't cached.

Closes gh-40
  • Loading branch information
rwinch committed Aug 18, 2024
1 parent 6757c71 commit b57d538
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions lib/inject-collector-cache-config-extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,17 @@ module.exports.register = function ({ playbook, config = {} }) {
}
logger.info(`Use the cache found at ${cacheDir}`)
} else {
const cachedConfig = []
const normalizedCollectorConfig = Array.isArray(collectorConfig) ? collectorConfig : [collectorConfig]
origin.descriptor.ext.collector = normalizedCollectorConfig
origin.descriptor.ext.collector = cachedConfig
normalizedCollectorConfig.forEach((collector) => {
const { scan: scanConfig = [] } = collector
// cache the output of the build
const scanDir = expandPath(scanConfig.dir, expandPathContext)
logger.info(`Configuring collector to cache '${scanDir}' at '${cacheDir}'`)
const cachedCollectorConfig = createCachedCollectorConfig(scanDir, cacheDir)
normalizedCollectorConfig.push.apply(normalizedCollectorConfig, cachedCollectorConfig)
cachedConfig.push(collector)
cachedConfig.push.apply(cachedConfig, cachedCollectorConfig)
})
// add the zip of cache to be published
zipInfo.push({ cacheDir, zipCacheFile })
Expand Down
8 changes: 4 additions & 4 deletions test/inject-collector-cache-config-extension-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,13 @@ describe('inject-collector-cache-config-extension', () => {
},
},
{
scan: {
dir: './build/antora-resources-2',
run: {
command: `node '${resolvedCacheScanDirIndexJs}' '${scan}' '${cache}'`,
},
},
{
run: {
command: `node '${resolvedCacheScanDirIndexJs}' '${scan}' '${cache}'`,
scan: {
dir: './build/antora-resources-2',
},
},
{
Expand Down

0 comments on commit b57d538

Please sign in to comment.