-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.js
41 lines (36 loc) · 1.07 KB
/
action.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
"use strict";
const env = require("process").env;
const os = require("os");
const fs = require("fs");
const join = require("path").join;
const chosenWay = "envFile";
const ways = {
"setEnv": function(variablesToPassThrough) {
for (let varName of variablesToPassThrough) {
let v = env[varName];
if(v)
console.log("::set-env name=" + varName + "::" + v);
else
console.log("::warning::No env var " + varName + " to pass through");
}
},
"envFile": function(variablesToPassThrough) {
const filePath = env["GITHUB_ENV"];
let lines2append = [];
for (let varName of variablesToPassThrough) {
let v = env[varName];
if(v)
lines2append.push(varName + "=" + v);
else
console.log("::warning::No env var " + varName + " to pass through");
}
lines2append.push("");
fs.appendFileSync(filePath, lines2append.join(os.EOL), {
encoding: "utf8"
});
}
};
fs.readFile(join(__dirname, "variables2pass.txt"), "utf8", function (err, data) {
const variablesToPassThrough = data.split(/\r?\n/g).filter(n => !!n);
ways[chosenWay](variablesToPassThrough);
});