forked from renovatebot/renovate
/
artifacts.ts
94 lines (86 loc) · 2.23 KB
/
artifacts.ts
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
import { quote } from 'shlex';
import { logger } from '../../logger';
import { exec } from '../../util/exec';
import { BinarySource } from '../../util/exec/common';
import { readLocalFile, writeLocalFile } from '../../util/fs';
import { UpdateArtifact, UpdateArtifactsResult } from '../common';
export async function updateArtifacts({
packageFileName,
updatedDeps,
newPackageFileContent,
config,
}: UpdateArtifact): Promise<UpdateArtifactsResult[] | null> {
logger.debug(`mix.getArtifacts(${packageFileName})`);
if (updatedDeps.length < 1) {
logger.debug('No updated mix deps - returning null');
return null;
}
const cwd = config.localDir;
if (!cwd) {
logger.debug('No local dir specified');
return null;
}
const lockFileName = 'mix.lock';
try {
await writeLocalFile(packageFileName, newPackageFileContent);
} catch (err) {
logger.warn({ err }, 'mix.exs could not be written');
return [
{
artifactError: {
lockFile: lockFileName,
stderr: err.message,
},
},
];
}
const existingLockFileContent = await readLocalFile(lockFileName, 'utf8');
if (!existingLockFileContent) {
logger.debug('No mix.lock found');
return null;
}
const cmdParts =
config.binarySource === BinarySource.Docker
? [
'docker',
'run',
'--rm',
`-v ${cwd}:${cwd}`,
`-w ${cwd}`,
'renovate/elixir mix',
]
: ['mix'];
cmdParts.push('deps.update');
/* istanbul ignore next */
try {
const command = [...cmdParts, ...updatedDeps.map(quote)].join(' ');
await exec(command, { cwd });
} catch (err) {
logger.warn(
{ err, message: err.message },
'Failed to update Mix lock file'
);
return [
{
artifactError: {
lockFile: lockFileName,
stderr: err.message,
},
},
];
}
const newMixLockContent = await readLocalFile(lockFileName, 'utf8');
if (existingLockFileContent === newMixLockContent) {
logger.debug('mix.lock is unchanged');
return null;
}
logger.debug('Returning updated mix.lock');
return [
{
file: {
name: lockFileName,
contents: newMixLockContent,
},
},
];
}