javascript - 如何在 JS 文件中使用 Github 机密
问题描述
我有一个基本的 git repo 设置了 github 操作来构建和部署(主要是 HTML 和 TS 文件)。
但是我必须在一些需要保密的 API 密钥中使用。
所以我想为他们使用 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
.
推荐阅读
- java - JVM“奇怪”行为
- c++ - 有没有更好的方法在循环中只运行一次动作?
- android - React-Native:我退出我的应用程序后,messaging().onNotificationOpenedApp 没有调用
- android - 如何在android中动态添加edittext?
- xamarin.forms - 列表视图中的 Xamarin 表单滑动视图不起作用
- javascript - 在 Google Apps 脚本中使用 oAuth 2.0
- python - 如何从 libfreenect2 中保存 rgb 和深度数据?
- javascript - 将视频编解码器转换为 vp9 到 mp4?
- javascript - 当你选择它并保存到数据库时如何锁定颜色,这是刷新页面时选择的颜色消失了
- reactjs - 为什么我看不到 currentUser 使用带有 react native 的 firebase?