Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gomod): preserve go/toolchain directives #34779

Open
wants to merge 35 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
72f8adf
preserve go mod toolchain directive in any case
trim21 Mar 13, 2025
3629f60
preserve go mod toolchain directive in any case
trim21 Mar 13, 2025
ab9f5b9
add more test
trim21 Mar 13, 2025
be3d457
fix eslint
trim21 Mar 13, 2025
0d94a80
fix regex
trim21 Mar 13, 2025
59a450d
Update lib/modules/manager/gomod/artifacts.ts
trim21 Mar 13, 2025
4b3fd95
Update lib/modules/manager/gomod/artifacts.ts
trim21 Mar 13, 2025
7843e56
preserve -d location
trim21 Mar 13, 2025
3f2750a
better variable name
trim21 Mar 13, 2025
4db59ef
Merge branch 'main' into fix/go-mod-toolchain
trim21 Mar 13, 2025
125e3db
preserve go/toolchain directive
trim21 Mar 13, 2025
de81b17
fix constraints
trim21 Mar 13, 2025
1667c12
fix test
trim21 Mar 13, 2025
ffe38b8
keep old flag order
trim21 Mar 13, 2025
6f2afba
go: control updates of directives when constraint is present
casaqori Apr 2, 2025
9064156
Merge branch 'main' into fix/go-mod-toolchain
trim21 Apr 2, 2025
8f46eb1
add notice when nothing changed
casaqori Apr 2, 2025
f91d392
Merge branch 'main' into fix/go-mod-toolchain
trim21 Apr 3, 2025
2fc88c9
Revert "add notice when nothing changed"
trim21 Apr 5, 2025
875aa50
revert
trim21 Apr 5, 2025
ed66459
fix version
trim21 Apr 5, 2025
a4c4690
fix test
trim21 Apr 5, 2025
e238578
use join instead of string concat
trim21 Apr 5, 2025
0eb2aac
handle major upgrade
trim21 Apr 5, 2025
26c511c
fix lint
trim21 Apr 5, 2025
ffec247
cov
trim21 Apr 5, 2025
5264a45
cov
trim21 Apr 5, 2025
0858735
docs
trim21 Apr 5, 2025
c3bf9f8
fix(gomod): disable toolchain switch
trim21 Apr 7, 2025
dea2c8c
fix(gomod): disable toolchain switch
trim21 Apr 7, 2025
e321b50
pick minial version
trim21 Apr 11, 2025
60bdc84
Merge remote-tracking branch 'origin/fix/go-no-switch-toolchain' into…
trim21 Apr 11, 2025
f72f7ed
fix test
trim21 Apr 11, 2025
6a5b70d
fix test
trim21 Apr 11, 2025
575376f
add comment
trim21 Apr 11, 2025
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
187 changes: 176 additions & 11 deletions lib/modules/manager/gomod/artifacts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ describe('modules/manager/gomod/artifacts', () => {
'docker run --rm --name=renovate_sidecar --label=renovate_child ' +
'-v "/tmp/github/some/repo":"/tmp/github/some/repo" ' +
'-v "/tmp/renovate/cache":"/tmp/renovate/cache" ' +
'-e GOTOOLCHAIN ' +
'-e GOPROXY ' +
'-e GOPRIVATE ' +
'-e GONOPROXY ' +
Expand Down Expand Up @@ -724,6 +725,7 @@ describe('modules/manager/gomod/artifacts', () => {
'docker run --rm --name=renovate_sidecar --label=renovate_child ' +
'-v "/tmp/github/some/repo":"/tmp/github/some/repo" ' +
'-v "/tmp/renovate/cache":"/tmp/renovate/cache" ' +
'-e GOTOOLCHAIN ' +
'-e GOPROXY ' +
'-e GOPRIVATE ' +
'-e GONOPROXY ' +
Expand Down Expand Up @@ -1247,6 +1249,7 @@ describe('modules/manager/gomod/artifacts', () => {
'docker run --rm --name=renovate_sidecar --label=renovate_child ' +
'-v "/tmp/github/some/repo":"/tmp/github/some/repo" ' +
'-v "/tmp/renovate/cache":"/tmp/renovate/cache" ' +
'-e GOTOOLCHAIN ' +
'-e GOPROXY ' +
'-e GOPRIVATE ' +
'-e GONOPROXY ' +
Expand Down Expand Up @@ -1311,6 +1314,7 @@ describe('modules/manager/gomod/artifacts', () => {
'docker run --rm --name=renovate_sidecar --label=renovate_child ' +
'-v "/tmp/github/some/repo":"/tmp/github/some/repo" ' +
'-v "/tmp/renovate/cache":"/tmp/renovate/cache" ' +
'-e GOTOOLCHAIN ' +
'-e GOPROXY ' +
'-e GOPRIVATE ' +
'-e GONOPROXY ' +
Expand Down Expand Up @@ -1375,6 +1379,7 @@ describe('modules/manager/gomod/artifacts', () => {
'docker run --rm --name=renovate_sidecar --label=renovate_child ' +
'-v "/tmp/github/some/repo":"/tmp/github/some/repo" ' +
'-v "/tmp/renovate/cache":"/tmp/renovate/cache" ' +
'-e GOTOOLCHAIN ' +
'-e GOPROXY ' +
'-e GOPRIVATE ' +
'-e GONOPROXY ' +
Expand Down Expand Up @@ -1439,6 +1444,7 @@ describe('modules/manager/gomod/artifacts', () => {
'docker run --rm --name=renovate_sidecar --label=renovate_child ' +
'-v "/tmp/github/some/repo":"/tmp/github/some/repo" ' +
'-v "/tmp/renovate/cache":"/tmp/renovate/cache" ' +
'-e GOTOOLCHAIN ' +
'-e GOPROXY ' +
'-e GOPRIVATE ' +
'-e GONOPROXY ' +
Expand Down Expand Up @@ -2024,7 +2030,7 @@ describe('modules/manager/gomod/artifacts', () => {
{ file: { type: 'addition', path: 'go.mod', contents: 'New go.mod' } },
]);
expect(execSnapshots).toMatchObject([
{ cmd: 'install-tool golang 1.23.3' },
{ cmd: 'install-tool golang 1.16.0' },
{
cmd: 'go get -d -t ./...',
options: { cwd: '/tmp/github/some/repo' },
Expand Down Expand Up @@ -2092,6 +2098,7 @@ describe('modules/manager/gomod/artifacts', () => {
'docker run --rm --name=renovate_sidecar --label=renovate_child ' +
'-v "/tmp/github/some/repo":"/tmp/github/some/repo" ' +
'-v "/tmp/renovate/cache":"/tmp/renovate/cache" ' +
'-e GOTOOLCHAIN ' +
'-e GOPROXY ' +
'-e GOPRIVATE ' +
'-e GONOPROXY ' +
Expand All @@ -2103,9 +2110,9 @@ describe('modules/manager/gomod/artifacts', () => {
'-w "/tmp/github/some/repo" ' +
'ghcr.io/containerbase/sidecar' +
' bash -l -c "' +
'install-tool golang 1.23.3' +
'install-tool golang 1.17.0' +
' && ' +
'go get -d -t ./...' +
'go get -t ./...' +
' && ' +
'go install github.com/marwan-at-work/mod/cmd/mod@latest' +
' && ' +
Expand Down Expand Up @@ -2134,10 +2141,18 @@ describe('modules/manager/gomod/artifacts', () => {
.mockResolvedValueOnce('New go.sum')
.mockResolvedValueOnce('New go.mod');

datasource.getPkgReleases.mockResolvedValueOnce({
releases: [
{ version: '1.17.0' },
{ version: '1.23.3' },
{ version: '1.23.6' },
],
});

const res = await gomod.updateArtifacts({
packageFileName: 'go.mod',
updatedDeps: [{ depName: 'golang.org/x/crypto', newVersion: '0.35.0' }],
newPackageFileContent: `someText\n\ngo 1.13\n\ntoolchain go1.23.6\n\n${gomod1}`,
newPackageFileContent: `someText\n\ngo 1.23\n\ntoolchain go1.23.6\n\n${gomod1}`,
config: {
updateType: 'minor',
},
Expand All @@ -2150,14 +2165,12 @@ describe('modules/manager/gomod/artifacts', () => {

expect(execSnapshots).toMatchObject([
{
cmd: 'install-tool golang 1.23.6',
cmd: 'install-tool golang 1.23.0',
},
{
cmd: 'go get -d -t ./...',
cmd: 'go get -t ./... [email protected] [email protected] golang.org/x/[email protected]',
},
]);

expect(datasource.getPkgReleases).toBeCalledTimes(0);
});

it('go.mod file contains full go version without toolchain', async () => {
Expand All @@ -2174,9 +2187,21 @@ describe('modules/manager/gomod/artifacts', () => {
.mockResolvedValueOnce('New go.sum')
.mockResolvedValueOnce('New go.mod');

datasource.getPkgReleases.mockResolvedValueOnce({
releases: [
{ version: '1.17.0' },
{ version: '1.23.3' },
{ version: '1.24.1' },
],
});

const res = await gomod.updateArtifacts({
packageFileName: 'go.mod',
updatedDeps: [{ depName: 'golang.org/x/crypto', newVersion: '0.35.0' }],
updatedDeps: [
{ depName: 'golang.org/x/crypto', newVersion: 'v0.35.0' },
{ depName: 'go', newVersion: '1.23.5' },
{ newVersion: '1.23.5' },
],
newPackageFileContent: `someText\n\ngo 1.23.5\n\n${gomod1}`,
config: {
updateType: 'minor',
Expand All @@ -2193,11 +2218,55 @@ describe('modules/manager/gomod/artifacts', () => {
cmd: 'install-tool golang 1.23.5',
},
{
cmd: 'go get -d -t ./...',
cmd: 'go get -t ./... toolchain@none [email protected] golang.org/x/[email protected]',
},
]);
});

it('preserve go.mod file without toolchain', async () => {
GlobalConfig.set({ ...adminConfig, binarySource: 'install' });
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename
const execSnapshots = mockExecAll();
git.getRepoStatus.mockResolvedValueOnce(
partial<StatusResult>({
modified: ['go.sum'],
}),
);
fs.readLocalFile
.mockResolvedValueOnce('New go.sum')
.mockResolvedValueOnce('New go.mod');

datasource.getPkgReleases.mockResolvedValueOnce({
releases: [
{ version: '1.17.0' },
{ version: '1.23.3' },
{ version: '1.24.1' },
],
});

const res = await gomod.updateArtifacts({
packageFileName: 'go.mod',
updatedDeps: [{ depName: 'golang.org/x/crypto', newVersion: 'v0.35.0' }],
newPackageFileContent: `someText\n\ngo 1.23\n\n${gomod1}`,
config: {
updateType: 'minor',
},
});

expect(res).toEqual([
{ file: { type: 'addition', path: 'go.sum', contents: 'New go.sum' } },
{ file: { type: 'addition', path: 'go.mod', contents: 'New go.mod' } },
]);

expect(datasource.getPkgReleases).toBeCalledTimes(0);
expect(execSnapshots).toMatchObject([
{
cmd: 'install-tool golang 1.23.0',
},
{
cmd: 'go get -t ./... toolchain@none [email protected] golang.org/x/[email protected]',
},
]);
});

it('returns artifact notices', async () => {
Expand Down Expand Up @@ -2286,6 +2355,7 @@ describe('modules/manager/gomod/artifacts', () => {
'docker run --rm --name=renovate_sidecar --label=renovate_child ' +
'-v "/tmp/github/some/repo":"/tmp/github/some/repo" ' +
'-v "/tmp/renovate/cache":"/tmp/renovate/cache" ' +
'-e GOTOOLCHAIN ' +
'-e GOPROXY ' +
'-e GOPRIVATE ' +
'-e GONOPROXY ' +
Expand Down Expand Up @@ -2411,4 +2481,99 @@ describe('modules/manager/gomod/artifacts', () => {
]);
expect(execSnapshots).toMatchObject([]);
});

it('preserve work with major upgrade', async () => {
GlobalConfig.set({ ...adminConfig, binarySource: 'install' });
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename
const execSnapshots = mockExecAll();
git.getRepoStatus.mockResolvedValueOnce(
partial<StatusResult>({
modified: ['go.sum'],
}),
);
fs.readLocalFile
.mockResolvedValueOnce('New go.sum')
.mockResolvedValueOnce('New go.mod');

datasource.getPkgReleases.mockResolvedValueOnce({
releases: [
{ version: '1.17.0' },
{ version: '1.23.3' },
{ version: '1.24.1' },
],
});

const res = await gomod.updateArtifacts({
packageFileName: 'go.mod',
updatedDeps: [
{
datasource: 'go',
depName: 'gopkg.in/yaml.v2',
fixedVersion: 'v2.4.0',
currentVersion: 'v2.4.0',
currentValue: 'v2.4.0',
newValue: 'v3.0.1',
newVersion: 'v3.0.1',
packageFile: 'go.mod',
updateType: 'major',
packageName: 'gopkg.in/yaml.v2',
},
{
depName: 'github.com/google/go-github/v24',
packageName: 'github.com/google/go-github/v24',
newVersion: 'v28.0.0',
datasource: 'go',
fixedVersion: 'v24.0.0',
currentVersion: 'v24.0.0',
currentValue: 'v24.0.0',
newValue: 'v28.0.0',
packageFile: 'go.mod',
updateType: 'major',
},
{
depName: 'github.com/renovatebot/renovate',
packageName: 'github.com/renovatebot/renovate',
newVersion: 'v1.0.0',
datasource: 'go',
fixedVersion: 'v0.0.1',
currentVersion: 'v0.0.1',
currentValue: 'v0.0.1',
newValue: 'v1.0.0',
packageFile: 'go.mod',
updateType: 'major',
},
{
depName: 'github.com/some/lib',
packageName: 'github.com/some/lib',
datasource: 'go',
fixedVersion: 'v0.0.1',
currentVersion: 'v0.0.1',
currentValue: 'v0.0.1',
newVersion: 'v2.0.0',
newValue: 'v2.0.0',
packageFile: 'go.mod',
updateType: 'major',
},
],
newPackageFileContent: `someText\n\ngo 1.23\n\n${gomod1}`,
config: {
updateType: 'minor',
},
});

expect(res).toEqual([
{ file: { type: 'addition', path: 'go.sum', contents: 'New go.sum' } },
{ file: { type: 'addition', path: 'go.mod', contents: 'New go.mod' } },
]);

expect(execSnapshots).toMatchObject([
{
cmd: 'install-tool golang 1.23.0',
},
{
cmd: 'go get -t ./... toolchain@none [email protected] gopkg.in/[email protected] github.com/google/go-github/[email protected] github.com/renovatebot/[email protected] github.com/some/lib/[email protected]',
},
]);
});
});
Loading