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 fs = require('fs-extra');
|
||||||
const upath = require('upath');
|
const upath = require('upath');
|
||||||
const os = require('os');
|
const os = require('os');
|
||||||
|
const hostRules = require('../../util/host-rules');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getArtifacts,
|
getArtifacts,
|
||||||
|
@ -60,12 +61,29 @@ async function getArtifacts(
|
||||||
cmd += envVars.map(e => `-e ${e} `).join('');
|
cmd += envVars.map(e => `-e ${e} `).join('');
|
||||||
cmd += '-e CGO_ENABLED=0 ';
|
cmd += '-e CGO_ENABLED=0 ';
|
||||||
cmd += `-w ${cwd} `;
|
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 {
|
} else {
|
||||||
logger.info('Running go via global command');
|
logger.info('Running go via global command');
|
||||||
cmd = 'go';
|
cmd = 'go';
|
||||||
}
|
}
|
||||||
let args = 'get';
|
let args = 'get';
|
||||||
|
if (cmd.includes('.insteadOf')) {
|
||||||
|
args += '"';
|
||||||
|
}
|
||||||
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,
|
||||||
|
@ -131,6 +149,9 @@ async function getArtifacts(
|
||||||
if (await platform.getFile(vendorModulesFileName)) {
|
if (await platform.getFile(vendorModulesFileName)) {
|
||||||
if (config.gitFs) {
|
if (config.gitFs) {
|
||||||
args = 'mod vendor';
|
args = 'mod vendor';
|
||||||
|
if (cmd.includes('.insteadOf')) {
|
||||||
|
args += '"';
|
||||||
|
}
|
||||||
logger.debug({ cmd, args }, 'go mod vendor command');
|
logger.debug({ cmd, args }, 'go mod vendor command');
|
||||||
({ stdout, stderr } = await exec(`${cmd} ${args}`, {
|
({ stdout, stderr } = await exec(`${cmd} ${args}`, {
|
||||||
cwd,
|
cwd,
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
jest.mock('fs-extra');
|
jest.mock('fs-extra');
|
||||||
jest.mock('child-process-promise');
|
jest.mock('child-process-promise');
|
||||||
|
jest.mock('../../../lib/util/host-rules');
|
||||||
|
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const { exec } = require('child-process-promise');
|
const { exec } = require('child-process-promise');
|
||||||
const gomod = require('../../../lib/manager/gomod/artifacts');
|
const gomod = require('../../../lib/manager/gomod/artifacts');
|
||||||
|
const hostRules = require('../../../lib/util/host-rules');
|
||||||
|
|
||||||
const gomod1 = `module github.com/renovate-tests/gomod1
|
const gomod1 = `module github.com/renovate-tests/gomod1
|
||||||
|
|
||||||
|
@ -48,7 +50,24 @@ describe('.getArtifacts()', () => {
|
||||||
await gomod.getArtifacts('go.mod', [], gomod1, config)
|
await gomod.getArtifacts('go.mod', [], gomod1, config)
|
||||||
).not.toBeNull();
|
).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');
|
platform.getFile.mockReturnValueOnce('Current go.sum');
|
||||||
exec.mockReturnValueOnce({
|
exec.mockReturnValueOnce({
|
||||||
stdout: '',
|
stdout: '',
|
||||||
|
|
Loading…
Reference in a new issue