Skip to content

Commit 8f46eb1

Browse files
committed
add notice when nothing changed
1 parent 9064156 commit 8f46eb1

File tree

2 files changed

+76
-2
lines changed

2 files changed

+76
-2
lines changed

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

+56-1
Original file line numberDiff line numberDiff line change
@@ -2304,7 +2304,7 @@ describe('modules/manager/gomod/artifacts', () => {
23042304
]);
23052305
});
23062306

2307-
it('go.mod file contains moder go full version without toolchain and constraint is present', async () => {
2307+
it('go.mod file contains modern go full version without toolchain and constraint is present', async () => {
23082308
GlobalConfig.set({ ...adminConfig, binarySource: 'install' });
23092309
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
23102310
fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename
@@ -2587,6 +2587,61 @@ describe('modules/manager/gomod/artifacts', () => {
25872587
expect(execSnapshots).toMatchObject(expectedResult);
25882588
});
25892589

2590+
it('with config constraint that does not result in any updates', async () => {
2591+
GlobalConfig.set({ ...adminConfig, binarySource: 'install' });
2592+
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
2593+
fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename
2594+
const execSnapshots = mockExecAll();
2595+
git.getRepoStatus.mockResolvedValueOnce(
2596+
partial<StatusResult>({
2597+
modified: [],
2598+
}),
2599+
);
2600+
fs.readLocalFile
2601+
.mockResolvedValueOnce('Current go.sum')
2602+
.mockResolvedValueOnce(`someText\n\ngo 1.23.6\n\n${gomod1}`);
2603+
2604+
datasource.getPkgReleases.mockResolvedValueOnce({
2605+
releases: [
2606+
{ version: '1.23.0' },
2607+
{ version: '1.23.6' },
2608+
{ version: '1.24.1' },
2609+
],
2610+
});
2611+
2612+
const res = await gomod.updateArtifacts({
2613+
packageFileName: 'go.mod',
2614+
updatedDeps: [{ depName: 'golang.org/x/crypto', newVersion: '0.35.0' }],
2615+
newPackageFileContent: `someText\n\ngo 1.23.6\n\n${gomod1}`,
2616+
config: {
2617+
updateType: 'minor',
2618+
constraints: {
2619+
go: '1.23',
2620+
},
2621+
},
2622+
});
2623+
2624+
expect(res).toEqual([
2625+
{
2626+
notice: {
2627+
file: 'go.mod',
2628+
message:
2629+
'Updates are constrained to go version 1.23 but the dependency required a more recent version.\nTherefore, the update was discarded.',
2630+
},
2631+
},
2632+
]);
2633+
2634+
expect(execSnapshots).toMatchObject([
2635+
{
2636+
cmd: 'install-tool golang 1.23.6',
2637+
},
2638+
{
2639+
cmd: 'go get -t ./... toolchain@none [email protected]',
2640+
// simulated to result in no changes since no more recent dependency version satisfies the constraint
2641+
},
2642+
]);
2643+
});
2644+
25902645
it('returns artifact notices', async () => {
25912646
artifactsExtra.getExtraDepsNotice.mockReturnValue('some extra notice');
25922647
GlobalConfig.set({ ...adminConfig, binarySource: 'docker' });

lib/modules/manager/gomod/artifacts.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ export async function updateArtifacts({
238238
// because the dependencies' go.mod is not in 'updatedDeps' to determine
239239
// which highest version is actually required.
240240
extraGetArguments.push(`go@${goConstraint}`);
241+
// TODO: if we are already at latest compatible version, then renovate still bumps it
242+
// instead the PR should be erroring out!!
241243
}
242244
}
243245
}
@@ -386,7 +388,25 @@ export async function updateArtifacts({
386388

387389
await exec(execCommands, execOptions);
388390

391+
const res: UpdateArtifactsResult[] = [];
389392
const status = await getRepoStatus();
393+
if (
394+
status.modified.length === 0 &&
395+
updatedDeps.length > 0 &&
396+
config.constraints?.go
397+
) {
398+
const downgradeNotice = `Updates are constrained to go version ${config.constraints.go} but the dependency required a more recent version.\nTherefore, the update was discarded.`;
399+
400+
logger.debug('Returning no update warning');
401+
res.push({
402+
notice: {
403+
file: goModFileName,
404+
message: downgradeNotice,
405+
},
406+
});
407+
408+
return res;
409+
}
390410
if (
391411
!status.modified.includes(sumFileName) &&
392412
!status.modified.includes(goModFileName) &&
@@ -395,7 +415,6 @@ export async function updateArtifacts({
395415
return null;
396416
}
397417

398-
const res: UpdateArtifactsResult[] = [];
399418
if (status.modified.includes(sumFileName)) {
400419
logger.debug('Returning updated go.sum');
401420
res.push({

0 commit comments

Comments
 (0)