Skip to content

Commit

Permalink
feat(gomod): Add gomodSkipVendor postUpdateOption (#30025)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
  • Loading branch information
r0bobo and viceice authored Jul 10, 2024
1 parent 650ac22 commit 5f21e17
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/usage/configuration-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -3378,6 +3378,7 @@ Table with options:
| `gomodTidy1.17` | Run `go mod tidy -compat=1.17` after Go module updates. |
| `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. |
| `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 @@ -2508,6 +2508,7 @@ const options: RenovateOptions[] = [
'gomodTidy1.17',
'gomodTidyE',
'gomodUpdateImportPaths',
'gomodSkipVendor',
'helmUpdateSubChartArchives',
'npmDedupe',
'pnpmDedupe',
Expand Down
50 changes: 50 additions & 0 deletions lib/modules/manager/gomod/artifacts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,56 @@ describe('modules/manager/gomod/artifacts', () => {
]);
});

it('skips vendor directory update with gomodSkipVendor', async () => {
const foo = join('vendor/github.com/foo/foo/go.mod');
const bar = join('vendor/github.com/bar/bar/go.mod');
const baz = join('vendor/github.com/baz/baz/go.mod');

fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
const execSnapshots = mockExecAll();
git.getRepoStatus.mockResolvedValueOnce(
partial<StatusResult>({
modified: ['go.sum', foo],
not_added: [bar],
deleted: [baz],
}),
);
fs.readLocalFile.mockResolvedValueOnce('New go.sum');
fs.readLocalFile.mockResolvedValueOnce('New go.mod');
const res = await gomod.updateArtifacts({
packageFileName: 'go.mod',
updatedDeps: [],
newPackageFileContent: gomod1,
config: {
...config,
postUpdateOptions: ['gomodSkipVendor'],
},
});
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' },
},
]);
});

it('supports vendor directory update with go.work', async () => {
const foo = join('vendor/github.com/foo/foo/go.mod');
const bar = join('vendor/github.com/bar/bar/go.mod');
Expand Down
4 changes: 3 additions & 1 deletion lib/modules/manager/gomod/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ export async function updateArtifacts({

const vendorDir = upath.join(goModDir, 'vendor/');
const vendorModulesFileName = upath.join(vendorDir, 'modules.txt');
const useVendor = (await readLocalFile(vendorModulesFileName)) !== null;
const useVendor =
!config.postUpdateOptions?.includes('gomodSkipVendor') &&
(await readLocalFile(vendorModulesFileName)) !== null;

let massagedGoMod = newGoModContent;

Expand Down

0 comments on commit 5f21e17

Please sign in to comment.