Skip to content

Commit e289257

Browse files
authored
Merge branch 'main' into fix/32307-global-extends-merging
2 parents 563fba1 + 7ed07b1 commit e289257

File tree

3 files changed

+164
-10
lines changed

3 files changed

+164
-10
lines changed

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

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,5 +162,151 @@ describe('modules/manager/gomod/artifacts-extra', () => {
162162
].join('\n'),
163163
);
164164
});
165+
166+
it('correctly identifies toolchain updates vs go version updates', () => {
167+
const toolChainUpdategoModBefore = codeBlock`
168+
go 1.22.0
169+
170+
toolchain go1.23.0
171+
172+
require (
173+
github.com/foo/foo v1.0.0
174+
github.com/bar/bar v2.0.0
175+
)
176+
`;
177+
178+
const toolChainUpdategoModAfter = codeBlock`
179+
go 1.22.0
180+
181+
toolchain go1.24.0
182+
183+
// Note the order change
184+
require (
185+
github.com/bar/bar v2.2.2
186+
github.com/foo/foo v1.1.1
187+
)
188+
`;
189+
const res = getExtraDepsNotice(
190+
toolChainUpdategoModBefore,
191+
toolChainUpdategoModAfter,
192+
[],
193+
);
194+
195+
expect(res).toEqual(
196+
[
197+
'In order to perform the update(s) described in the table above, Renovate ran the `go get` command, which resulted in the following additional change(s):',
198+
'',
199+
'',
200+
'- 2 additional dependencies were updated',
201+
'',
202+
'',
203+
'Details:',
204+
'',
205+
'',
206+
'| **Package** | **Change** |',
207+
'| :------------------- | :------------------- |',
208+
'| `go (toolchain)` | `1.23.0` -> `1.24.0` |',
209+
'| `github.com/foo/foo` | `v1.0.0` -> `v1.1.1` |',
210+
'| `github.com/bar/bar` | `v2.0.0` -> `v2.2.2` |',
211+
].join('\n'),
212+
);
213+
});
214+
215+
it('correctly identifies and distinguishes toolchain updates vs go version updates when both are present', () => {
216+
const toolChainUpdategoModBefore = codeBlock`
217+
go 1.22.0
218+
219+
toolchain go1.23.0
220+
221+
require (
222+
github.com/foo/foo v1.0.0
223+
github.com/bar/bar v2.0.0
224+
)
225+
`;
226+
227+
const toolChainUpdategoModAfter = codeBlock`
228+
go 1.22.2
229+
230+
toolchain go1.24.0
231+
232+
// Note the order change
233+
require (
234+
github.com/bar/bar v2.2.2
235+
github.com/foo/foo v1.1.1
236+
)
237+
`;
238+
const res = getExtraDepsNotice(
239+
toolChainUpdategoModBefore,
240+
toolChainUpdategoModAfter,
241+
[],
242+
);
243+
244+
expect(res).toEqual(
245+
[
246+
'In order to perform the update(s) described in the table above, Renovate ran the `go get` command, which resulted in the following additional change(s):',
247+
'',
248+
'',
249+
'- 2 additional dependencies were updated',
250+
'- The `go` directive was updated for compatibility reasons',
251+
'',
252+
'',
253+
'Details:',
254+
'',
255+
'',
256+
'| **Package** | **Change** |',
257+
'| :------------------- | :------------------- |',
258+
'| `go` | `1.22.0` -> `1.22.2` |',
259+
'| `go (toolchain)` | `1.23.0` -> `1.24.0` |',
260+
'| `github.com/foo/foo` | `v1.0.0` -> `v1.1.1` |',
261+
'| `github.com/bar/bar` | `v2.0.0` -> `v2.2.2` |',
262+
].join('\n'),
263+
);
264+
});
265+
266+
it('correctly handles the introduction of a toolchain directive by not indicating a change', () => {
267+
const toolChainUpdategoModBefore = codeBlock`
268+
go 1.22.0
269+
270+
require (
271+
github.com/foo/foo v1.0.0
272+
github.com/bar/bar v2.0.0
273+
)
274+
`;
275+
276+
const toolChainUpdategoModAfter = codeBlock`
277+
go 1.22.0
278+
279+
toolchain go1.24.0
280+
281+
// Note the order change
282+
require (
283+
github.com/bar/bar v2.2.2
284+
github.com/foo/foo v1.1.1
285+
)
286+
`;
287+
const res = getExtraDepsNotice(
288+
toolChainUpdategoModBefore,
289+
toolChainUpdategoModAfter,
290+
[],
291+
);
292+
293+
expect(res).toEqual(
294+
[
295+
'In order to perform the update(s) described in the table above, Renovate ran the `go get` command, which resulted in the following additional change(s):',
296+
'',
297+
'',
298+
'- 2 additional dependencies were updated',
299+
'',
300+
'',
301+
'Details:',
302+
'',
303+
'',
304+
'| **Package** | **Change** |',
305+
'| :------------------- | :------------------- |',
306+
'| `github.com/foo/foo` | `v1.0.0` -> `v1.1.1` |',
307+
'| `github.com/bar/bar` | `v2.0.0` -> `v2.2.2` |',
308+
].join('\n'),
309+
);
310+
});
165311
});
166312
});

lib/modules/manager/gomod/artifacts-extra.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,23 @@ export function getExtraDeps(
2626
continue;
2727
}
2828

29-
const { depName, currentValue } = res;
29+
const { depName, depType, currentValue } = res;
3030
if (!depName || !currentValue) {
3131
continue;
3232
}
3333

34+
let expandedDepName = depName;
35+
// NOTE: Right now the only special depType we care about is 'toolchain' because the table
36+
// rendering prior to this change was ambiguous with regards to go version vs toolchain
37+
// version updates.
38+
if (depType === 'toolchain') {
39+
expandedDepName = `${depName} (${depType})`;
40+
}
41+
3442
if (added) {
35-
addDeps[depName] = currentValue;
43+
addDeps[expandedDepName] = currentValue;
3644
} else {
37-
rmDeps[depName] = currentValue;
45+
rmDeps[expandedDepName] = currentValue;
3846
}
3947
}
4048

@@ -92,7 +100,11 @@ export function getExtraDepsNotice(
92100
];
93101

94102
const goUpdated = extraDeps.some(({ depName }) => depName === 'go');
95-
const otherDepsCount = extraDeps.length - (goUpdated ? 1 : 0);
103+
const toolchainUpdated = extraDeps.some(
104+
({ depName }) => depName === 'go (toolchain)',
105+
);
106+
const otherDepsCount =
107+
extraDeps.length - (goUpdated ? 1 : 0) - (toolchainUpdated ? 1 : 0);
96108

97109
if (otherDepsCount === 1) {
98110
noticeLines.push(`- ${otherDepsCount} additional dependency was updated`);

lib/util/git/index.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,7 @@ async function cleanLocalBranches(): Promise<void> {
269269
const existingBranches = (await git.raw(['branch']))
270270
.split(newlineRegex)
271271
.map((branch) => branch.trim())
272-
.filter((branch) => branch.length)
273-
.filter((branch) => !branch.startsWith('* '));
272+
.filter((branch) => branch.length > 0 && !branch.startsWith('* '));
274273
logger.debug({ existingBranches });
275274
for (const branchName of existingBranches) {
276275
await deleteLocalBranch(branchName);
@@ -405,15 +404,12 @@ export async function syncGit(): Promise<void> {
405404
if (await fs.pathExists(gitHead)) {
406405
try {
407406
await git.raw(['remote', 'set-url', 'origin', config.url]);
408-
await resetToBranch(await getDefaultBranch(git));
409407
const fetchStart = Date.now();
410-
await gitRetry(() => git.pull());
411-
await gitRetry(() => git.fetch());
408+
await gitRetry(() => git.fetch(['--prune', 'origin']));
412409
config.currentBranch =
413410
config.currentBranch || (await getDefaultBranch(git));
414411
await resetToBranch(config.currentBranch);
415412
await cleanLocalBranches();
416-
await gitRetry(() => git.raw(['remote', 'prune', 'origin']));
417413
const durationMs = Math.round(Date.now() - fetchStart);
418414
logger.info({ durationMs }, 'git fetch completed');
419415
clone = false;

0 commit comments

Comments
 (0)