Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: exclude unstable data from cache fingerprints #18148

Merged
merged 7 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/config/options/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ const options: RenovateOptions[] = [
globalOnly: true,
type: 'string',
default: null,
stage: 'global',
viceice marked this conversation as resolved.
Show resolved Hide resolved
},
// Onboarding
{
Expand Down
6 changes: 6 additions & 0 deletions lib/util/fingerprint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import hasha from 'hasha';
import { safeStringify } from './stringify';

export function fingerprint(input: unknown): string {
return hasha(safeStringify(input));
}
4 changes: 2 additions & 2 deletions lib/workers/repository/process/extract-update.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import hasha from 'hasha';
import { git, mocked } from '../../../../test/util';
import type { PackageFile } from '../../../modules/manager/types';
import * as _repositoryCache from '../../../util/cache/repository';
import { fingerprint } from '../../../util/fingerprint';
import * as _branchify from '../updates/branchify';
import { extract, lookup, update } from './extract-update';

Expand Down Expand Up @@ -71,7 +71,7 @@ describe('workers/repository/process/extract-update', () => {
scan: {
master: {
sha: '123test',
configHash: hasha(JSON.stringify(config)),
configHash: fingerprint(config),
packageFiles,
},
},
Expand Down
7 changes: 5 additions & 2 deletions lib/workers/repository/process/extract-update.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// TODO #7154
import is from '@sindresorhus/is';
import hasha from 'hasha';
import type { RenovateConfig } from '../../../config/types';
import { logger } from '../../../logger';
import type { PackageFile } from '../../../modules/manager/types';
import { getCache } from '../../../util/cache/repository';
import { checkGithubToken as ensureGithubToken } from '../../../util/check-token';
import { fingerprint } from '../../../util/fingerprint';
import { checkoutBranch, getBranchCommit } from '../../../util/git';
import type { BranchConfig } from '../../types';
import { extractAllDependencies } from '../extract';
Expand Down Expand Up @@ -71,7 +71,10 @@ export async function extract(
const cache = getCache();
cache.scan ||= {};
const cachedExtract = cache.scan[baseBranch!];
const configHash = hasha(JSON.stringify(config));
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { packageRules, ...remainingConfig } = config;
rarkins marked this conversation as resolved.
Show resolved Hide resolved
// Calculate hash excluding packageRules, because they're not applied during extract
const configHash = fingerprint(remainingConfig);
// istanbul ignore if
if (
cachedExtract?.sha === baseBranchSha &&
Expand Down
57 changes: 27 additions & 30 deletions lib/workers/repository/process/write.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import is from '@sindresorhus/is';
import hasha from 'hasha';
import {
RenovateConfig,
getConfig,
Expand All @@ -16,6 +15,7 @@ import type {
BranchCache,
RepoCacheData,
} from '../../../util/cache/repository/types';
import { fingerprint } from '../../../util/fingerprint';
import { Limit, isLimitReached } from '../../global/limits';
import { BranchConfig, BranchResult, BranchUpgradeConfig } from '../../types';
import * as _branchWorker from '../update/branch';
Expand Down Expand Up @@ -166,21 +166,20 @@ describe('workers/repository/process/write', () => {
result: BranchResult.Done,
commitSha: 'some-value',
});
const branchManagersFingerprint = hasha(
[
...new Set(
branches[0].upgrades
.map((upgrade) => hashMap.get(upgrade.manager) ?? upgrade.manager)
.filter(is.string)
),
].sort()
);
const fingerprint = hasha([
JSON.stringify(branches[0]),
branchManagersFingerprint,
]);
const branch = branches[0];
const managers = [
...new Set(
branch.upgrades
.map((upgrade) => hashMap.get(upgrade.manager) ?? upgrade.manager)
.filter(is.string)
),
].sort();
const branchFingerprint = fingerprint({
branch,
managers,
});
expect(await writeUpdates(config, branches)).toBe('done');
expect(branches[0].branchFingerprint).toBe(fingerprint);
expect(branch.branchFingerprint).toBe(branchFingerprint);
});

it('caches same fingerprint when no commit is made', async () => {
Expand All @@ -196,25 +195,23 @@ describe('workers/repository/process/write', () => {
],
},
]);
const branchManagersFingerprint = hasha(
[
...new Set(
branches[0].upgrades
.map((upgrade) => hashMap.get(upgrade.manager) ?? upgrade.manager)
.filter(is.string)
),
].sort()
);
const fingerprint = hasha([
JSON.stringify(branches[0]),
branchManagersFingerprint,
]);
const managers = [
...new Set(
branches[0].upgrades
.map((upgrade) => hashMap.get(upgrade.manager) ?? upgrade.manager)
.filter(is.string)
),
].sort();
const branchFingerprint = fingerprint({
branches: JSON.stringify(branches[0]),
managers,
});
repoCache.getCache.mockReturnValueOnce({
branches: [
{
branchName: 'new/some-branch',
baseBranch: 'base_branch',
branchFingerprint: fingerprint,
branchFingerprint,
} as BranchCache,
],
});
Expand All @@ -223,7 +220,7 @@ describe('workers/repository/process/write', () => {
result: BranchResult.Done,
});
expect(await writeUpdates(config, branches)).toBe('done');
expect(branches[0].branchFingerprint).toBe(fingerprint);
expect(branches[0].branchFingerprint).toBe(branchFingerprint);
});

it('creates new branchCache when cache is not enabled', async () => {
Expand Down
27 changes: 12 additions & 15 deletions lib/workers/repository/process/write.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import is from '@sindresorhus/is';
import hasha from 'hasha';
import stringify from 'safe-stable-stringify';
import type { RenovateConfig } from '../../../config/types';
import { addMeta, logger, removeMeta } from '../../../logger';
import { hashMap } from '../../../modules/manager';
import { getCache } from '../../../util/cache/repository';
import type { BranchCache } from '../../../util/cache/repository/types';
import { fingerprint } from '../../../util/fingerprint';
import { branchExists, getBranchCommit } from '../../../util/git';
import { setBranchNewCommit } from '../../../util/git/set-branch-commit';
import { Limit, incLimitedValue, setMaxLimit } from '../../global/limits';
Expand Down Expand Up @@ -124,19 +123,17 @@ export async function writeUpdates(
// TODO: base branch name cannot be undefined - fix optional types (#7154)
const branchState = syncBranchState(branchName, baseBranch!);

const branchManagersFingerprint = hasha(
[
...new Set(
branch.upgrades
.map((upgrade) => hashMap.get(upgrade.manager) ?? upgrade.manager)
.filter(is.string)
),
].sort()
);
const branchFingerprint = hasha([
stringify(branch),
branchManagersFingerprint,
]);
const managers = [
...new Set(
branch.upgrades
.map((upgrade) => hashMap.get(upgrade.manager) ?? upgrade.manager)
.filter(is.string)
),
].sort();
const branchFingerprint = fingerprint({
branch,
managers,
});
branch.skipBranchUpdate = canSkipBranchUpdateCheck(
branchState,
branchFingerprint
Expand Down