Skip to content
Snippets Groups Projects
Unverified Commit c87a1538 authored by Rhys Arkins's avatar Rhys Arkins Committed by GitHub
Browse files

feat: go module vendoring support (#3191)

Detects if a `vendor/modules.txt` is present and runs `go mod vendor` if so. Requires gitFs to work.

Closes #2580
parent 279f632b
No related branches found
No related tags found
No related merge requests found
...@@ -65,19 +65,20 @@ async function getArtifacts( ...@@ -65,19 +65,20 @@ async function getArtifacts(
logger.info('Running go via global command'); logger.info('Running go via global command');
cmd = 'go'; cmd = 'go';
} }
const args = 'get'; let args = 'get';
logger.debug({ cmd, args }, 'go get command'); logger.debug({ cmd, args }, 'go get command');
({ stdout, stderr } = await exec(`${cmd} ${args}`, { ({ stdout, stderr } = await exec(`${cmd} ${args}`, {
cwd, cwd,
shell: true, shell: true,
env, env,
})); }));
const duration = process.hrtime(startTime); let duration = process.hrtime(startTime);
const seconds = Math.round(duration[0] + duration[1] / 1e9); let seconds = Math.round(duration[0] + duration[1] / 1e9);
logger.info( logger.info(
{ seconds, type: 'go.sum', stdout, stderr }, { seconds, type: 'go.sum', stdout, stderr },
'Generated lockfile' 'Generated lockfile'
); );
const res = [];
// istanbul ignore if // istanbul ignore if
if (config.gitFs) { if (config.gitFs) {
const status = await platform.getRepoStatus(); const status = await platform.getRepoStatus();
...@@ -93,14 +94,46 @@ async function getArtifacts( ...@@ -93,14 +94,46 @@ async function getArtifacts(
} }
} }
logger.debug('Returning updated go.sum'); logger.debug('Returning updated go.sum');
return [ res.push({
{ file: {
file: { name: sumFileName,
name: sumFileName, contents: await fs.readFile(localGoSumFileName, 'utf8'),
contents: await fs.readFile(localGoSumFileName, 'utf8'),
},
}, },
]; });
const vendorDir = upath.join(upath.dirname(goModFileName), 'vendor/');
const vendorModulesFileName = upath.join(vendorDir, 'modules.txt');
// istanbul ignore if
if (platform.getFile(vendorModulesFileName)) {
if (config.gitFs) {
args = 'mod vendor';
logger.debug({ cmd, args }, 'go mod vendor command');
({ stdout, stderr } = await exec(`${cmd} ${args}`, {
cwd,
shell: true,
env,
}));
duration = process.hrtime(startTime);
seconds = Math.round(duration[0] + duration[1] / 1e9);
logger.info({ seconds, stdout, stderr }, 'Vendored modules');
const status = await platform.getRepoStatus();
for (const modified of status.modified) {
if (modified.startsWith(vendorDir)) {
const localModified = upath.join(config.localDir, modified);
res.push({
file: {
name: modified,
contents: await fs.readFile(localModified, 'utf8'),
},
});
}
}
} else {
logger.warn(
'Vendor modules found - Renovate administrator should enable gitFs in order to update them'
);
}
}
return res;
} catch (err) { } catch (err) {
logger.warn({ err, message: err.message }, 'Failed to update go.sum'); logger.warn({ err, message: err.message }, 'Failed to update go.sum');
return [ return [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment