mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-11 22:46:27 +00:00
feat(gomod): private module support (#3495)
Adds support for fetching private modules off github.com Closes #3202
This commit is contained in:
parent
9cf43e2fde
commit
0bd0ea33f6
2 changed files with 42 additions and 2 deletions
|
@ -2,6 +2,7 @@ const { exec } = require('child-process-promise');
|
|||
const fs = require('fs-extra');
|
||||
const upath = require('upath');
|
||||
const os = require('os');
|
||||
const hostRules = require('../../util/host-rules');
|
||||
|
||||
module.exports = {
|
||||
getArtifacts,
|
||||
|
@ -60,12 +61,29 @@ async function getArtifacts(
|
|||
cmd += envVars.map(e => `-e ${e} `).join('');
|
||||
cmd += '-e CGO_ENABLED=0 ';
|
||||
cmd += `-w ${cwd} `;
|
||||
cmd += `renovate/go go`;
|
||||
cmd += `renovate/go `;
|
||||
const credentials = hostRules.find({
|
||||
platform: 'github',
|
||||
host: 'api.github.com',
|
||||
});
|
||||
if (credentials && credentials.token) {
|
||||
logger.debug('Setting github.com credentials');
|
||||
cmd += `bash -c "git config --global url.\\"https://${
|
||||
global.appMode
|
||||
? `x-access-token:${credentials.token}`
|
||||
: credentials.token
|
||||
}@github.com/\\".insteadOf \\"https://github.com/\\" && go`;
|
||||
} else {
|
||||
cmd += 'go';
|
||||
}
|
||||
} else {
|
||||
logger.info('Running go via global command');
|
||||
cmd = 'go';
|
||||
}
|
||||
let args = 'get';
|
||||
if (cmd.includes('.insteadOf')) {
|
||||
args += '"';
|
||||
}
|
||||
logger.debug({ cmd, args }, 'go get command');
|
||||
({ stdout, stderr } = await exec(`${cmd} ${args}`, {
|
||||
cwd,
|
||||
|
@ -131,6 +149,9 @@ async function getArtifacts(
|
|||
if (await platform.getFile(vendorModulesFileName)) {
|
||||
if (config.gitFs) {
|
||||
args = 'mod vendor';
|
||||
if (cmd.includes('.insteadOf')) {
|
||||
args += '"';
|
||||
}
|
||||
logger.debug({ cmd, args }, 'go mod vendor command');
|
||||
({ stdout, stderr } = await exec(`${cmd} ${args}`, {
|
||||
cwd,
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
jest.mock('fs-extra');
|
||||
jest.mock('child-process-promise');
|
||||
jest.mock('../../../lib/util/host-rules');
|
||||
|
||||
const fs = require('fs-extra');
|
||||
const { exec } = require('child-process-promise');
|
||||
const gomod = require('../../../lib/manager/gomod/artifacts');
|
||||
const hostRules = require('../../../lib/util/host-rules');
|
||||
|
||||
const gomod1 = `module github.com/renovate-tests/gomod1
|
||||
|
||||
|
@ -48,7 +50,24 @@ describe('.getArtifacts()', () => {
|
|||
await gomod.getArtifacts('go.mod', [], gomod1, config)
|
||||
).not.toBeNull();
|
||||
});
|
||||
it('supports docker mode', async () => {
|
||||
it('supports docker mode without credentials', async () => {
|
||||
platform.getFile.mockReturnValueOnce('Current go.sum');
|
||||
exec.mockReturnValueOnce({
|
||||
stdout: '',
|
||||
stderror: '',
|
||||
});
|
||||
fs.readFile = jest.fn(() => 'New go.sum');
|
||||
expect(
|
||||
await gomod.getArtifacts('go.mod', [], gomod1, {
|
||||
...config,
|
||||
binarySource: 'docker',
|
||||
})
|
||||
).not.toBeNull();
|
||||
});
|
||||
it('supports docker mode with credentials', async () => {
|
||||
hostRules.find.mockReturnValue({
|
||||
token: 'some-token',
|
||||
});
|
||||
platform.getFile.mockReturnValueOnce('Current go.sum');
|
||||
exec.mockReturnValueOnce({
|
||||
stdout: '',
|
||||
|
|
Loading…
Reference in a new issue