-
Notifications
You must be signed in to change notification settings - Fork 3k
Expand file tree
/
Copy pathartifacts.ts
More file actions
108 lines (101 loc) · 2.99 KB
/
artifacts.ts
File metadata and controls
108 lines (101 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import is from '@sindresorhus/is';
import semver from 'semver';
import { quote } from 'shlex';
import { logger } from '../../../logger';
import { exec } from '../../../util/exec';
import type { ExecOptions } from '../../../util/exec/types';
import { getSiblingFileName, readLocalFile } from '../../../util/fs';
import type { UpdateArtifact, UpdateArtifactsResult } from '../types';
export async function updateArtifacts({
config: { constraints, isLockFileMaintenance, updateType },
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 supportsNoInstall = constraints?.devbox
? semver.intersects(constraints.devbox, '>=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: constraints?.nix,
},
{
toolName: 'devbox',
constraint: constraints?.devbox,
},
],
docker: {},
};
const cmd = [];
if (isLockFileMaintenance) {
cmd.push(
supportsNoInstall ? 'devbox update --no-install' : 'devbox update',
);
} else if (is.nonEmptyArray(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 [
{
file: {
type: 'addition',
path: lockFileName,
contents: newLockFileContent,
},
},
];
} catch (err) {
logger.warn({ err }, 'Error updating devbox.lock');
return [
{
artifactError: {
lockFile: lockFileName,
stderr: err.message,
},
},
];
}
}