简体   繁体   English

可访问私有仓库的 GitHub 操作

[英]GitHub action with access to private repo

I would like to run the CI part of my Node / Ionic project where I just yesterday added a custom capacitor plugin - repo A.我想运行我的 Node / Ionic 项目的 CI 部分,我昨天刚刚在其中添加了一个自定义电容器插件 - repo A。

This plugin sits in repo B.这个插件位于 repo B 中。

On my dev machine I added B as在我的开发机器上,我将 B 添加为

npm install https://PERSONAL_ACCESS_TOKEN@github.com/ME/B.git --save

to project A.到项目 A。

package.json now contains package.json现在包含

"B": "git+https://PERSONAL_ACCESS_TOKEN@github.com/ME/B.git",

and I pushed this to my current merge request.我把它推送到我当前的合并请求中。 However, the CI pipeline is telling me now:但是,CI 管道现在告诉我:

  npm install
  shell: /usr/bin/bash -e {0}
npm ERR! Error while executing:
npm ERR! /usr/bin/git ls-remote -h -t https://***@github.com/ME/B.git
npm ERR! 
npm ERR! remote: Repository not found.
npm ERR! fatal: repository 'https://github.com/ME/B.git/' not found
npm ERR! 

Project B is a private repo.项目 B 是一个私人仓库。 My account owns both repos and I am using my newly created Personal Access Token.我的帐户拥有两个存储库,并且我正在使用我新创建的个人访问令牌。

What should I check?我应该检查什么? I can pull the repo on my local, but there I am setup with my git+ssh env credentials too, so it might work just because of that...我可以在本地提取 repo,但是我也使用我的 git+ssh env 凭据进行了设置,因此它可能正因为如此......

Check first if you need your GitHub username:首先检查您是否需要您的 GitHub 用户名:

 https://myGitHubUsername:PERSONAL_ACCESS_TOKEN@github.com/ME/B.git
         ^^^^^^^^^^^^^^^^^

Then, if you need the token in the git+https URL:然后,如果您需要git+https URL 中的令牌:

" How to use private GitHub repo as npm dependency " mentions the use of npm-cli-login instead: 如何使用私有 GitHub 存储库作为 npm 依赖项”提到使用npm-cli-login代替:

- name: Login to GitHub private NPM registry
  env:
    CI_ACCESS_TOKEN: ${{ secrets.NAME_OF_YOUR_ACCESS_TOKEN_SECRET }}
  shell: bash
  run: |
    npm install -g npm-cli-login
    npm-cli-login -u "USERNAME" -p "${CI_ACCESS_TOKEN}" -e "EMAIL" -r "https://npm.pkg.github.com" -s "@SCOPE"

Most answers that I have seen to install private GitHub repo我见过的大多数安装私有 GitHub 存储库的答案

"package": "git+https://PERSONAL_ACCESS_TOKEN:x-oauth-basic@github.com/username/packge.git"

or或者

"package": "https://PERSONAL_ACCESS_TOKEN:x-oauth-basic@github.com/username/packge.git"

This works in local, however, if you are using actions/checkout@v2 in your github Action then you need to use persist-credentials:false like the following.这适用于本地,但是,如果您在 github Action 中使用actions/checkout@v2 ,则需要使用persist-credentials:false ,如下所示。

- uses: actions/checkout@v2
  with:
    persist-credentials: false

otherwise, you'll get an error message remote: Repository not found.否则,您将收到一条错误消息remote: Repository not found.

other ways to install private github repo其他安装私有 github 仓库的方法

if you are using ssh like following如果您使用ssh如下

"package": "git+ssh://git@github.com/username/packge.git"

then you have to use the ssh-agent in your github action like this然后你必须像这样在你的 github 操作中使用 ssh-agent

- uses: webfactory/ssh-agent@v0.5.4
  with:
      ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}

here SSH_PRIVATE_KEY is a private key from public-private key pair generated using ssh-keygen and the public key is added as a deploy key in the private repo that you are trying to install as an npm package.这里SSH_PRIVATE_KEY是来自使用ssh-keygen生成的公钥-私钥对的私钥,公钥作为部署密钥添加到您尝试作为 npm 包安装的私有 repo 中。 for more information about this, you can check the official doc有关这方面的更多信息,您可以查看官方文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM