mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-25 23:11:31 +00:00
f31aec34fe
chore(tools): handle additional error
In the case that `pdm` can't be executed, for instance if it's only
installed in a Virtualenv that's not currently active, this previously
would silently pass, even though the command had failed.
We can now make it more resilient by warning/erroring in the cases that:
- there is a timeout
- the process was killed
- the process failed to execute
Originally raised as #40987, which was closed due to the migration to
`execa` and errors being flagged as an `unhandledRejection`.
However, after b35d7c9cad, we would no
longer reject, leading to an incomplete error handling case.
97 lines
2.7 KiB
TypeScript
97 lines
2.7 KiB
TypeScript
import { Command } from 'commander';
|
|
import type { ExecaSyncReturnValue } from 'execa';
|
|
import fs from 'fs-extra';
|
|
import { init, logger } from '../lib/logger/index.ts';
|
|
import { generateDocs } from './docs/index.ts';
|
|
import { exec } from './utils/exec.ts';
|
|
|
|
await init();
|
|
|
|
process.on('unhandledRejection', (err) => {
|
|
// Will print "unhandledRejection err is not defined"
|
|
logger.error({ err }, 'unhandledRejection');
|
|
process.exit(-1);
|
|
});
|
|
|
|
const program = new Command('pnpm mkdocs').description('Run mkdocs');
|
|
|
|
program
|
|
.command('build', { isDefault: true })
|
|
.description('Build mkdocs')
|
|
.option('--version <version>', 'the current version of the Renovate CLI')
|
|
.option('--no-build', 'do not build docs from source')
|
|
.option('--no-strict', 'do not build in strict mode')
|
|
.action(async (opts) => {
|
|
await prepareDocs(opts);
|
|
logger.info('* running mkdocs build');
|
|
const args = ['run', 'mkdocs', 'build'];
|
|
if (opts.strict) {
|
|
args.push('--strict');
|
|
}
|
|
const res = await exec('pdm', args, {
|
|
cwd: 'tools/mkdocs',
|
|
stdio: 'inherit',
|
|
env: {
|
|
...process.env,
|
|
RENOVATE_VERSION: opts.version ?? '',
|
|
},
|
|
reject: false,
|
|
});
|
|
checkResult(res);
|
|
});
|
|
|
|
program
|
|
.command('serve')
|
|
.description('serve mkdocs')
|
|
.option('--no-build', 'do not build docs from source')
|
|
.option('--no-strict', 'do not build in strict mode')
|
|
.action(async (opts) => {
|
|
await prepareDocs(opts);
|
|
logger.info('serving docs');
|
|
logger.info('* running mkdocs serve');
|
|
const args = ['run', 'mkdocs', 'serve'];
|
|
if (opts.strict) {
|
|
args.push('--strict');
|
|
}
|
|
const res = await exec('pdm', args, {
|
|
cwd: 'tools/mkdocs',
|
|
stdio: 'inherit',
|
|
reject: false,
|
|
});
|
|
checkResult(res);
|
|
});
|
|
|
|
async function prepareDocs(opts: any): Promise<void> {
|
|
logger.info('Building docs');
|
|
if (opts.build) {
|
|
logger.info('* generate docs');
|
|
await generateDocs('tools/mkdocs', false, opts.version);
|
|
} else {
|
|
logger.info('* using prebuild docs from build step');
|
|
await fs.copy('tmp/docs', 'tools/mkdocs/docs');
|
|
}
|
|
}
|
|
|
|
function checkResult(res: ExecaSyncReturnValue<string>): void {
|
|
if (res.signal) {
|
|
logger.error(`Signal received: ${res.signal}`);
|
|
process.exit(-1);
|
|
} else if (res.exitCode) {
|
|
logger.error(`Error occured:\n${res.stderr || res.stdout}`);
|
|
process.exit(res.exitCode);
|
|
} else if (res.timedOut) {
|
|
logger.error({ res }, 'Process timed out');
|
|
process.exit(-1);
|
|
} else if (res.killed) {
|
|
logger.error({ res }, 'Process was killed');
|
|
process.exit(-1);
|
|
} else if (res.failed) {
|
|
logger.error({ res }, 'Process call failed');
|
|
process.exit(-1);
|
|
} else {
|
|
logger.debug(`Build completed:\n${res.stdout || res.stderr}`);
|
|
}
|
|
}
|
|
|
|
void program.parseAsync();
|