访问本地env文件中的github秘密

发布于 2025-01-28 05:47:43 字数 105 浏览 3 评论 0原文

有没有办法在本地env文件中访问github秘密?因此,而不是直接保存在env文件中,而是引用github秘密。我已经看到,github秘密可以在工作流程中使用,但我主要需要在env文件中具有值。

Is there a way to access GitHub secrets in a local env file? So instead of having a secret saved directly in the env file it would reference a GitHub secret. I've seen that the GitHub secrets can be used within a workflow but I mainly just need to have the values in the env file.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鹤仙姿 2025-02-04 05:47:43

我认为您可能会混淆事情。

本地env文件无法访问变量,而是您的代码读取ENV文件并使用这些变量。

如果您使用 dotenv ,此工具将读取您的Env文件,并在定义的情况下覆盖它们变量直接在环境上。

您可以使用将您的github秘密作为env变量导出的动作工作流程(披露:我是作者),因此最后一部分(替代)只能使用。

一个示例是:

- run: echo "Value of MY_SECRET1: $MY_SECRET1"
  env:
    MY_SECRET1: ${{ secrets.MY_SECRET1 }}
    MY_SECRET2: ${{ secrets.MY_SECRET2 }}
    MY_SECRET3: ${{ secrets.MY_SECRET3 }}
    MY_SECRET4: ${{ secrets.MY_SECRET4 }}
    MY_SECRET5: ${{ secrets.MY_SECRET5 }}
    MY_SECRET6: ${{ secrets.MY_SECRET6 }}
    ...

您可以将其转换为:

- uses: oNaiPs/secrets-to-env-action@v1
  with:
    secrets: ${{ toJSON(secrets) }}
- run: echo "Value of MY_SECRET1: $MY_SECRET1"

链接到该操作,其中包含有关配置的更多文档: https://github.com/onaips/secrets-to-env-action

请参阅此相关的

I think you might be confusing things.

A local env file does not access variables, instead, your code reads the env file and uses those variables.

If you use something like dotenv, this tool will read your env files, and optionally override them if you defined the variables directly on the environment.

You can use an action workflow (disclosure: i'm the author) that exports your github secrets as env variables, so last part (overrides) would just work.

An example would be:

- run: echo "Value of MY_SECRET1: $MY_SECRET1"
  env:
    MY_SECRET1: ${{ secrets.MY_SECRET1 }}
    MY_SECRET2: ${{ secrets.MY_SECRET2 }}
    MY_SECRET3: ${{ secrets.MY_SECRET3 }}
    MY_SECRET4: ${{ secrets.MY_SECRET4 }}
    MY_SECRET5: ${{ secrets.MY_SECRET5 }}
    MY_SECRET6: ${{ secrets.MY_SECRET6 }}
    ...

You could convert it to:

- uses: oNaiPs/secrets-to-env-action@v1
  with:
    secrets: ${{ toJSON(secrets) }}
- run: echo "Value of MY_SECRET1: $MY_SECRET1"

Link to the action, which contains more documentation about configuration: https://github.com/oNaiPs/secrets-to-env-action

See this related SO post.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文