-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathvss-task.js
51 lines (43 loc) · 1.34 KB
/
vss-task.js
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
const fs = require('fs');
const path = require('path');
const config = {
public: {
id: '8f9cb13f-f551-439c-83e4-fac6801c3fab',
name: 'trivy',
friendlyName: 'Trivy',
},
private: {
id: '3612b9ee-fd2a-11ef-8d14-00155d47a2a9',
name: 'trivy-dev',
friendlyName: 'Trivy [Dev]',
},
};
function updateJsonFile(filePath, updates) {
try {
const data = fs.readFileSync(filePath, 'utf8');
const jsonObject = JSON.parse(data);
updates.version = {
Major: jsonObject.version.Major,
Minor: jsonObject.version.Minor,
// Set patch to the current build number or increment it
Patch: process.env.BUILD_NUMBER || jsonObject.version.Patch + 1,
};
Object.assign(jsonObject, updates);
fs.writeFileSync(filePath, JSON.stringify(jsonObject, null, 2) + '\n', 'utf8');
console.log(`Applied config for ${filePath}: ${JSON.stringify(updates, null, 2)}`);
} catch (error) {
console.error('Error updating JSON file:', error);
}
}
function updateTask(extensionType) {
const tasks = ['trivyV1', 'trivyV2'];
const updates = {
name: config[extensionType].name,
id: config[extensionType].id,
friendlyName: config[extensionType].friendlyName,
};
tasks.forEach((task) => {
updateJsonFile(path.join('trivy-task', task, 'task.json'), updates);
});
}
module.exports = { updateTask };