renovate/lib/manager/helmv3/artifacts.ts
Michael Kriese 40a59cc9e0
feat: use short renovate image names (#9133)
Co-authored-by: Rhys Arkins <rhys@arkins.net>
2021-03-15 13:23:38 +00:00

81 lines
2.2 KiB
TypeScript

import { quote } from 'shlex';
import { TEMPORARY_ERROR } from '../../constants/error-messages';
import { logger } from '../../logger';
import { ExecOptions, exec } from '../../util/exec';
import {
getSiblingFileName,
getSubDirectory,
readLocalFile,
writeLocalFile,
} from '../../util/fs';
import type { UpdateArtifact, UpdateArtifactsResult } from '../types';
async function helmUpdate(manifestPath: string): Promise<void> {
const cmd = `helm dependency update ${quote(getSubDirectory(manifestPath))}`;
const execOptions: ExecOptions = {
docker: {
image: 'helm',
},
};
await exec(cmd, execOptions);
}
export async function updateArtifacts({
packageFileName,
updatedDeps,
newPackageFileContent,
config,
}: UpdateArtifact): Promise<UpdateArtifactsResult[] | null> {
logger.debug(`helmv3.updateArtifacts(${packageFileName})`);
const isLockFileMaintenance = config.updateType === 'lockFileMaintenance';
if (
!isLockFileMaintenance &&
(updatedDeps === undefined || updatedDeps.length < 1)
) {
logger.debug('No updated helmv3 deps - returning null');
return null;
}
const lockFileName = getSiblingFileName(packageFileName, 'Chart.lock');
const existingLockFileContent = await readLocalFile(lockFileName);
if (!existingLockFileContent) {
logger.debug('No Chart.lock found');
return null;
}
try {
await writeLocalFile(packageFileName, newPackageFileContent);
logger.debug('Updating ' + lockFileName);
await helmUpdate(packageFileName);
logger.debug('Returning updated Chart.lock');
const newHelmLockContent = await readLocalFile(lockFileName);
if (existingLockFileContent === newHelmLockContent) {
logger.debug('Chart.lock is unchanged');
return null;
}
return [
{
file: {
name: lockFileName,
contents: newHelmLockContent,
},
},
];
} catch (err) {
// istanbul ignore if
if (err.message === TEMPORARY_ERROR) {
throw err;
}
logger.warn({ err }, 'Failed to update Helm lock file');
return [
{
artifactError: {
lockFile: lockFileName,
stderr: err.message,
},
},
];
}
}