Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cardinalby/export-env-action
GitHub Action that exports .env file variables to job env
https://github.com/cardinalby/export-env-action
Last synced: about 5 hours ago
JSON representation
GitHub Action that exports .env file variables to job env
- Host: GitHub
- URL: https://github.com/cardinalby/export-env-action
- Owner: cardinalby
- License: mit
- Created: 2022-01-03T15:44:48.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2024-06-19T04:03:19.000Z (5 months ago)
- Last Synced: 2024-11-03T16:03:11.278Z (4 days ago)
- Language: TypeScript
- Size: 473 KB
- Stars: 41
- Watchers: 1
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![test](https://github.com/cardinalby/export-env-action/actions/workflows/test.yml/badge.svg)](https://github.com/cardinalby/export-env-action/actions/workflows/test.yml)
# Table of contents
1. [Export variables from .env file to job env](#export_variables_from_env)
1. [Examples](#examples)
1. [Simple case](#examples_simple_case)
1. [Multiple environment files](#examples_multiple_environment)
1. [Specify variables filter](#examples_specify_variables_filter)
1. [Expand variables](#examples_expand_variables)
1. [Do not export](#examples_do_not_export)
1. [Inputs](#inputs)
1. [envFile](#inputs_env_file)
1. [filter](#inputs_filter)
1. [expand](#inputs_expand)
1. [expandWithJobEnv](#inputs_expand_with_job_env)
1. [export](#inputs_export)
1. [mask](#inputs_mask)
1. [Outputs](#outputs)## Export variables from .env file to job env
Can be useful if you want to use .env file as a storage of constants among
multiple workflows.## Examples
### Simple case:
```dotenv
# constants.env fileVAR1=abc
VAR2=def
``````yaml
- uses: cardinalby/export-env-action@v2
with:
envFile: 'constants.env'
# env.VAR1 == 'abc'
# env.VAR2 == 'def'
```### Multiple environment files:
```dotenv
# constants1.env fileVAR1=abc
VAR2=def
``````dotenv
# constants2.env fileVAR2=ghi
VAR3=jkl
``````yaml
- uses: cardinalby/export-env-action@v2
with:
envFile: 'constants1.env|constants2.env'
# env.VAR1 == 'abc'
# env.VAR2 == 'ghi'
# env.VAR3 == 'jkl'
```### Specify variables filter:
```dotenv
# constants.env fileVAR1=abc
VAR2=def
VAR3=ghi
``````yaml
- uses: cardinalby/export-env-action@v2
with:
envFile: 'constants.env'
filter: 'VAR1|VAR3'
# env.VAR1 == 'abc'
# env.VAR3 == 'jkl'
```### Expand variables
```dotenv
# constants.env filePROTOCOL=https
HOST=example.com
PORT=8080
URI=${PROTOCOL}://${HOST}:${PORT}
``````yaml
- uses: cardinalby/export-env-action@v2
with:
envFile: 'constants.env'
expand: 'true'
# env.PROTOCOL == 'https'
# env.HOST == 'example.com'
# env.PORT == '8080'
# env.URI == 'https://example.com:8080'
```### Do not export:
```dotenv
# constants.env fileVAR1=abc
VAR2=def
``````yaml
- uses: cardinalby/export-env-action@v2
id: exportStep
with:
envFile: 'constants.env'
export: 'false'
# env.VAR1 == ''
# env.VAR2 == ''
# steps.exportStep.outputs.VAR1 == 'abc'
# steps.exportStep.outputs.VAR2 == 'def'
```## Inputs
### 🔸 `envFile` Required
Path to env file to parse.### 🔹 `filter` Default: null
Filter regexp to only export specific variables matching the filter.It *filters* both exported variables and action outputs (if `export: false`), but doesn't impacts variables extending and masking.
If filter is: 'VAR_1|VAR_3'
```dotenv
VAR_1=aaa
VAR_2=bbb
VAR_3=ccc
```
Will lead to following exported variables: `VAR_1 = aaa`, `VAR3 = ccc`.### 🔹 `expand` Default: `false`
If `true`, "expands" variables:
```dotenv
VAR_1=aaa
VAR_2=${VAR_1}_bbb
```
Will lead to following exported variables: `VAR1 = aaa`, `VAR2 = aaa_bbb`.Read more about expand engine rules [here](https://github.com/motdotla/dotenv-expand#what-rules-does-the-expansion-engine-follow).
### 🔹 `expandWithJobEnv` Default: `false`
If `true`, "expands" variables considering step (job) env variables (in addition to variables defined in the same env file).
It means, `${GITHUB_RUN_ATTEMPT}` in a variable value will be substituted by the value of `$GITHUB_RUN_ATTEMPT` job env variable.### 🔹 `export` Default: `true`
Export variables to a job environment. If `false`, all variables will be set as an action
outputs instead.### 🔹 `mask` Default: `false`
If `true` [masks](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#masking-a-value-in-log) all result values (after expanding) as secrets.**Warning**: be cautious if you want to use this option, it is bad idea to store secrets in
`.env` file in the repo, use [GitHub secrets](https://docs.github.com/en/codespaces/managing-codespaces-for-your-organization/managing-encrypted-secrets-for-your-repository-and-organization-for-github-codespaces) for that purpose.## Outputs
If `export` is `false` then there are individual outputs for each variable from env file (where output name equals variable name).