diff --git a/dotenv_action.js b/dotenv_action.js index dc69b96..c7b4b92 100644 --- a/dotenv_action.js +++ b/dotenv_action.js @@ -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; \ No newline at end of file +module.exports = dotenv_action; diff --git a/fixtures/.expand.env b/fixtures/.expand.env new file mode 100644 index 0000000..db29f45 --- /dev/null +++ b/fixtures/.expand.env @@ -0,0 +1,3 @@ +FIXTURES_3=xyz +EXPANDED=123-${FIXTURES_3} +EXPANDED_2=123-$FIXTURES_3 \ No newline at end of file diff --git a/index.test.js b/index.test.js index 8223178..8b463da 100644 --- a/index.test.js +++ b/index.test.js @@ -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" }); }) \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 890a1f9..217e262 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,8 @@ "license": "MIT", "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", @@ -2137,6 +2138,14 @@ "node": ">=8" } }, + "node_modules/dotenv-expand": { + "version": "8.0.3", + "resolved": "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-8.0.3.tgz", + "integrity": "sha512-SErOMvge0ZUyWd5B0NXMQlDkN+8r+HhVUsxgOO7IoPDOdDRD2JjExpN6y3KnFR66jsJMwSn1pqIivhU5rcJiNg==", + "engines": { + "node": ">=12" + } + }, "node_modules/electron-to-chromium": { "version": "1.3.802", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.802.tgz", @@ -8256,6 +8265,11 @@ "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.2.0.tgz", "integrity": "sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw==" }, + "dotenv-expand": { + "version": "8.0.3", + "resolved": "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-8.0.3.tgz", + "integrity": "sha512-SErOMvge0ZUyWd5B0NXMQlDkN+8r+HhVUsxgOO7IoPDOdDRD2JjExpN6y3KnFR66jsJMwSn1pqIivhU5rcJiNg==" + }, "electron-to-chromium": { "version": "1.3.802", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.802.tgz", diff --git a/package.json b/package.json index ab65343..6a88a6a 100644 --- a/package.json +++ b/package.json @@ -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",