gpt4 book ai didi

javascript - 如何在 JS 文件中使用 Github secret

转载 作者:行者123 更新时间:2023-12-03 06:56:28 29 4
gpt4 key购买 nike

我有一个基本的 git repo 设置了 github 操作来构建和部署(主要是 HTML 和 TS 文件)。

但是我必须在一些需要保密的 API key 中使用。

所以我想为他们使用 GITHUB SECRETS。

如何在我的 js(或 TS)文件中访问 GITHUB SECRETS,以便它可以使用 github 操作正确构建?

最佳答案

您可以将 Secrets 作为 ENV 变量传入。

示例:

   ...
steps:
- name: Git checkout
uses: actions/checkout@v2

- name: Use Node 12.x
uses: actions/setup-node@v1
with:
node-version: 12.x

- name: Install Dependencies (prod)
run: yarn install --frozen-lockfile --production

- name: Run Tests (JEST)
run: yarn test --ci --silent --testPathIgnorePatterns=experimental
env:
CI: true
API_KEY: ${{ secrets.API_KEY }}

在 Node.js 中,您可以通过 process.env.API_KEY 访问它.

关于javascript - 如何在 JS 文件中使用 Github secret ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59686823/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com