如何使用 GitHub 操作导入私人数据?
How to import private data with GitHub actions?
我正在处理一个涉及多个 API 键的 Node 项目。我将 API 密钥存储在配置文件 config.js
中。然后我将 config.js
添加到 .gitignore
以便 API 键不会在 public 存储库中显示。但是当我尝试使用 GitHub 操作 npm run build
时,出现导入错误,因为 config.js
不在存储库中。
我可以 "simulate" config.js
以某种方式在 GitHub 上吗?或者我应该设置一个从其他地方下载 config.js
的动作吗?有更好的方法吗?
我正在使用 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
我是 CI/CD 的新手。提前致谢!
更新:我使用下面接受的答案解决了这个问题。我将 config.js
存储在 GitHub 上的秘密变量 config
中。然后我在工作流程中添加了一个步骤,在需要之前创建 config.js
:
...
- name: create config.js
run: echo '${{ secrets.config }}' > path/to/config.js
- name: npm install, build, and test
...
您可以将您的密钥声明为您想要的名称下的 secret in GitHub Actions(例如“my_secret_key
”)
另见“Creating and using secrets (encrypted variables)”
所述键可以在您的 config.js
中作为变量引用 $my_secret_key
。
我正在处理一个涉及多个 API 键的 Node 项目。我将 API 密钥存储在配置文件 config.js
中。然后我将 config.js
添加到 .gitignore
以便 API 键不会在 public 存储库中显示。但是当我尝试使用 GitHub 操作 npm run build
时,出现导入错误,因为 config.js
不在存储库中。
我可以 "simulate" config.js
以某种方式在 GitHub 上吗?或者我应该设置一个从其他地方下载 config.js
的动作吗?有更好的方法吗?
我正在使用 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
我是 CI/CD 的新手。提前致谢!
更新:我使用下面接受的答案解决了这个问题。我将 config.js
存储在 GitHub 上的秘密变量 config
中。然后我在工作流程中添加了一个步骤,在需要之前创建 config.js
:
...
- name: create config.js
run: echo '${{ secrets.config }}' > path/to/config.js
- name: npm install, build, and test
...
您可以将您的密钥声明为您想要的名称下的 secret in GitHub Actions(例如“my_secret_key
”)
另见“Creating and using secrets (encrypted variables)”
所述键可以在您的 config.js
中作为变量引用 $my_secret_key
。