Newer
Older
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'
);
}
function validate(config: RenovateConfig, input: any): Cache | null {
if (input?.repository === config.repository) {
logger.debug('Repository cache is valid');
logger.info('Repository cache invalidated');
export async function initialize(config: RenovateConfig): Promise<void> {
try {
cacheFileName = getCacheFileName(config);
repositoryCache = config.repositoryCache;
if (repositoryCache === 'enabled') {
cache = validate(
config,
JSON.parse(await fs.readFile(cacheFileName, 'utf8'))
);
logger.debug({ cacheFileName }, 'Repository cache not found');
cache = cache || { repository: config.repository };