2019-07-25 06:17:19 +00:00
|
|
|
import { ensureDir, outputFile, readFile } from 'fs-extra';
|
|
|
|
import { join, dirname } from 'upath';
|
|
|
|
import { exec } from '../../util/exec';
|
|
|
|
import { getChildProcessEnv } from '../../util/env';
|
|
|
|
import { logger } from '../../logger';
|
|
|
|
import { UpdateArtifactsResult, UpdateArtifactsConfig } from '../common';
|
2018-11-23 06:58:25 +00:00
|
|
|
|
2019-07-25 06:17:19 +00:00
|
|
|
export async function updateArtifacts(
|
|
|
|
pipfileName: string,
|
|
|
|
_updatedDeps: string[],
|
|
|
|
newPipfileContent: string,
|
|
|
|
config: UpdateArtifactsConfig
|
2019-08-22 15:42:35 +00:00
|
|
|
): Promise<UpdateArtifactsResult[] | null> {
|
2019-06-09 06:18:41 +00:00
|
|
|
logger.debug(`pipenv.updateArtifacts(${pipfileName})`);
|
2018-11-23 06:58:25 +00:00
|
|
|
process.env.PIPENV_CACHE_DIR =
|
2019-07-25 06:17:19 +00:00
|
|
|
process.env.PIPENV_CACHE_DIR || join(config.cacheDir, './others/pipenv');
|
|
|
|
await ensureDir(process.env.PIPENV_CACHE_DIR);
|
2018-11-23 06:58:25 +00:00
|
|
|
logger.debug('Using pipenv cache ' + process.env.PIPENV_CACHE_DIR);
|
|
|
|
const lockFileName = pipfileName + '.lock';
|
|
|
|
const existingLockFileContent = await platform.getFile(lockFileName);
|
|
|
|
if (!existingLockFileContent) {
|
|
|
|
logger.debug('No Pipfile.lock found');
|
|
|
|
return null;
|
|
|
|
}
|
2019-07-25 06:17:19 +00:00
|
|
|
const cwd = join(config.localDir, dirname(pipfileName));
|
|
|
|
let stdout: string;
|
|
|
|
let stderr: string;
|
2018-11-23 06:58:25 +00:00
|
|
|
try {
|
2019-07-25 06:17:19 +00:00
|
|
|
const localPipfileFileName = join(config.localDir, pipfileName);
|
|
|
|
await outputFile(localPipfileFileName, newPipfileContent);
|
|
|
|
const localLockFileName = join(config.localDir, lockFileName);
|
2019-07-13 06:23:03 +00:00
|
|
|
const env = getChildProcessEnv(['LC_ALL', 'LANG', 'PIPENV_CACHE_DIR']);
|
2018-11-23 06:58:25 +00:00
|
|
|
const startTime = process.hrtime();
|
2019-07-25 06:17:19 +00:00
|
|
|
let cmd: string;
|
2018-11-23 06:58:25 +00:00
|
|
|
if (config.binarySource === 'docker') {
|
|
|
|
logger.info('Running pipenv via docker');
|
|
|
|
cmd = `docker run --rm `;
|
2019-01-27 05:52:23 +00:00
|
|
|
const volumes = [config.localDir, process.env.PIPENV_CACHE_DIR];
|
2018-11-23 06:58:25 +00:00
|
|
|
cmd += volumes.map(v => `-v ${v}:${v} `).join('');
|
|
|
|
const envVars = ['LC_ALL', 'LANG', 'PIPENV_CACHE_DIR'];
|
|
|
|
cmd += envVars.map(e => `-e ${e} `).join('');
|
|
|
|
cmd += `-w ${cwd} `;
|
|
|
|
cmd += `renovate/pipenv pipenv`;
|
|
|
|
} else {
|
|
|
|
logger.info('Running pipenv via global command');
|
|
|
|
cmd = 'pipenv';
|
|
|
|
}
|
|
|
|
const args = 'lock';
|
|
|
|
logger.debug({ cmd, args }, 'pipenv lock command');
|
|
|
|
({ stdout, stderr } = await exec(`${cmd} ${args}`, {
|
|
|
|
cwd,
|
|
|
|
env,
|
|
|
|
}));
|
|
|
|
const duration = process.hrtime(startTime);
|
|
|
|
const seconds = Math.round(duration[0] + duration[1] / 1e9);
|
|
|
|
stdout = stdout ? stdout.replace(/(Locking|Running)[^\s]*?\s/g, '') : null;
|
|
|
|
logger.info(
|
|
|
|
{ seconds, type: 'Pipfile.lock', stdout, stderr },
|
|
|
|
'Generated lockfile'
|
|
|
|
);
|
2019-05-25 04:23:44 +00:00
|
|
|
const status = await platform.getRepoStatus();
|
|
|
|
if (!(status && status.modified.includes(lockFileName))) {
|
|
|
|
return null;
|
2018-11-23 06:58:25 +00:00
|
|
|
}
|
|
|
|
logger.debug('Returning updated Pipfile.lock');
|
2019-02-08 13:50:06 +00:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
file: {
|
|
|
|
name: lockFileName,
|
2019-07-25 06:17:19 +00:00
|
|
|
contents: await readFile(localLockFileName, 'utf8'),
|
2019-02-08 13:50:06 +00:00
|
|
|
},
|
2018-11-23 06:58:25 +00:00
|
|
|
},
|
2019-02-08 13:50:06 +00:00
|
|
|
];
|
2018-11-23 06:58:25 +00:00
|
|
|
} catch (err) {
|
2019-04-08 06:52:04 +00:00
|
|
|
logger.warn({ err }, 'Failed to update Pipfile.lock');
|
2019-02-08 13:50:06 +00:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
artifactError: {
|
|
|
|
lockFile: lockFileName,
|
|
|
|
stderr: err.message,
|
|
|
|
},
|
2018-11-23 06:58:25 +00:00
|
|
|
},
|
2019-02-08 13:50:06 +00:00
|
|
|
];
|
2018-11-23 06:58:25 +00:00
|
|
|
}
|
|
|
|
}
|