fix(cache): skip save repo cache on dry-run (#19094)

This commit is contained in:
Michael Kriese 2022-11-25 10:33:16 +01:00 committed by GitHub
parent 325a11257d
commit 7603bebd03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View file

@ -36,6 +36,18 @@ describe('util/cache/repository/index', () => {
expect(isCacheModified()).toBeUndefined(); expect(isCacheModified()).toBeUndefined();
}); });
it('skips saves cache on dry run', async () => {
GlobalConfig.set({
cacheDir: '/tmp/cache',
platform: 'github',
dryRun: true,
});
await initRepoCache({ ...config, repositoryCache: 'enabled' });
await saveCache();
expect(fs.outputCacheFile).not.toHaveBeenCalled();
expect(isCacheModified()).toBeUndefined();
});
it('resets cache', async () => { it('resets cache', async () => {
await initRepoCache({ ...config, repositoryCache: 'reset' }); await initRepoCache({ ...config, repositoryCache: 'reset' });
expect(fs.readCacheFile).not.toHaveBeenCalled(); expect(fs.readCacheFile).not.toHaveBeenCalled();

View file

@ -1,3 +1,5 @@
import { GlobalConfig } from '../../../config/global';
import { logger } from '../../../logger';
import { RepoCacheNull } from './impl/null'; import { RepoCacheNull } from './impl/null';
import type { RepoCache, RepoCacheData } from './types'; import type { RepoCache, RepoCacheData } from './types';
@ -18,7 +20,11 @@ export function getCache(): RepoCacheData {
} }
export async function saveCache(): Promise<void> { export async function saveCache(): Promise<void> {
if (GlobalConfig.get('dryRun')) {
logger.info(`DRY-RUN: Would save repository cache.`);
} else {
await repoCache.save(); await repoCache.save();
}
} }
export function isCacheModified(): boolean | undefined { export function isCacheModified(): boolean | undefined {