Skip to content

Commit

Permalink
fix(gomod): update toolchain (#28476)
Browse files Browse the repository at this point in the history
Co-authored-by: Sebastian Poxhofer <secustor@users.noreply.github.com>
  • Loading branch information
rarkins and secustor committed Apr 17, 2024
1 parent 5ce3e23 commit 0354bcb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/modules/manager/gomod/__fixtures__/3/go-mod
Expand Up @@ -131,3 +131,6 @@ replace (
k8s.io/sample-cli-plugin => k8s.io/sample-cli-plugin v0.17.3
k8s.io/sample-controller => k8s.io/sample-controller v0.17.3
)

toolchain go1.22.1

12 changes: 12 additions & 0 deletions lib/modules/manager/gomod/update.spec.ts
Expand Up @@ -32,6 +32,18 @@ describe('modules/manager/gomod/update', () => {
expect(res).toContain(upgrade.newValue);
});

it('replaces go toolchain', () => {
const upgrade = {
depName: 'go',
managerData: { lineNumber: 134 },
newValue: '1.22.2',
depType: 'toolchain',
};
const res = updateDependency({ fileContent: gomod3, upgrade });
expect(res).not.toEqual(gomod3);
expect(res).toContain(upgrade.newValue);
});

it('replaces two values in one file', () => {
const upgrade1 = {
depName: 'github.com/pkg/errors',
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/manager/gomod/update.ts
Expand Up @@ -34,6 +34,7 @@ export function updateDependency({
return null;
}
const lineToChange = lines[upgrade.managerData.lineNumber];
logger.trace({ upgrade, lineToChange }, 'go.mod current line');
if (
!lineToChange.includes(depNameNoVersion) &&
!lineToChange.includes('rethinkdb/rethinkdb-go.v5')
Expand All @@ -46,7 +47,7 @@ export function updateDependency({
}
let updateLineExp: RegExp | undefined;

if (depType === 'golang') {
if (depType === 'golang' || depType === 'toolchain') {
updateLineExp = regEx(
/(?<depPart>(?:toolchain )?go)(?<divider>\s*)([^\s]+|[\w]+)/,
);
Expand Down

0 comments on commit 0354bcb

Please sign in to comment.