0

I'm currently working on a Django project. I have create a GitHub action to run python manage.py test command everytime I push the code to main branch.

The problem here is, I have many environment variables in my project. I can't set env variables as GitHub secrets for each variables.

I have a env.dev file in my repository. What I need to do is, everytime I push the code, it needs to assign environment variables by reading it from the env.dev file.

Is there any way to do this?

This is my django.yml file used for GitHub actions.

name: Django CI

on:
  pull_request:
    branches: [ "main"]

jobs:
  build:

    runs-on: ubuntu-latest
    strategy:
      max-parallel: 4
      matrix:
        python-version: [3.9]

    steps:
    - uses: actions/checkout@v3
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v3
      with:
        python-version: ${{ matrix.python-version }}
    - name: Install Dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -r requirements.txt
    - name: Run Tests
      run: |
        python manage.py test
rangarajan
  • 143
  • 5
  • 17
  • There is likely a cleaner solution, but you could create your own GitHub action that uses node to read the file and outputs secrets as workflow secret parameters. If you don't find another solution feel free to comment and I'll code it for you tomorrow. – Saddy Jul 05 '22 at 02:50

1 Answers1

1

As noted in "How do I use an env file with GitHub Actions?", you do have actions like Dotenv Action which do read a .env file from the root of this repo and provides environment variables to build steps.

But those would not be GitHub secret though.
There is an API to create secrets, which means, if your .env content does not change too often, you can script the secret creation step.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250