aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRhys Arkins <[email protected]>2024-12-17 17:41:41 +0100
committerGitHub <[email protected]>2024-12-17 16:41:41 +0000
commit8ae744857c18337dd0f8b9c47d5a70e9e4b17b73 (patch)
tree448d6b7f9de5158fd7ab0c330bc323a5de8e8b9d
parent3b9464c8fa4b74e32115a8e167b190bd846ad852 (diff)
downloadrenovate-8ae744857c18337dd0f8b9c47d5a70e9e4b17b73.tar.gz
renovate-8ae744857c18337dd0f8b9c47d5a70e9e4b17b73.zip
fix(cache): add extract revision, stop deleting skipReason (#33172)39.72.2
-rw-r--r--lib/util/cache/repository/types.ts1
-rw-r--r--lib/workers/repository/process/extract-update.spec.ts22
-rw-r--r--lib/workers/repository/process/extract-update.ts26
3 files changed, 43 insertions, 6 deletions
diff --git a/lib/util/cache/repository/types.ts b/lib/util/cache/repository/types.ts
index 3341418e230..f4798c8ab46 100644
--- a/lib/util/cache/repository/types.ts
+++ b/lib/util/cache/repository/types.ts
@@ -8,6 +8,7 @@ import type { RepoInitConfig } from '../../../workers/repository/init/types';
import type { PrBlockedBy } from '../../../workers/types';
export interface BaseBranchCache {
+ revision?: number;
sha: string; // branch commit sha
configHash: string; // object hash of config
extractionFingerprints: Record<string, string | undefined>; // matching manager fingerprints
diff --git a/lib/workers/repository/process/extract-update.spec.ts b/lib/workers/repository/process/extract-update.spec.ts
index 21627e84b9c..220e9c8535e 100644
--- a/lib/workers/repository/process/extract-update.spec.ts
+++ b/lib/workers/repository/process/extract-update.spec.ts
@@ -6,7 +6,13 @@ import { fingerprint } from '../../../util/fingerprint';
import type { LongCommitSha } from '../../../util/git/types';
import { generateFingerprintConfig } from '../extract/extract-fingerprint-config';
import * as _branchify from '../updates/branchify';
-import { extract, isCacheExtractValid, lookup, update } from './extract-update';
+import {
+ EXTRACT_CACHE_REVISION,
+ extract,
+ isCacheExtractValid,
+ lookup,
+ update,
+} from './extract-update';
const createVulnerabilitiesMock = jest.fn();
@@ -97,6 +103,7 @@ describe('workers/repository/process/extract-update', () => {
repositoryCache.getCache.mockReturnValueOnce({
scan: {
master: {
+ revision: EXTRACT_CACHE_REVISION,
sha: '123test',
configHash: fingerprint(generateFingerprintConfig(config)),
extractionFingerprints: {},
@@ -150,6 +157,7 @@ describe('workers/repository/process/extract-update', () => {
beforeEach(() => {
cachedExtract = {
+ revision: EXTRACT_CACHE_REVISION,
sha: 'sha',
configHash: undefined as never,
extractionFingerprints: {},
@@ -162,6 +170,18 @@ describe('workers/repository/process/extract-update', () => {
expect(logger.logger.debug).toHaveBeenCalledTimes(0);
});
+ it('returns false if no revision', () => {
+ delete cachedExtract.revision;
+ expect(isCacheExtractValid('sha', 'hash', cachedExtract)).toBe(false);
+ expect(logger.logger.debug).toHaveBeenCalledTimes(1);
+ });
+
+ it('returns false if revision mismatch', () => {
+ cachedExtract.revision = -1;
+ expect(isCacheExtractValid('sha', 'hash', cachedExtract)).toBe(false);
+ expect(logger.logger.debug).toHaveBeenCalledTimes(1);
+ });
+
it('partial cache', () => {
expect(isCacheExtractValid('sha', 'hash', cachedExtract)).toBe(false);
expect(logger.logger.debug).toHaveBeenCalledTimes(0);
diff --git a/lib/workers/repository/process/extract-update.ts b/lib/workers/repository/process/extract-update.ts
index 75aecabd65a..610e519da73 100644
--- a/lib/workers/repository/process/extract-update.ts
+++ b/lib/workers/repository/process/extract-update.ts
@@ -18,6 +18,9 @@ import { Vulnerabilities } from './vulnerabilities';
import type { WriteUpdateResult } from './write';
import { writeUpdates } from './write';
+// Increment this if needing to cache bust ALL extract caches
+export const EXTRACT_CACHE_REVISION = 1;
+
export interface ExtractResult {
branches: BranchConfig[];
branchList: string[];
@@ -69,7 +72,23 @@ export function isCacheExtractValid(
configHash: string,
cachedExtract?: BaseBranchCache,
): boolean {
- if (!(cachedExtract?.sha && cachedExtract.configHash)) {
+ if (!cachedExtract) {
+ return false;
+ }
+
+ if (!cachedExtract.revision) {
+ logger.debug('Cached extract is missing revision, so cannot be used');
+ return false;
+ }
+
+ if (cachedExtract.revision !== EXTRACT_CACHE_REVISION) {
+ logger.debug(
+ `Extract cache revision has changed (old=${cachedExtract.revision}, new=${EXTRACT_CACHE_REVISION})`,
+ );
+ return false;
+ }
+
+ if (!(cachedExtract.sha && cachedExtract.configHash)) {
return false;
}
if (cachedExtract.sha !== baseBranchSha) {
@@ -128,10 +147,6 @@ export async function extract(
for (const file of files) {
for (const dep of file.deps) {
delete dep.updates;
- if (dep.skipStage && dep.skipStage !== 'extract') {
- delete dep.skipReason;
- delete dep.skipStage;
- }
}
}
}
@@ -146,6 +161,7 @@ export async function extract(
const { extractionFingerprints } = extractResult;
// TODO: fix types (#22198)
cache.scan[baseBranch!] = {
+ revision: EXTRACT_CACHE_REVISION,
sha: baseBranchSha!,
configHash,
extractionFingerprints,