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

feat(manager/gomod): option to always run go mod vendor #33066

Merged
merged 13 commits into from
Dec 20, 2024
1 change: 1 addition & 0 deletions docs/usage/configuration-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -3348,6 +3348,7 @@ Table with options:
| `gomodTidyE` | Run `go mod tidy -e` after Go module updates. |
| `gomodUpdateImportPaths` | Update source import paths on major module updates, using [mod](https://github.com/marwan-at-work/mod). |
| `gomodSkipVendor` | Never run `go mod vendor` after Go module updates. |
| `gomodVendor` | Always run `go mod vendor` after Go module updates. |
omercnet marked this conversation as resolved.
Show resolved Hide resolved
| `helmUpdateSubChartArchives` | Update subchart archives in the `/charts` folder. |
| `npmDedupe` | Run `npm install` with `--prefer-dedupe` for npm >= 7 or `npm dedupe` after `package-lock.json` update for npm <= 6. |
| `pnpmDedupe` | Run `pnpm dedupe --config.ignore-scripts=true` after `pnpm-lock.yaml` updates. |
Expand Down
1 change: 1 addition & 0 deletions lib/config/options/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2389,6 +2389,7 @@ const options: RenovateOptions[] = [
'gomodTidyE',
'gomodUpdateImportPaths',
'gomodSkipVendor',
'gomodVendor',
'helmUpdateSubChartArchives',
'npmDedupe',
'pnpmDedupe',
Expand Down
68 changes: 68 additions & 0 deletions lib/modules/manager/gomod/artifacts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,74 @@ describe('modules/manager/gomod/artifacts', () => {
]);
});

it('runs go mod vendor with gomodVendor', async () => {
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename
fs.readLocalFile.mockResolvedValueOnce('New go.sum');
fs.readLocalFile.mockResolvedValueOnce('New go.mod');

const execSnapshots = mockExecAll();
git.getRepoStatus.mockResolvedValueOnce(
partial<StatusResult>({
modified: ['go.sum'],
not_added: [],
deleted: [],
}),
);
const res = await gomod.updateArtifacts({
packageFileName: 'go.mod',
updatedDeps: [],
newPackageFileContent: gomod1,
config: {
...config,
postUpdateOptions: ['gomodVendor'],
},
});
expect(res).toEqual([
{
file: {
contents: 'New go.sum',
path: 'go.sum',
type: 'addition',
},
},
{
file: {
contents: 'New go.mod',
path: 'go.mod',
type: 'addition',
},
},
]);

expect(execSnapshots).toMatchObject([
{
cmd: 'go get -d -t ./...',
options: {
cwd: '/tmp/github/some/repo',
encoding: 'utf-8',
env: {
...envMock.basic,
...goEnv,
GOFLAGS: '-modcacherw',
},
},
},
{
cmd: 'go mod vendor',
options: {
cwd: '/tmp/github/some/repo',
encoding: 'utf-8',
env: {
...envMock.basic,
...goEnv,
GOFLAGS: '-modcacherw',
},
},
},
]);
});

it('supports vendor directory update', async () => {
const foo = join('vendor/github.com/foo/foo/go.mod');
const bar = join('vendor/github.com/bar/bar/go.mod');
Expand Down
6 changes: 3 additions & 3 deletions lib/modules/manager/gomod/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ export async function updateArtifacts({
const vendorDir = upath.join(goModDir, 'vendor/');
const vendorModulesFileName = upath.join(vendorDir, 'modules.txt');
omercnet marked this conversation as resolved.
Show resolved Hide resolved
const useVendor =
!config.postUpdateOptions?.includes('gomodSkipVendor') &&
(await readLocalFile(vendorModulesFileName)) !== null;

(!config.postUpdateOptions?.includes('gomodSkipVendor') &&
(await readLocalFile(vendorModulesFileName)) !== null) ||
config.postUpdateOptions?.includes('gomodVendor');
omercnet marked this conversation as resolved.
Show resolved Hide resolved
let massagedGoMod = newGoModContent;

if (config.postUpdateOptions?.includes('gomodMassage')) {
Expand Down
Loading