Skip to content

Commit

Permalink
fix(gomod): Commit updated go.mod when only go.mod changes (#20372)
Browse files Browse the repository at this point in the history
Co-authored-by: Rhys Arkins <[email protected]>
  • Loading branch information
Shegox and rarkins authored Feb 13, 2023
1 parent 09402a3 commit 9669ba3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
33 changes: 33 additions & 0 deletions lib/modules/manager/gomod/artifacts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1283,6 +1283,39 @@ describe('modules/manager/gomod/artifacts', () => {
]);
});

it('returns go.mod if only go.mod changes', async () => {
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename
const execSnapshots = mockExecAll();
git.getRepoStatus.mockResolvedValueOnce(
partial<StatusResult>({
modified: ['go.mod'],
})
);
fs.readLocalFile.mockResolvedValueOnce('New go.mod');
expect(
await gomod.updateArtifacts({
packageFileName: 'go.mod',
updatedDeps: [{ depName: 'github.com/google/go-github/v24' }],
newPackageFileContent: gomod1,
config: {
...config,
updateType: 'major',
newMajor: 28,
postUpdateOptions: [],
},
})
).toEqual([
{ file: { type: 'addition', path: 'go.mod', contents: 'New go.mod' } },
]);
expect(execSnapshots).toMatchObject([
{
cmd: 'go get -d -t ./...',
options: { cwd: '/tmp/github/some/repo' },
},
]);
});

it('skips updating import paths with gomodUpdateImportPaths on v0 to v1', async () => {
fs.readLocalFile.mockResolvedValueOnce('Current go.sum');
fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename
Expand Down
16 changes: 10 additions & 6 deletions lib/modules/manager/gomod/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,20 +337,24 @@ export async function updateArtifacts({
await exec(execCommands, execOptions);

const status = await getRepoStatus();
if (!status.modified.includes(sumFileName)) {
if (
!status.modified.includes(sumFileName) &&
!status.modified.includes(goModFileName)
) {
return null;
}

logger.debug('Returning updated go.sum');
const res: UpdateArtifactsResult[] = [
{
const res: UpdateArtifactsResult[] = [];
if (status.modified.includes(sumFileName)) {
logger.debug('Returning updated go.sum');
res.push({
file: {
type: 'addition',
path: sumFileName,
contents: await readLocalFile(sumFileName),
},
},
];
});
}

// Include all the .go file import changes
if (isImportPathUpdateRequired) {
Expand Down

0 comments on commit 9669ba3

Please sign in to comment.