Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
book-open

GitHub Action

Export all secrets to env variables

v1

Export all secrets to env variables

book-open

Export all secrets to env variables

Utility action that exports all github secrets to environment variables

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Export all secrets to env variables

uses: oNaiPs/secrets-to-env-action@v1

Learn more about this action in oNaiPs/secrets-to-env-action

Choose a version

secrets-to-env

secrets-to-env-action status

This action provides the following functionality for GitHub Actions users:

  • Read Github secrets and export them as environment variables
  • Optionally including, excluding and manipulating variables as needed before importing

Usage

Add the following action to your workflow:

- uses: oNaiPs/secrets-to-env-action@v1
  with:
    secrets: ${{ toJSON(secrets) }}

Note the secrets key. It is mandatory so the action can read and export the secrets.

Basic:

steps:
- uses: actions/checkout@v3
- uses: oNaiPs/secrets-to-env-action@v1
  with:
    secrets: ${{ toJSON(secrets) }}
- run: echo "Value of MY_SECRET: $MY_SECRET"

Include or exclude secrets:

Exclude defined secret MY_SECRET from list of secrets.

steps:
- uses: actions/checkout@v3
- uses: oNaiPs/secrets-to-env-action@v1
  with:
    secrets: ${{ toJSON(secrets) }}
    exclude: MY_SECRET
# MY_SECRET is not export

Only include secret MY_SECRET

steps:
- uses: actions/checkout@v3
- uses: oNaiPs/secrets-to-env-action@v1
  with:
    secrets: ${{ toJSON(secrets) }}
    include: MY_SECRET
- run: echo "Value of MY_SECRET: $MY_SECRET"

NOTE: If specified secret does not exist, it is ignored.

Add a prefix:

Adds a prefix to all exported secrets.

steps:
- uses: actions/checkout@v3
- uses: oNaiPs/secrets-to-env-action@v1
  with:
    secrets: ${{ 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: oNaiPs/secrets-to-env-action@v1
  with:
    secrets: ${{ toJSON(secrets) }}
    convert: lower
- run: echo "Value of my_secret: $my_secret"

License

The scripts and documentation in this project are released under the MIT License

Contributions

Contributions are welcome!