This action provides the following functionality for GitHub Actions users:
- Read json (key-value pairs) and export all of them as environment variables
- Optionally including, excluding and manipulating variables as needed before importing
Before | After |
---|---|
- run: echo "Value of MY_SECRET1: $MY_SECRET1" env: MY_SECRET1: ${{ secrets.MY_SECRET1 }} MY_SECRET2: ${{ secrets.MY_SECRET2 }} MY_SECRET3: ${{ secrets.MY_SECRET3 }} MY_SECRET4: ${{ secrets.MY_SECRET4 }} MY_SECRET5: ${{ secrets.MY_SECRET5 }} MY_SECRET6: ${{ secrets.MY_SECRET6 }} ... |
- uses: RaphaelNeumann/json-to-env-action@v1 with: json_envs: ${{ toJSON(secrets) }} - run: echo "Value of MY_SECRET1: $MY_SECRET1" |
Add the following action to your workflow:
- uses: RaphaelNeumann/json-to-env-action@v1
with:
json_envs: ${{ toJSON(secrets) }}
After running this action, subsequent actions will be able to access the secrets as env variables.
Note the json_envs
key. It is mandatory so the action can read and export the secrets, vars for example.
Basic using secrets:
steps:
- uses: actions/checkout@v3
- uses: RaphaelNeumann/json-to-env-action@v1
with:
json_envs: ${{ toJSON(secrets) }}
- run: echo "Value of MY_SECRET: $MY_SECRET"
Basic using Enviroment Variables:
enviroment: production
steps:
- uses: actions/checkout@v3
- uses: RaphaelNeumann/json-to-env-action@v1
with:
json_envs: ${{ toJSON(vars) }}
- run: echo "Value of PRODUCTION_ENV_VAR: $PRODUCTION_ENV_VAR"
Add a prefix:
Adds a prefix to all exported secrets.
steps:
- uses: actions/checkout@v3
- uses: RaphaelNeumann/json-to-env-action@v1
with:
json_envs: ${{ toJSON(secrets) }}
prefix: PREFIXED_
- run: echo "Value of PREFIXED_MY_SECRET: $PREFIXED_MY_SECRET"
Convert:
Converts all exported secrets according to a template.
Available: lower, upper, camel, constant, pascal, snake
.
steps:
- uses: actions/checkout@v3
- uses: RaphaelNeumann/json-to-env-action@v1
with:
json_envs: ${{ toJSON(secrets) }}
convert: lower
- run: echo "Value of my_secret: $my_secret"
Include or skip the prefix on conversion (default is true):
steps:
- uses: actions/checkout@v3
- uses: RaphaelNeumann/json-to-env-action@v1
with:
json_envs: ${{ toJSON(secrets) }}
prefix: PREFIX_
convert: lower
convert_prefix: false
- run: env
# E.g. secret with MY_SECRET would become PREFIX_my_secret
This action uses the input in json_envs
to read a JSON in key-value pairs format, and exporting all the variables one by one.
The scripts and documentation in this project are released under the MIT License
Contributions are welcome! Past contributors:
- Tamas Kadar @KTamas
- José Luis Pereira @oNaiPs