-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
artifacts.ts
76 lines (70 loc) · 2.02 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
import { quote } from 'shlex';
import { logger } from '../../logger';
import { ExecOptions, exec } from '../../util/exec';
import {
getSiblingFileName,
getSubDirectory,
readLocalFile,
writeLocalFile,
} from '../../util/fs';
import { UpdateArtifact, UpdateArtifactsResult } from '../common';
async function helmUpdate(manifestPath: string): Promise<void> {
const cmd = `helm dependency update ${quote(getSubDirectory(manifestPath))}`;
const execOptions: ExecOptions = {
docker: {
image: 'renovate/helm',
},
};
await exec(cmd, execOptions);
}
export async function updateArtifacts({
packageFileName,
updatedDeps,
newPackageFileContent,
config,
}: UpdateArtifact): Promise<UpdateArtifactsResult[] | null> {
logger.debug(`helmv3.updateArtifacts(${packageFileName})`);
const isLockFileMaintenance = config.updateType === 'lockFileMaintenance';
if (
!isLockFileMaintenance &&
(updatedDeps === undefined || updatedDeps.length < 1)
) {
logger.debug('No updated helmv3 deps - returning null');
return null;
}
const lockFileName = getSiblingFileName(packageFileName, 'Chart.lock');
const existingLockFileContent = await readLocalFile(lockFileName);
if (!existingLockFileContent) {
logger.debug('No Chart.lock found');
return null;
}
try {
await writeLocalFile(packageFileName, newPackageFileContent);
logger.debug('Updating ' + lockFileName);
await helmUpdate(packageFileName);
logger.debug('Returning updated Chart.lock');
const newHelmLockContent = await readLocalFile(lockFileName);
if (existingLockFileContent === newHelmLockContent) {
logger.debug('Chart.lock is unchanged');
return null;
}
return [
{
file: {
name: lockFileName,
contents: newHelmLockContent,
},
},
];
} catch (err) {
logger.warn({ err }, 'Failed to update Helm lock file');
return [
{
artifactError: {
lockFile: lockFileName,
stderr: err.message,
},
},
];
}
}