Skip to content

Latest commit

 

History

History
13 lines (11 loc) · 892 Bytes

load-secret-env-variables-using-dotenv.md

File metadata and controls

13 lines (11 loc) · 892 Bytes

Load secret environment variables using dotenv

I usually keep secret environment variables in a .env.local file (not checked into version control) and use dotenv to load the variables into process.env. To make these secrets available in a GitHub action, the variables need to be stored as an encrypted secret on GitHub. If stored as MY_SECRET, the secret is available in an action as secrets.MY_SECRET. To be able to load this variable using dotenv, the variable needs to be written to the .env.local file. The following step implements this:

steps:
  - name: Create .env.local file
    run: |
      touch .env.local
      echo MY_SECRET=$MY_SECRET >> .env.local
    env:
      MY_SECRET: ${{ secrets.MY_SECRET }}