-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
34 lines (26 loc) · 1.04 KB
/
index.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
const fs = require('fs');
const core = require('@actions/core');
(async () => {
try {
const path = core.getInput('composer_file');
const debug = core.getInput('debug');
const data = await fs.promises.readFile(path);
const composerJson = JSON.parse(data);
const generateEnvValues = (object, namePrefix) => {
for (const property in object) {
if (typeof object[property] === 'object' && object[property] !== null) {
generateEnvValues(object[property], namePrefix + property + '_');
continue;
}
const propertyName = property.replace(/[\/\\]/g, '-');
if (debug !== '0') {
console.log('${{ env.' + namePrefix + propertyName + ' }}');
}
core.exportVariable(namePrefix + propertyName, object[property]);
}
};
generateEnvValues(composerJson, 'composer_');
} catch (error) {
core.setFailed(error.message);
}
})();