2020-01-10 10:35:49 +00:00
|
|
|
import fs from 'fs-extra';
|
2021-11-23 20:10:45 +00:00
|
|
|
import { GlobalConfig } from '../../config/global';
|
2021-04-20 08:52:57 +00:00
|
|
|
import type { RenovateConfig } from '../../config/types';
|
2020-01-10 10:35:49 +00:00
|
|
|
import { logger, setMeta } from '../../logger';
|
2021-06-02 06:50:23 +00:00
|
|
|
import { removeDanglingContainers } from '../../util/exec/docker';
|
2021-01-17 08:18:32 +00:00
|
|
|
import { deleteLocalFile, privateCacheDir } from '../../util/fs';
|
2020-12-11 09:09:09 +00:00
|
|
|
import * as queue from '../../util/http/queue';
|
2020-05-08 08:18:00 +00:00
|
|
|
import { addSplit, getSplits, splitInit } from '../../util/split';
|
2020-09-22 11:10:07 +00:00
|
|
|
import { setBranchCache } from './cache';
|
2021-06-01 13:07:54 +00:00
|
|
|
import { ensureDependencyDashboard } from './dependency-dashboard';
|
2020-05-01 16:03:48 +00:00
|
|
|
import handleError from './error';
|
|
|
|
import { finaliseRepo } from './finalise';
|
2020-01-10 10:35:49 +00:00
|
|
|
import { initRepo } from './init';
|
|
|
|
import { ensureOnboardingPr } from './onboarding/pr';
|
2020-05-08 06:53:39 +00:00
|
|
|
import { extractDependencies, updateRepo } from './process';
|
2020-05-01 16:03:48 +00:00
|
|
|
import { ProcessResult, processResult } from './result';
|
2020-06-13 06:37:56 +00:00
|
|
|
import { printRequestStats } from './stats';
|
2017-06-26 12:26:49 +00:00
|
|
|
|
2020-01-11 06:50:08 +00:00
|
|
|
let renovateVersion = 'unknown';
|
|
|
|
try {
|
2020-08-10 14:18:08 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
2021-11-08 19:20:03 +00:00
|
|
|
renovateVersion = require('../../../package.json').version;
|
2020-01-11 08:04:11 +00:00
|
|
|
} catch (err) /* istanbul ignore next */ {
|
2020-01-11 06:50:08 +00:00
|
|
|
logger.debug({ err }, 'Error getting renovate version');
|
|
|
|
}
|
|
|
|
|
2018-05-09 06:03:59 +00:00
|
|
|
// istanbul ignore next
|
2020-01-10 10:35:49 +00:00
|
|
|
export async function renovateRepository(
|
2021-05-31 11:01:48 +00:00
|
|
|
repoConfig: RenovateConfig,
|
|
|
|
canRetry = true
|
2020-01-10 10:35:49 +00:00
|
|
|
): Promise<ProcessResult> {
|
2020-05-08 08:18:00 +00:00
|
|
|
splitInit();
|
2021-11-23 20:10:45 +00:00
|
|
|
let config = GlobalConfig.set(repoConfig);
|
2021-06-02 06:50:23 +00:00
|
|
|
await removeDanglingContainers();
|
2019-07-15 09:04:05 +00:00
|
|
|
setMeta({ repository: config.repository });
|
2020-02-24 07:43:01 +00:00
|
|
|
logger.info({ renovateVersion }, 'Repository started');
|
2018-05-09 06:03:59 +00:00
|
|
|
logger.trace({ config });
|
2020-01-10 10:35:49 +00:00
|
|
|
let repoResult: ProcessResult;
|
2020-12-11 09:09:09 +00:00
|
|
|
queue.clear();
|
2021-11-23 20:10:45 +00:00
|
|
|
const { localDir } = GlobalConfig.get();
|
2017-10-18 08:29:49 +00:00
|
|
|
try {
|
2021-05-26 11:22:16 +00:00
|
|
|
await fs.ensureDir(localDir);
|
|
|
|
logger.debug('Using localDir: ' + localDir);
|
2017-11-05 04:45:49 +00:00
|
|
|
config = await initRepo(config);
|
2020-05-08 08:18:00 +00:00
|
|
|
addSplit('init');
|
2020-05-08 06:53:39 +00:00
|
|
|
const { branches, branchList, packageFiles } = await extractDependencies(
|
|
|
|
config
|
|
|
|
);
|
2020-04-14 10:56:44 +00:00
|
|
|
await ensureOnboardingPr(config, packageFiles, branches);
|
2020-09-01 16:33:45 +00:00
|
|
|
const res = await updateRepo(config, branches);
|
2021-06-14 20:15:28 +00:00
|
|
|
setMeta({ repository: config.repository });
|
2020-05-08 08:18:00 +00:00
|
|
|
addSplit('update');
|
2020-09-22 11:10:07 +00:00
|
|
|
await setBranchCache(branches);
|
2021-05-31 11:01:48 +00:00
|
|
|
if (res === 'automerged') {
|
|
|
|
if (canRetry) {
|
|
|
|
logger.info('Renovating repository again after automerge result');
|
|
|
|
const recursiveRes = await renovateRepository(repoConfig, false);
|
|
|
|
return recursiveRes;
|
|
|
|
}
|
|
|
|
logger.debug(`Automerged but already retried once`);
|
|
|
|
} else {
|
2021-06-01 13:07:54 +00:00
|
|
|
await ensureDependencyDashboard(config, branches);
|
2019-07-17 08:22:13 +00:00
|
|
|
}
|
2018-05-07 10:59:32 +00:00
|
|
|
await finaliseRepo(config, branchList);
|
2018-10-17 10:19:02 +00:00
|
|
|
repoResult = processResult(config, res);
|
2018-04-04 17:35:01 +00:00
|
|
|
} catch (err) /* istanbul ignore next */ {
|
2020-01-11 08:16:22 +00:00
|
|
|
setMeta({ repository: config.repository });
|
2018-10-17 10:19:02 +00:00
|
|
|
const errorRes = await handleError(config, err);
|
|
|
|
repoResult = processResult(config, errorRes);
|
|
|
|
}
|
2021-05-26 11:22:16 +00:00
|
|
|
if (localDir && !config.persistRepoData) {
|
2020-08-25 08:22:21 +00:00
|
|
|
try {
|
|
|
|
await deleteLocalFile('.');
|
|
|
|
} catch (err) /* istanbul ignore if */ {
|
2021-05-26 11:22:16 +00:00
|
|
|
logger.warn({ err }, 'localDir deletion error');
|
2020-08-25 08:22:21 +00:00
|
|
|
}
|
2018-04-10 07:19:24 +00:00
|
|
|
}
|
2021-01-17 08:18:32 +00:00
|
|
|
try {
|
|
|
|
await fs.remove(privateCacheDir());
|
|
|
|
} catch (err) /* istanbul ignore if */ {
|
|
|
|
logger.warn({ err }, 'privateCacheDir deletion error');
|
|
|
|
}
|
2020-05-08 08:18:00 +00:00
|
|
|
const splits = getSplits();
|
|
|
|
logger.debug(splits, 'Repository timing splits (milliseconds)');
|
2020-06-13 06:37:56 +00:00
|
|
|
printRequestStats();
|
2020-05-08 08:18:00 +00:00
|
|
|
logger.info({ durationMs: splits.total }, 'Repository finished');
|
2018-10-17 10:19:02 +00:00
|
|
|
return repoResult;
|
2017-06-26 12:26:49 +00:00
|
|
|
}
|