Skip to content

Commit

Permalink
Merge pull request #43 from F21/support-exporting-as-environment-vari…
Browse files Browse the repository at this point in the history
…ables

Support exporting as environment variables
  • Loading branch information
falti authored Feb 28, 2023
2 parents 12dfe4c + 0b74ee3 commit 6024f6b
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 1 deletion.
14 changes: 14 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,17 @@ jobs:
- uses: ./
with:
path: ./fixtures/.env

test-export:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./
with:
path: ./fixtures/.env
export-variables: true
- run: |
if [ "$fixtures_1" != "123" ]; then
echo "Variables not exported"
exit 1
fi
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ Log variables after reading from the `.env` file.

Mask values after reading from the `.env` file.

### `export-variables`

Export values as environment variables in addition to storing them in the output after reading from the `.env` file.

## Outputs

### `generic`
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ inputs:
description: 'whether to mask the variables as secrets or not'
required: false
default: 'false'
export-variables:
description: 'whether to export the variables to the environment or not'
required: false
default: 'false'
outputs:
generic: # output will be available to future steps
description: 'This command will have generic output variables based on .env'
Expand Down
Binary file modified dist/index.js.cache
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/index.js.cache.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ try {
const logVariables = core.getInput('log-variables').toLowerCase() === 'true';
const maskVariables =
core.getInput('mask-variables').toLowerCase() === 'true';
const exportVariables =
core.getInput('export-variables').toLowerCase() === 'true';
const variables = dotenvAction(dotenvFile, logVariables);

if (maskVariables) {
Expand All @@ -27,6 +29,10 @@ try {
for (const key in variables) {
const value = variables[key];
core.setOutput(key, value);

if (exportVariables) {
core.exportVariable(key, value);
}
}
} catch (error) {
core.setFailed(error.message);
Expand Down

0 comments on commit 6024f6b

Please sign in to comment.