我正在开发一个涉及多个 API 密钥的 Node 项目。我将 API 密钥存储在配置文件config.js中。然后我添加config.js了,.gitignore这样 API 密钥就不会在公共存储库中显示。但是当我尝试npm run build使用 GitHub 操作时,会出现导入错误,因为config.js它不在存储库中。
我可以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 相当陌生。提前致谢!
更新:我使用下面接受的答案解决了这个问题。我存储在GitHub 上config.js的一个秘密变量中。config然后,我在config.js需要之前创建的工作流程中添加了一个步骤:
...
- name: create config.js
run: echo '${{ secrets.config }}' > path/to/config.js
- name: npm install, build, and test
...