Files
renovate/lib/modules/manager/helmfile/artifacts.ts
Sebastian Poxhofer 9fc451c44d refactor(manager): share the lock file updateArtifacts skeleton (#46093)
Migrate pub, gleam, helmfile, pixi, mise, poetry, pep621/pdm and
pep621/uv onto `updateLockFile()`, so each manager keeps only its
command and `ExecOptions` construction.

Behaviour changes:

- Artifact error text now comes from `artifactErrorMessageFromExecError`,
  i.e. a non-blank `err.stderr`, else a non-blank `err.stdout`, else
  `err.message`. Previously pixi used `${err}` ("Error: " prefix), mise
  joined stdout, stderr and message, and poetry rendered
  "<stdout>\n<stderr>" (literally "undefined\nundefined" when the error
  carried neither).
- helmfile, pixi, poetry, pdm and uv now return null instead of an
  addition when the lock file is missing or empty after the run, which
  is what gleam and mise already did.
- Unchanged/missing lock file debug messages are now uniformly
  "<lockFileName> is unchanged" / "No <lockFileName> found". pub gains
  such a message, mise loses "Returning updated mise lock file" and
  poetry loses "Returning updated <lockFileName>".
2026-09-16 13:13:42 +00:00

116 lines
3.6 KiB
TypeScript

import { isFalsy } from '@sindresorhus/is';
import { quote } from 'shlex';
import { TEMPORARY_ERROR } from '../../../constants/error-messages.ts';
import { logger } from '../../../logger/index.ts';
import { coerceArray } from '../../../util/array.ts';
import { exec } from '../../../util/exec/index.ts';
import type { ToolConstraint } from '../../../util/exec/types.ts';
import { getSiblingFileName } from '../../../util/fs/index.ts';
import { getFile } from '../../../util/git/index.ts';
import { regEx } from '../../../util/regex.ts';
import { Result } from '../../../util/result.ts';
import { parseYaml } from '../../../util/yaml.ts';
import { generateHelmEnvs } from '../helmv3/common.ts';
import type { UpdateArtifact, UpdateArtifactsResult } from '../types.ts';
import {
artifactErrorResult,
resolveToolConstraint,
updateLockFile,
} from '../util.ts';
import { Doc, LockVersion } from './schema.ts';
import { generateRegistryLoginCmd, isOCIRegistry } from './utils.ts';
export async function updateArtifacts({
packageFileName,
updatedDeps,
newPackageFileContent,
config,
}: UpdateArtifact): Promise<UpdateArtifactsResult[] | null> {
logger.trace(`helmfile.updateArtifacts(${packageFileName})`);
const { isLockFileMaintenance } = config;
if (
!isLockFileMaintenance &&
(updatedDeps === undefined || updatedDeps.length < 1)
) {
logger.debug('No updated helmfile deps - returning null');
return null;
}
const lockFileName = getSiblingFileName(packageFileName, 'helmfile.lock');
const existingLockFileContent = await getFile(lockFileName);
if (isFalsy(existingLockFileContent)) {
logger.debug('No helmfile.lock found');
return null;
}
try {
const toolConstraints: ToolConstraint[] = [
{
toolName: 'helm',
constraint: await resolveToolConstraint(config, 'helm'),
},
{
toolName: 'helmfile',
constraint: await resolveToolConstraint(config, 'helmfile', () =>
Result.parse(existingLockFileContent, LockVersion).unwrapOrNull(),
),
},
];
const needKustomize = updatedDeps.some(
(dep) => dep.managerData?.needKustomize,
);
if (needKustomize) {
toolConstraints.push({
toolName: 'kustomize',
constraint: await resolveToolConstraint(config, 'kustomize'),
});
}
const cmd: string[] = [];
const docs = parseYaml(newPackageFileContent, {
removeTemplates: true,
customSchema: Doc,
failureBehaviour: 'filter',
});
for (const doc of docs) {
for (const value of coerceArray(doc.repositories).filter(isOCIRegistry)) {
const loginCmd = await generateRegistryLoginCmd(
value.name,
`https://${value.url}`,
// this extracts the hostname from url like format ghcr.ip/helm-charts
value.url.replace(regEx(/\/.*/), ''),
);
// v8 ignore else -- needs a repository the login helper cannot handle
if (loginCmd) {
cmd.push(loginCmd);
}
}
}
cmd.push(`helmfile deps -f ${quote(packageFileName)}`);
return await updateLockFile({
lockFileName,
existingLockFileContent,
packageFile: { path: packageFileName, contents: newPackageFileContent },
run: () =>
exec(cmd, {
docker: {},
extraEnv: generateHelmEnvs(),
toolConstraints,
}),
});
} catch (err) {
/* v8 ignore if -- defensive rethrow, not reproduced in the helmfile specs */
if (err.message === TEMPORARY_ERROR) {
throw err;
}
logger.debug({ err }, 'Failed to update Helmfile lock file');
return artifactErrorResult(lockFileName, err);
}
}