User Tools

Site Tools


wiki:add_dotenv_env_file_github_action

Add dotenv (.env) file in Github action

Instead of creating variables one by one in GH action like so:

   - name: 'Create env file'
        run: |
          touch .env
          echo API_ENDPOINT="https://xxx.execute-api.us-west-2.amazonaws.com" >> .env
          echo API_KEY=${{ secrets.API_KEY }} >> .env
          cat .env

You can base64 encode the entire .env file and c/p it into the Github secrets variable.

Encode the file:

cat apps/myapp/.env | base64 -w 0

Now c/p the output from above command to GH secrets, go to repository Settings > Secrets and variables > Actions > New repository secret.

Next in the github workflow decode the secret and redirect it to the .env e.g.

...
      - name: Create .env
        env:
          ENV_SECRET: ${{ secrets.DOTENV_STY }}
        run: |
          echo "$ENV_SECRET" | base64 --decode > apps/myapp/.env
...

Tested on

  • Github actions 2025.02

See also

References

wiki/add_dotenv_env_file_github_action.txt · Last modified: 2025/02/17 14:18 by antisa

Except where otherwise noted, content on this wiki is licensed under the following license: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki