Skip to content

Commit

Permalink
Merge pull request #15 from F21/support-variable-expansion
Browse files Browse the repository at this point in the history
Add support for variable expansion
  • Loading branch information
xom9ikk authored Mar 3, 2023
2 parents 0aa0b3b + dbd05a4 commit de1ff27
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
9 changes: 8 additions & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* ⛳ ability to specify the path to the folder;
* 🎨 setup mode;
* 💎 simple API;
* 🍃 variable expansion;
## 💡 Input
Expand All @@ -31,7 +32,7 @@
| `load-mode` | x | `strict` | sets whether the program should fail when the .env file is not present (`strict`) or continue (`skip`) | skip|

## 🧩 Notes
This action is built on top of the [dotenv](https://github.com/motdotla/dotenv) library.
This action is built on top of the [dotenv](https://github.com/motdotla/dotenv) and [dotenv-expand](https://github.com/motdotla/dotenv-expand) libraries.
When starting the action, the file is read from the target folder in the `path` property and using the mode specified in` mode`.

The name of the `.env` file depends on the startup mode.
Expand All @@ -43,3 +44,9 @@ Thus, specifying `mode: test` will read the `.env.test` file. `mode: development
After reading and parsing the variables from the `.env` file, it writes them to `GITHUB_ENV`.

If the action should continue when the .env file is not present, the optional `load-mode` flag can be set to `skip`. This can be particularly, for example, useful in secondary branches, where some aspects of the action may not be relevant.

Action also supports variable expansion, e.g.
```bash
PASSWORD="s1mpl3"
DB_PASS=$PASSWORD
```
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

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.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dot-env",
"version": "2.1.1",
"version": "2.2.0",
"private": true,
"description": "GitHub Action to read .env file and add variables to GITHUB_ENV",
"main": "dist/index.js",
Expand Down Expand Up @@ -28,7 +28,8 @@
"license": "MIT",
"dependencies": {
"@actions/core": "^1.2.6",
"dotenv": "^8.2.0"
"dotenv": "^8.2.0",
"dotenv-expand": "^10.0.0"
},
"devDependencies": {
"@types/node": "^14.14.10",
Expand Down
5 changes: 4 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as core from '@actions/core';
import * as dotenv from 'dotenv';
import * as dotenvExpand from 'dotenv-expand';
import * as fs from 'fs';
import * as path from 'path';

Expand Down Expand Up @@ -42,7 +43,9 @@ const readFile: IReadFile = async (filePath, loadMode) => new Promise<string>((
return resolve(data);
}));

const parseEnv: IParseEnv = (content) => dotenv.parse(content);
const parseEnv: IParseEnv = (
content,
) => dotenvExpand.expand({ parsed: dotenv.parse(content) }).parsed;

const setEnvVariable: ISetEnvVariable = ([key, value]) => {
core.exportVariable(key, value);
Expand Down

0 comments on commit de1ff27

Please sign in to comment.