Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
- Loading branch information
Showing
13 changed files
with
205 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import * as _fs from 'fs-extra'; | ||
import { mocked } from '../../../../test/util'; | ||
import * as repositoryCache from '.'; | ||
|
||
jest.mock('fs-extra'); | ||
|
||
const fs = mocked(_fs); | ||
|
||
describe('lib/util/cache/repository', () => { | ||
const config = { | ||
cacheDir: '/tmp/renovate/cache/', | ||
platform: 'github', | ||
repository: 'abc/def', | ||
}; | ||
it('catches and returns', async () => { | ||
await repositoryCache.initialize({}); | ||
expect(fs.readFile.mock.calls).toHaveLength(0); | ||
}); | ||
it('returns if cache not enabled', async () => { | ||
await repositoryCache.initialize({ | ||
...config, | ||
repositoryCache: 'disabled', | ||
}); | ||
expect(fs.readFile.mock.calls).toHaveLength(0); | ||
}); | ||
it('reads from cache and finalizes', async () => { | ||
fs.readFile.mockResolvedValueOnce('{}' as any); | ||
await repositoryCache.initialize({ | ||
...config, | ||
repositoryCache: 'enabled', | ||
}); | ||
await repositoryCache.finalize(); | ||
expect(fs.readFile.mock.calls).toHaveLength(1); | ||
expect(fs.outputFile.mock.calls).toHaveLength(1); | ||
}); | ||
it('gets', () => { | ||
expect(repositoryCache.getCache()).toEqual({}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import * as fs from 'fs-extra'; | ||
import { join } from 'upath'; | ||
import { RenovateConfig, RepositoryCacheConfig } from '../../../config/common'; | ||
import { logger } from '../../../logger'; | ||
import { PackageFile } from '../../../manager/common'; | ||
|
||
export interface BaseBranchCache { | ||
sha: string; // branch commit sha | ||
configHash: string; // object hash of config | ||
packageFiles: PackageFile[]; // extract result | ||
} | ||
|
||
export interface Cache { | ||
init?: { | ||
configFile: string; | ||
contents: RenovateConfig; | ||
}; | ||
scan?: Record<string, BaseBranchCache>; | ||
} | ||
|
||
let repositoryCache: RepositoryCacheConfig = 'disabled'; | ||
let cacheFileName: string; | ||
let cache: Cache = Object.create({}); | ||
|
||
export function getCacheFileName(config: RenovateConfig): string { | ||
return join( | ||
config.cacheDir, | ||
'/renovate/repository/', | ||
config.platform, | ||
config.repository + '.json' | ||
); | ||
} | ||
|
||
export async function initialize(config: RenovateConfig): Promise<void> { | ||
try { | ||
cacheFileName = getCacheFileName(config); | ||
repositoryCache = config.repositoryCache; | ||
if (repositoryCache !== 'enabled') { | ||
logger.debug('Skipping repository cache'); | ||
cache = {}; | ||
return; | ||
} | ||
cache = JSON.parse(await fs.readFile(cacheFileName, 'utf8')); | ||
logger.debug({ cacheFileName }, 'Read repository cache'); | ||
} catch (err) { | ||
logger.debug({ cacheFileName }, 'No repository cache found'); | ||
} | ||
} | ||
|
||
export function getCache(): Cache { | ||
return cache; | ||
} | ||
|
||
export async function finalize(): Promise<void> { | ||
if (repositoryCache !== 'disabled') { | ||
await fs.outputFile(cacheFileName, JSON.stringify(cache)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
lib/workers/repository/process/__snapshots__/extract-update.spec.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters