Skip to content

Commit 1a99c23

Browse files
author
Maydaer
committed
fix(gomod): pseudo-version digest updates produce no change when module
is absent from go proxy
1 parent 27cc994 commit 1a99c23

2 files changed

Lines changed: 38 additions & 5 deletions

File tree

lib/modules/manager/gomod/update.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,33 @@ describe('modules/manager/gomod/update', () => {
400400
expect(res).not.toContain('knative.dev/pkg 4a022ed9999a');
401401
});
402402

403+
it('falls back to bare hash when newValue equals currentValue', () => {
404+
const fileContent = codeBlock`
405+
module example.com/test
406+
require (
407+
example.private.com/org/module v0.0.0-20250312035536-b7bbf4be5dbd
408+
)
409+
`;
410+
const upgrade = {
411+
depName: 'example.private.com/org/module',
412+
managerData: { lineNumber: 2, multiLine: true },
413+
updateType: 'digest' as const,
414+
currentValue: 'v0.0.0-20250312035536-b7bbf4be5dbd',
415+
currentDigest: 'b7bbf4be5dbd',
416+
newValue: 'v0.0.0-20250312035536-b7bbf4be5dbd',
417+
newDigest: '4a022ed9999a',
418+
depType: 'require',
419+
};
420+
const res = updateDependency({
421+
fileContent,
422+
packageFile: 'go.mod',
423+
upgrade,
424+
});
425+
// Should fall back to bare hash since newValue === currentValue
426+
expect(res).toContain('example.private.com/org/module 4a022ed9999a');
427+
expect(res).not.toContain('b7bbf4be5dbd');
428+
});
429+
403430
it('handles multiline mismatch', () => {
404431
const upgrade = {
405432
depName: 'github.com/fatih/color',

lib/modules/manager/gomod/update.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,13 @@ export function updateDependency({
8383
// Since the 2024 goproxy datasource changes, newValue and newDigest are
8484
// both extracted from the same proxy version string and always reference
8585
// the same commit, so newValue can be written directly for pseudo-versions.
86-
if (upgrade.newValue?.startsWith('v0.0.0-')) {
86+
// However, for private modules (GONOPROXY / direct datasource), the proxy
87+
// has no data and newValue may equal currentValue. In that case, fall
88+
// through to the bare hash path so that gomodTidy can resolve it.
89+
if (
90+
upgrade.newValue?.startsWith('v0.0.0-') &&
91+
upgrade.newValue !== upgrade.currentValue
92+
) {
8793
logger.debug(
8894
{ depName: currentName, lineToChange, newValue: upgrade.newValue },
8995
'gomod: updating pseudo-version digest',
@@ -94,10 +100,10 @@ export function updateDependency({
94100
`$<depPart>$<divider>${upgrade.newValue}`,
95101
);
96102
} else {
97-
// Defensive fallback for non-pseudo-version digest updates.
98-
// Unreachable for gomod in practice: currentDigest is only extracted
99-
// for pseudo-versions, and the gomod override in lookup/index.ts that
100-
// sets updateType='digest' requires newValue to start with 'v0.0.0-'.
103+
// Fallback for private modules where the proxy could not resolve a new
104+
// pseudo-version, or non-pseudo-version digest updates.
105+
// Writes the bare hash so that postUpdateOptions like gomodTidy can
106+
// normalize it into a valid pseudo-version via `go get`.
101107
const newDigestRightSized = upgrade.newDigest!.substring(
102108
0,
103109
upgrade.currentDigest!.length,

0 commit comments

Comments
 (0)