我正在尝试使用GitHub Actions为Node.js项目运行构建。作为npm install
的一部分,我需要直接从私有GitHub存储库中安装npm模块(而不是从GPR!)。
在package.json
中,我有:
"dependencies": {
...
"my-module": "github:<org>/<my-module>#master",
...
},
但是,在运行npm install
时,我得到了:
npm ERR! git@github.com:权限被拒绝(公钥)。 npm ERR!致命:无法从远程存储库读取。
该存储库是我自己的组织的一部分,并且在本地(即从我的计算机中)运行。我该如何运行?
我已经尝试设置NODE_AUTH_TOKEN
环境变量,但是没有任何区别。尽管您经常发现此建议,但它似乎仅解决了GPR。我要避免的是必须将令牌硬编码到package.json
文件中。有什么想法吗?
答案 0 :(得分:6)
这就是我设法从私有GitHub存储库安装依赖项的方式。
package.json中的依赖项可以如下添加。 github:
前缀是可选的。指定#branch
或#tag
也是可选的。
"dependencies": {
...
"myrepo": "username/myrepo#master",
"myotherrepo": "github:username/myotherrepo"
},
这是示例工作流程。 PAT
是repo
范围内的Personal Access Token。禁用actions/checkout
上的持久凭证很重要,否则它们将覆盖您的PAT
。请注意,git config
更改在步骤之间仍然存在,因此每个作业只需运行一次。
- uses: actions/checkout@v2
with:
persist-credentials: false
- uses: actions/setup-node@v1
with:
node-version: 12.x
- run: git config --global url."https://${{ secrets.PAT }}@github.com/".insteadOf ssh://git@github.com/
- run: npm ci
...
答案 1 :(得分:0)
从错误和包含依赖项的方式(在package.json中)看来,您没有通过身份验证凭据(令牌,ssh。
的详细信息,请参阅此文档。可以通过https和oauth或ssh完成。
https和oauth :具有“回购”范围的create an access token,然后是use this syntax:
import pandas as df
df=pd.read_csv('F:/Wells FargoZinitra.txt', 'r')
print(df)
或
ssh :设置ssh,然后使用以下语法:
"package-name": "git+https://<github_token>:x-oauth-basic@github.com/<user>/<repo>.git"
答案 2 :(得分:-1)
您应该编辑.npmrc
文件。
您也可以使用npm config
npm config set @myco:registry http://reg.example.com
有关更多信息,请参见以下线程: Is there any way to configure multiple registries in a single npmrc file