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
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.