如何在JS文件中使用Github机密 [英] How can I use Github secrets in JS files

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

问题描述

我有一个基本的git存储库,其中设置了github动作来构建和部署(主要是HTML和TS文件).

I have a basic git repo set up with github actions to build and deploy (HTML and TS files mainly).

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

However I have to use in some API Keys that needs to be secret.

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

So I figure out to use GITHUB SECRETS for them.

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

How can I access GITHUB SECRETS in my js (or TS) files so it can build with github actions properly?

推荐答案

您可以将Secrets作为ENV变量传递.

You can pass-in Secrets as ENV variables.

示例:

   ...
   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访问它.

In Node.js you can access it via process.env.API_KEY.

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

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