Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/workers/repository/process/write.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type { BranchConfig, BranchUpgradeConfig } from '../../types';
import * as _branchWorker from '../update/branch';
import * as _limits from './limits';
import {
canSkipBranchUpdateCheck,
compareCacheFingerprint,
generateCommitFingerprintConfig,
syncBranchState,
writeUpdates,
Expand Down Expand Up @@ -358,7 +358,9 @@ describe('workers/repository/process/write', () => {
branchName: 'new/some-branch',
sha: '111',
};
expect(canSkipBranchUpdateCheck(branchCache, '222')).toBe(false);
expect(compareCacheFingerprint(branchCache, '222')).toBe(
'no-fingerprint',
);
});

it('returns false when fingerprints are not same', () => {
Expand All @@ -368,7 +370,7 @@ describe('workers/repository/process/write', () => {
sha: '111',
commitFingerprint: '211',
};
expect(canSkipBranchUpdateCheck(branchCache, '222')).toBe(false);
expect(compareCacheFingerprint(branchCache, '222')).toBe('no-match');
});

it('returns true', () => {
Expand All @@ -378,7 +380,7 @@ describe('workers/repository/process/write', () => {
sha: '111',
commitFingerprint: '222',
};
expect(canSkipBranchUpdateCheck(branchCache, '222')).toBe(true);
expect(compareCacheFingerprint(branchCache, '222')).toBe('matched');
});
});

Expand Down
18 changes: 11 additions & 7 deletions lib/workers/repository/process/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import type { BranchCache } from '../../../util/cache/repository/types';
import { fingerprint } from '../../../util/fingerprint';
import { setBranchNewCommit } from '../../../util/git/set-branch-commit';
import { incCountValue, setCount } from '../../global/limits';
import type { BranchConfig, UpgradeFingerprintConfig } from '../../types';
import type {
BranchConfig,
CacheFingerprintMatchResult,
UpgradeFingerprintConfig,
} from '../../types';
import { processBranch } from '../update/branch';
import { upgradeFingerprintFields } from './fingerprint-fields';
import {
Expand All @@ -33,22 +37,22 @@ export function generateCommitFingerprintConfig(
return res;
}

export function canSkipBranchUpdateCheck(
export function compareCacheFingerprint(
branchState: BranchCache,
commitFingerprint: string,
): boolean {
): CacheFingerprintMatchResult {
if (!branchState.commitFingerprint) {
logger.trace('branch.isUpToDate(): no fingerprint');
return false;
return 'no-fingerprint';
}

if (commitFingerprint !== branchState.commitFingerprint) {
logger.debug('branch.isUpToDate(): needs recalculation');
return false;
return 'no-match';
}

logger.debug('branch.isUpToDate(): using cached result "true"');
return true;
return 'matched';
}

export async function syncBranchState(
Expand Down Expand Up @@ -156,7 +160,7 @@ export async function writeUpdates(
commitFingerprintConfig: generateCommitFingerprintConfig(branch),
managers,
});
branch.skipBranchUpdate = canSkipBranchUpdateCheck(
branch.cacheFingerprintMatch = compareCacheFingerprint(
branchState,
commitFingerprint,
);
Expand Down
44 changes: 40 additions & 4 deletions lib/workers/repository/update/branch/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ import * as _mergeConfidence from '../../../../util/merge-confidence';
import * as _sanitize from '../../../../util/sanitize';
import type { Timestamp } from '../../../../util/timestamp';
import * as _limits from '../../../global/limits';
import type { BranchConfig, BranchUpgradeConfig } from '../../../types';
import type {
BranchConfig,
BranchUpgradeConfig,
CacheFingerprintMatchResult,
} from '../../../types';
import type { ResultWithPr } from '../pr';
import * as _prWorker from '../pr';
import * as _prAutomerge from '../pr/automerge';
Expand Down Expand Up @@ -897,6 +901,38 @@ describe('workers/repository/update/branch/index', () => {
expect(prWorker.ensurePr).toHaveBeenCalledTimes(0);
});

it('updates branch when no fingerprint match', async () => {
expect.assertions(3);
getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce(
partial<PackageFilesResult>({
updatedPackageFiles: [partial<FileChange>()],
}),
);
npmPostExtract.getAdditionalFiles.mockResolvedValueOnce({
artifactErrors: [],
updatedArtifacts: [partial<FileChange>()],
});
const inconfig = {
...config,
ignoreTests: true,
prCreation: 'not-pending',
commitBody: '[skip-ci]',
fetchChangeLogs: 'branch',
cacheFingerprintMatch: 'no-match',
} satisfies BranchConfig;
scm.getBranchCommit.mockResolvedValue('123test' as LongCommitSha); //TODO:not needed?
expect(await branchWorker.processBranch(inconfig)).toEqual({
branchExists: true,
updatesVerified: true,
prNo: undefined,
result: 'pending',
commitSha: '123test',
});

expect(automerge.tryBranchAutomerge).toHaveBeenCalledTimes(0);
expect(prWorker.ensurePr).toHaveBeenCalledTimes(0);
});

it('ensures PR and comments notice', async () => {
getUpdated.getUpdatedPackageFiles.mockResolvedValueOnce(
partial<PackageFilesResult>({
Expand Down Expand Up @@ -1226,7 +1262,7 @@ describe('workers/repository/update/branch/index', () => {
await branchWorker.processBranch({
...config,
baseBranch: 'new_base',
skipBranchUpdate: true,
cacheFingerprintMatch: 'matched',
});
expect(logger.debug).toHaveBeenCalledWith(
'Base branch changed by user, rebasing the branch onto new base',
Expand Down Expand Up @@ -1480,7 +1516,7 @@ describe('workers/repository/update/branch/index', () => {
branchPrefixOld: 'old/',
commitFingerprint: '111',
reuseExistingBranch: true,
skipBranchUpdate: true,
cacheFingerprintMatch: 'matched' as CacheFingerprintMatchResult,
};
expect(await branchWorker.processBranch(inconfig)).toEqual({
branchExists: true,
Expand Down Expand Up @@ -2500,7 +2536,7 @@ describe('workers/repository/update/branch/index', () => {
}),
);
config.reuseExistingBranch = true;
config.skipBranchUpdate = true;
config.cacheFingerprintMatch = 'matched';
const inconfig = {
...config,
branchName: 'new/some-branch',
Expand Down
11 changes: 10 additions & 1 deletion lib/workers/repository/update/branch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,12 +475,21 @@ export async function processBranch(
'Base branch changed by user, rebasing the branch onto new base',
);
config.reuseExistingBranch = false;
} else if (config.cacheFingerprintMatch === 'no-match') {
logger.debug(
'Cache fingerprint does not match, cannot reuse existing branch',
);
config.reuseExistingBranch = false;
} else {
config = await shouldReuseExistingBranch(config);
}
// TODO: types (#22198)
logger.debug(`Using reuseExistingBranch: ${config.reuseExistingBranch!}`);
if (!(config.reuseExistingBranch && config.skipBranchUpdate)) {
if (
!(
config.reuseExistingBranch && config.cacheFingerprintMatch === 'matched'
)
) {
await scm.checkoutBranch(config.baseBranch);
const res = await getUpdatedPackageFiles(config);
// istanbul ignore if
Expand Down
7 changes: 6 additions & 1 deletion lib/workers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ export type BranchResult =
| 'rebase'
| 'update-not-scheduled';

export type CacheFingerprintMatchResult =
| 'matched'
| 'no-match'
| 'no-fingerprint';

export interface BranchConfig
extends BranchUpgradeConfig,
LegacyAdminConfig,
Expand All @@ -135,7 +140,7 @@ export interface BranchConfig
stopUpdating?: boolean;
isConflicted?: boolean;
commitFingerprint?: string;
skipBranchUpdate?: boolean;
cacheFingerprintMatch?: CacheFingerprintMatchResult;
}

export interface BranchMetadata {
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,13 @@
"@cdktf/hcl2json": "0.21.0",
"@opentelemetry/api": "1.9.0",
"@opentelemetry/context-async-hooks": "2.0.1",
"@opentelemetry/exporter-trace-otlp-http": "0.202.0",
"@opentelemetry/instrumentation": "0.202.0",
"@opentelemetry/instrumentation-bunyan": "0.48.0",
"@opentelemetry/instrumentation-http": "0.202.0",
"@opentelemetry/resource-detector-aws": "2.2.0",
"@opentelemetry/resource-detector-azure": "0.9.0",
"@opentelemetry/resource-detector-gcp": "0.36.0",
"@opentelemetry/exporter-trace-otlp-http": "0.203.0",
"@opentelemetry/instrumentation": "0.203.0",
"@opentelemetry/instrumentation-bunyan": "0.49.0",
"@opentelemetry/instrumentation-http": "0.203.0",
"@opentelemetry/resource-detector-aws": "2.3.0",
"@opentelemetry/resource-detector-azure": "0.10.0",
"@opentelemetry/resource-detector-gcp": "0.37.0",
"@opentelemetry/resource-detector-github": "0.31.0",
"@opentelemetry/resources": "2.0.1",
"@opentelemetry/sdk-trace-base": "2.0.1",
Expand Down Expand Up @@ -276,7 +276,7 @@
"@ls-lint/ls-lint": "2.3.1",
"@openpgp/web-stream-tools": "0.1.3",
"@semantic-release/exec": "7.1.0",
"@smithy/util-stream": "4.2.2",
"@smithy/util-stream": "4.2.3",
"@types/auth-header": "1.0.6",
"@types/aws4": "1.11.6",
"@types/better-sqlite3": "7.6.13",
Expand Down
Loading
Loading