如何从github操作中的文件中分配环境变量?
我目前正在从事一个Django项目。我创建了一个github操作,以运行python manage.py test
命令每次将代码推到main
分支时。
这里的问题是,我的项目中有许多环境变量。我无法将ENV变量设置为每个变量的GitHub秘密。
我的存储库中有一个env.dev
文件。我需要做的是,每当我推动代码时,都需要通过从env.dev
文件中读取环境变量来分配环境变量。
有什么办法做到这一点吗?
这是我的django.yml
用于github操作的文件。
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如“ 我如何使用github操作? “ https://github.com/marketplace/actions/dotenv-action” rel =“ nofollow noreferrer”> dotenv动作确实从本仓的根部读取
.env
文件,并提供环境变量来构建步骤。但是这些并不是Github的秘密。
有一个 api ,这意味着,如果您的
.env
内容不经常变化,则可以脚本脚本秘密创建步骤。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.