mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-31 17:51:49 +00:00
bf5ff94d28
Migrate apm, bun, cargo, cocoapods, composer, conan, copier, deno,
devbox, gomod, helmv3, jsonnet-bundler, kustomize, mix, nuget and vendir
onto `fileAddition()`, `artifactError()` and `artifactErrorResult()`.
copier's private `artifactError()` is replaced by the shared one.
Behaviour change: artifact error text now comes from
`artifactErrorMessageFromExecError` everywhere, i.e. a non-blank
`err.stderr`, else a non-blank `err.stdout`, else `err.message`.
Previously apm used `${err}` ("Error: " prefix), cocoapods used a
nullish coalesce that kept an empty stderr, nuget preferred stdout over
stderr, and jsonnet-bundler emitted an undefined stderr with no
fallback. The rest used `err.message` only and are unchanged for errors
without output.
102 lines
3.0 KiB
TypeScript
102 lines
3.0 KiB
TypeScript
import { isNonEmptyArray } from '@sindresorhus/is';
|
|
import semver from 'semver';
|
|
import { quote } from 'shlex';
|
|
import { logger } from '../../../logger/index.ts';
|
|
import { exec } from '../../../util/exec/index.ts';
|
|
import type { ExecOptions } from '../../../util/exec/types.ts';
|
|
import { getSiblingFileName, readLocalFile } from '../../../util/fs/index.ts';
|
|
import type { UpdateArtifact, UpdateArtifactsResult } from '../types.ts';
|
|
import {
|
|
artifactErrorResult,
|
|
fileAddition,
|
|
resolveToolConstraint,
|
|
} from '../util.ts';
|
|
|
|
export async function updateArtifacts({
|
|
config,
|
|
packageFileName,
|
|
updatedDeps,
|
|
}: UpdateArtifact): Promise<UpdateArtifactsResult[] | null> {
|
|
const lockFileName = getSiblingFileName(packageFileName, 'devbox.lock');
|
|
const existingLockFileContent = await readLocalFile(lockFileName, 'utf8');
|
|
if (!existingLockFileContent) {
|
|
logger.debug('No devbox.lock found');
|
|
return null;
|
|
}
|
|
|
|
const nixConstraint = await resolveToolConstraint(config, 'nix');
|
|
const devboxConstraint = await resolveToolConstraint(config, 'devbox');
|
|
|
|
const supportsNoInstall = devboxConstraint
|
|
? semver.intersects(devboxConstraint, '>=0.14.0')
|
|
: true;
|
|
|
|
const execOptions: ExecOptions = {
|
|
cwdFile: packageFileName,
|
|
toolConstraints: [
|
|
// we are required to install nix because devbox spawns nix commands internally
|
|
// https://github.com/renovatebot/renovate/discussions/35382
|
|
// https://github.com/jetify-com/devbox/issues/2585
|
|
{
|
|
toolName: 'nix',
|
|
constraint: nixConstraint,
|
|
},
|
|
{
|
|
toolName: 'devbox',
|
|
constraint: devboxConstraint,
|
|
},
|
|
],
|
|
docker: {},
|
|
};
|
|
|
|
const cmd = [];
|
|
if (config.isLockFileMaintenance) {
|
|
cmd.push(
|
|
supportsNoInstall ? 'devbox update --no-install' : 'devbox update',
|
|
);
|
|
} else if (isNonEmptyArray(updatedDeps)) {
|
|
if (supportsNoInstall) {
|
|
const updateCommands: string[] = updatedDeps
|
|
.map(
|
|
(dep) =>
|
|
dep.depName && `devbox update ${quote(dep.depName)} --no-install`,
|
|
)
|
|
.filter((dep): dep is string => Boolean(dep));
|
|
if (updateCommands.length) {
|
|
cmd.push(...updateCommands);
|
|
} else {
|
|
logger.trace('No updated devbox packages - returning null');
|
|
return null;
|
|
}
|
|
} else {
|
|
cmd.push('devbox install');
|
|
}
|
|
} else {
|
|
logger.trace('No updated devbox packages - returning null');
|
|
return null;
|
|
}
|
|
|
|
const oldLockFileContent = await readLocalFile(lockFileName);
|
|
if (!oldLockFileContent) {
|
|
logger.trace(`No ${lockFileName} found`);
|
|
return null;
|
|
}
|
|
|
|
try {
|
|
await exec(cmd, execOptions);
|
|
const newLockFileContent = await readLocalFile(lockFileName);
|
|
|
|
if (
|
|
!newLockFileContent ||
|
|
Buffer.compare(oldLockFileContent, newLockFileContent) === 0
|
|
) {
|
|
return null;
|
|
}
|
|
logger.trace('Returning updated devbox.lock');
|
|
return [fileAddition(lockFileName, newLockFileContent)];
|
|
} catch (err) {
|
|
logger.warn({ err }, 'Error updating devbox.lock');
|
|
return artifactErrorResult(lockFileName, err);
|
|
}
|
|
}
|