Skip to content

Commit

Permalink
Merge pull request #34 from falti/variable_expansion
Browse files Browse the repository at this point in the history
Variable expansion
  • Loading branch information
falti authored Oct 17, 2022
2 parents 376a458 + 87b9d0e commit c29c64d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
7 changes: 4 additions & 3 deletions dotenv_action.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ let dotenv_action = function (dotenvFile) {
}

const dotenv = require('dotenv').config({ path: dotenvFile });
const dotenv_expand = require('dotenv-expand').expand(dotenv);
console.log("loading .env file from " + dotenvFile);

const returnedMap = {};
for (const key in dotenv.parsed) {
const value = dotenv.parsed[key];
for (const key in dotenv_expand.parsed) {
const value = dotenv_expand.parsed[key];
const lowercase_key = key.toLocaleLowerCase()
returnedMap[lowercase_key] = value;
}
return returnedMap;
}

module.exports = dotenv_action;
module.exports = dotenv_action;
3 changes: 3 additions & 0 deletions fixtures/.expand.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FIXTURES_3=xyz
EXPANDED=123-${FIXTURES_3}
EXPANDED_2=123-$FIXTURES_3
5 changes: 5 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ test('test runs with different path', () => {
test('test runs with broken path', () => {
const dotenv_action = require('./dotenv_action');
expect(() => { dotenv_action("nosuchfile")}).toThrow(Error);
})

test('test runs with expanded values', () => {
const dotenv_action = require('./dotenv_action');
expect(dotenv_action("fixtures/.expand.env")).toEqual({ fixtures_3: "xyz", "expanded": "123-xyz", "expanded_2": "123-xyz" });
})
16 changes: 15 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"homepage": "https://github.com/falti/dotenv-action#readme",
"dependencies": {
"@actions/core": "^1.9.1",
"dotenv": "^8.2.0"
"dotenv": "^8.2.0",
"dotenv-expand": "^8.0.3"
},
"devDependencies": {
"@zeit/ncc": "^0.22.1",
Expand Down

0 comments on commit c29c64d

Please sign in to comment.