-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildinfo.js
54 lines (42 loc) · 1.49 KB
/
buildinfo.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
52
53
54
const { readFileSync } = require('fs');
const { dirname, join } = require('path');
const { debug, error } = require('@actions/core');
const { getFileEncoding } = require('./inputs.js');
function readBuildInfoFile(filePath) {
const outputs = [];
try {
debug(`readBuildInfo(${filePath})`);
const encoding = getFileEncoding();
const location = dirname(filePath);
const content = readFileSync(filePath, encoding);
const lines = content.split(/\n|\r\n/);
debug(`readBuildInfo(${filePath}) : file has ${lines.length} lines`);
lines.forEach(line => {
if (line.startsWith('outputs') && line.includes('filename=')) {
const outputFileName = line.split('=')[1];
const outputFilePath = join(location, outputFileName);
if (!outputFileName.includes('.pom')) {
outputs.push(outputFilePath);
}
}
});
return outputs;
} catch (err) {
error(err);
throw new Error(`Cannot read buildinfo file ${filePath}`, { cause: err });
} finally {
debug(`readBuildInfo(${filePath}) : output [${outputs.length}] ${JSON.stringify(outputs)}`);
}
}
function readBuildInfoFiles(filePathArray) {
let outputs = [];
if (filePathArray) {
filePathArray.forEach(file => {
outputs = outputs.concat(readBuildInfoFile(file));
});
}
return outputs;
}
module.exports = {
readBuildInfoFiles,
};