[英]How to import private data with GitHub actions?
I'm working on a Node project involving several API keys.我正在处理一个涉及多个 API 密钥的 Node 项目。 I stored the API keys in a configuration file
config.js
.我将 API 密钥存储在配置文件
config.js
。 Then I added config.js
to .gitignore
so that the API keys aren't revealed in the public repository.然后我将
config.js
添加到.gitignore
以便 API 密钥不会在公共存储库中显示。 But when I try to npm run build
with GitHub actions, there's an import error because config.js
isn't in the repository.但是当我尝试使用 GitHub 操作
npm run build
时,出现导入错误,因为config.js
不在存储库中。
Can I "simulate" config.js
somehow on GitHub?我可以在 GitHub 上以某种方式“模拟”
config.js
吗? Or should I setup an action to download config.js
from elsewhere?或者我应该设置一个操作来从其他地方下载
config.js
吗? Is there a better approach?有没有更好的方法?
I'm using GitHub's boilerplate nodejs.yml
:我正在使用 GitHub 的样板文件
nodejs.yml
:
name: Node CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [8.x, 10.x, 12.x]
steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: npm install, build, and test
run: |
npm install
npm run build --if-present
env:
CI: true
I'm fairly new to CI/CD.我对 CI/CD 相当陌生。 Thanks in advance!
提前致谢!
UPDATE: I solved this problem using the accepted answer below.更新:我使用下面接受的答案解决了这个问题。 I stored
config.js
in a secret variable config
on GitHub.我将
config.js
存储在 GitHub 上的一个秘密变量config
中。 Then I added a step in the workflow that creates config.js
before it's needed:然后我在工作流中添加了一个步骤,在需要之前创建
config.js
:
...
- name: create config.js
run: echo '${{ secrets.config }}' > path/to/config.js
- name: npm install, build, and test
...
You could declare your key as a secret in GitHub Actions under the name you want (for instance ' my_secret_key
')您可以在 GitHub Actions中以您想要的名称(例如“
my_secret_key
”)将您的密钥声明为秘密
See also " Creating and using secrets (encrypted variables) "另请参阅“ 创建和使用机密(加密变量) ”
Said key can be referenced in your config.js
as a variable $my_secret_key
.所述密钥可以在您的
config.js
作为变量$my_secret_key
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.