-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathreadFile.js
31 lines (26 loc) · 953 Bytes
/
readFile.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
const core = require('@actions/core');
const { promises: fsAsync, existsSync } = require('fs');
const yaml = require('yaml');
const readSchemaFile = async (path) => {
core.info(`Reading ${path} file ...`);
let content = await fsAsync.readFile(path, 'utf8');
try {
core.debug(`File read`);
return JSON.stringify(JSON.parse(content.toString()), null, 2);
} catch (e) {
try {
const [doc] = new yaml.Parser().parse(content.toString())
if (doc.value.items && doc.value.items.length > 0 && yaml.stringify(yaml.parse(content.toString()))) {
return content.toString();
}
} catch (ye) { /* empty */ }
throw e;
}
};
const readReleaseNotes = async (path) => {
if (existsSync(path)) {
let content = await fsAsync.readFile(path, 'utf8');
return content.toString();
}
};
module.exports = { readSchemaFile, readReleaseNotes };