Files
renovate/lib/modules/manager/cloudbuild/extract.ts
T
Michael Kriese 497d4c131f fix(manager): unify logging (#22398)
Co-authored-by: Sebastian Poxhofer <secustor@users.noreply.github.com>
2023-05-25 16:53:05 +00:00

50 lines
1.3 KiB
TypeScript

import is from '@sindresorhus/is';
import { load } from 'js-yaml';
import { logger } from '../../../logger';
import { getDep } from '../dockerfile/extract';
import type { PackageDependency, PackageFileContent } from '../types';
export function extractPackageFile(
content: string,
packageFile?: string
): PackageFileContent | null {
const deps: PackageDependency[] = [];
try {
// TODO: fix types
const doc: any = load(content);
if (doc?.steps && is.array(doc.steps)) {
for (const step of doc.steps) {
if (step.name) {
const dep = getDep(step.name);
logger.trace(
{
depName: dep.depName,
currentValue: dep.currentValue,
currentDigest: dep.currentDigest,
},
'Cloud Build docker image'
);
deps.push(dep);
}
}
}
} catch (err) /* istanbul ignore next */ {
if (err.stack?.startsWith('YAMLException:')) {
logger.debug(
{ err, packageFile },
'YAML exception extracting Docker images from a Cloud Build configuration file.'
);
} else {
logger.debug(
{ err, packageFile },
'Error extracting Docker images from a Cloud Build configuration file.'
);
}
}
if (!deps.length) {
return null;
}
return { deps };
}