Skip to content

Commit

Permalink
Adjusted replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
dschiese committed Mar 28, 2024
1 parent da77ec2 commit a3ba672
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ let envVariableNames = Object.keys(process.env).map(key => key); // stores the e
const workspacePath = process.env.GITHUB_WORKSPACE;
console.log(`GitHub workspace path: ${workspacePath}`);

//Change dir to runner home dir
/**
* Change dir to runner home dir
*/
try {
process.chdir(workspacePath);
} catch (err) {
Expand All @@ -29,15 +31,19 @@ envFilePaths.forEach(envFile => {
*/
function replaceEnvs(file){
fs.readFile(file, 'utf-8', function (err, data) {
let replaced = data;
envVariableNames.forEach(envVariable => {
let envVar = envVariable + "=";
replaced.includes(envVar) ?
replaced = replaced.replace(envVar, envVar + process.env[envVariable])
:
null;

const fileContent = data.split("\n");

const replacedContent = fileContent.map(line => {
const [key, value] = line.split("=");
if(envVariableNames.includes(key)) {
return `${key}=${process.env[key]}`
}
else
return line;
})
fs.writeFile(file, replaced, function (err) {

fs.writeFile(file, replacedContent.join("\n"), 'utf-8', function (err) {
if (err) return console.log(err);
});
});
Expand Down

0 comments on commit a3ba672

Please sign in to comment.