如何在GitHub Actions中使用env文件? [英] How do I use an env file with GitHub Actions?

查看:222
本文介绍了如何在GitHub Actions中使用env文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个环境(dev,qa,prod),并且我正在使用.env文件存储机密等...现在我切换到GitHub Actions,我想使用我的.env文件并声明它们进入github action yml的 env 部分.

但是到目前为止,看来我无法设置文件路径,必须手动重新声明所有变量.

我应该如何进行最佳实践?

解决方案

您使用的是Circleci上下文,因此每个环境都有一套秘密.我知道他们正在努力将秘密带到组织级别,甚至可能在团队级别.如果他们会像在CCI中那样创建类似的上下文,则没有任何信息.

我曾考虑过使用yml上的$ {env} _GITHUB_KEY将环境作为像STAGE_GITHUB_KEY或INTEGRATION_GITHUB_KEY之类的秘密名称的前缀添加,作为目前的解决方法...您如何看待?

---原始答案:如果我对您很了解,那么您已经将dotenv文件存储在某个位置,并且想要将所有这些秘密注入到步骤中,而不必手动将它们添加到github秘密中,并在您迁移的每个工作流中进行映射...对吗?/p>

某人执行一项操作,该操作读取dotenv文件并将其值放入输出中,因此您可以在进一步的步骤中使用链接的文件.这是链接: https://github.com/marketplace/actions/dotenv-action

.env文件中存在的所有内容都将转换为输出变量.例如带有内容的.env文件:

  VERSION = 1.0作者=米老鼠 

您这样做:

  id:dotenv用途:./.github/actions/dotenv-action 

然后,您可以参考像这样的高山版本$ {{steps.dotenv.outputs.version}}

I have multiple environments (dev, qa, prod) and I'm using .env files to store secrets etc... Now I'm switching to GitHub Actions, and I want to use my .env files and declare them into the env section of the github actions yml.

But from what I've seen so far, it seems that I can not set a file path and I have to manually re-declare all variables.

How should I proceed as best practice?

解决方案

Edit: You were using Circleci Contexts, so with that you had a set of secrets of each env. I know they are working to bring secrets to org level, and maybe team level... there is no info if they will create sort of contexts like we have in CCI.

I have thought on adding the env as prefix of the secret name like STAGE_GITHUB_KEY or INTEGRATION_GITHUB_KEY using ${env}_GITHUB_KEY on the yml as a workaround for now... What do you think?

--- Original answer: If I understand you well, you already have the dotenv files stored somewhere and you want to inject all those secrets into the steps, without having to manually add them to github secrets and do the mapping in each workflow you migrate... right?

There is an action made by someone that reads a dotenv file and put its values into ouputs, so you can use them linked in further steps. Here is the link: https://github.com/marketplace/actions/dotenv-action

Whatever is present in the .env file will be converted into an output variable. For example .env file with content:

VERSION=1.0
AUTHOR=Mickey Mouse

You do:

id: dotenv
uses: ./.github/actions/dotenv-action

Then later you can refer to the alpine version like this ${{ steps.dotenv.outputs.version }}

这篇关于如何在GitHub Actions中使用env文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆