Generate dotenv
ActionsTags
(1)gen env
This GitHub Action compute dotenv file from github vars and secrets. Then you may pass it whenever you need.
- Minimum dependency between changing your vars/secrets in repository and
changing your action's files
So you will have possibility to update your environment (not only values but keys) without need to make new commits in your yml. So you can simply rerun some workflow.
- Flexibility in choosing strategy how you want to declare your dotenv. So this
is combination from such factors:
- include/exclude pattern matching
- value as single value or as part of dotenv's content
- mapping to new names or shorthand syntax for the same ones
- order of merging (prioritizing)
-
### All options are optional, ### but it important to understand their relations from each other ### to be able flexibly satisfies all your requirements. ### ### Below the example with exhaustive usage of all options uses: kindkitchen/genv@v1.0.0 with: dotenv_path: ./.env vars_obj: ${{ toJson(vars) }} secrets_obj: ${{ toJson(secrets) }} content_from_vars_include_pattern: "^CONFIG$" vars_include_pattern: ".*" vars_exclude_pattern: "^TEST" content_from_secrets_include_pattern: "^APP$" secrets_include_pattern: ".*" secrets_exclude_pattern: "GITHUB" dotenv_content: | HELLO=world OK=captain
- The core options:
dotenv_path
the path to dotenv file where result will be storedvars_obj
json string with low priority variables (probably you may want usetoJson(vars)
as in example)secrets_obj
json string with higher priority
content_from_vars_include_pattern
- herevars.CONFIG
will be appended to.env
file. And because this defined incontent_from_vars_include_pattern
the content will be treated as already part of the.env
. So possibly in your repository you can have varCONFIG
with valuePORT=300 DB_NAME=example
vars_include_pattern
- we continue to processing github'svars
that should have single value (not part of the content).vars_exclude_pattern
- all passed vars from previous step are filtered by not match this pattern- Then repeat previous steps but for secrets:
content_from_secrets_include_pattern
secrets_include_pattern
secrets_exclude_pattern
dotenv_content
- the part of dotenv with absolute priority
This order describe the priority of applying variables on conflict. Currently all variants of conflicted keys will be present and the priority relayed on assumption that the consumer of your dotenv file will use strategy
last written win
- The core options:
If you have not so many variables that should be passed into dotenv file - may be the simpler solution will be something like this:
- One of the simplest and straightforward alternatives
- run: |
echo "PORT=${{ vars.PORT }}" >> .env
echo "PORT=${{ secrets.API_KEY }}" >> .env
- Usage of the another, more authority and famous github action:
https://github.com/marketplace?query=dotenv
Generate dotenv is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.