【问题标题】:Install private github package from package.json on Github Actions在 Github Actions 上从 package.json 安装私有 github 包
【发布时间】:2019-05-05 22:43:21
【问题描述】:

我正在尝试在我的项目中将 Github 操作作为 CI 实施。问题是我在 package.json 上使用了私有 git URL,但 CI 出现错误,因为 Github 操作“不知何故”无法访问该存储库,这是不可能的,因为它位于同一用户帐户上。

有人知道如何解决这个问题吗?

ma​​in.workflow 文件:

workflow "Github Actions" {
  on = "pull_request"
  resolves = ["Danger JS"]
}

action "Build" { <-------- This gets error
  uses = "actions/npm@master"
  args = "install"
}

action "Linter" {
  uses = "actions/npm@master"
  needs = "Build"
  runs = "lint"
}

action "Test" {
  needs = "Linter"
  uses = "actions/npm@master"
  args = "test"
}

action "Danger JS" {
  uses = "danger/danger-js@master"
  needs = ["Test"]
  secrets = ["DANGERJS_TOKEN"]
}

错误日志:

Successfully built xxxxxxxxxxxxx
Successfully tagged gcr.io/xxxxxxxxxxxxx
Pulling image: gcr.io/github-actions-development/action-runner:latest
latest: Pulling from github-actions-development/action-runner
xxxxxxxxxxxxx: Pulling fs layer
xxxxxxxxxxxxx: Verifying Checksum
xxxxxxxxxxxxx: Download complete
xxxxxxxxxxxxx: Pull complete
Digest: sha256:xxxxxxxxxxxxx
Status: Downloaded newer image for gcr.io/github-actions-development/action-runner:latest
npm ERR! code ENOGIT
npm ERR! Error while executing:
This package is on same user account but github actions doesn't have access anyhow ------> npm ERR! undefined ls-remote -h -t ssh://git@github.com/test-user/react-test-package.git 
npm ERR! 
npm ERR! undefined
npm ERR! No git binary found in $PATH
npm ERR! 
npm ERR! Failed using git.
npm ERR! Please check if you have git installed and in your PATH.

npm ERR! A complete log of this run can be found in:
npm ERR!     /github/home/.npm/_logs/2018-12-04T13_03_05_291Z-debug.log

### FAILED Build

【问题讨论】:

  • 在运行时容器内是否没有可访问的 git 可执行文件?从 npm ERR 看来是这样!在 $PATH 中找不到 git 二进制文件
  • 是的,我也在考虑这个问题,我检查了它。如果我将该回购公开,那么它可以工作:)
  • 尝试将secrets = ["GITHUB_TOKEN"] 添加到您的Build 步骤中。

标签: docker github npm continuous-integration github-actions


【解决方案1】:

您可以将具有注册表读取权限的 authToken 放入运行 npm install 的存储库中的 .npmrc

例子:

//npm.pkg.github.com/:_authToken=**************
@youraccount:registry=https://npm.pkg.github.com

【讨论】:

  • 虽然这确实有效,但暴露我们的 authToken 不是很糟糕吗?因为这是在包存储库本身中?
【解决方案2】:

现在有一个专门的操作来自动设置 nodejs,它被称为actions/setup-node

这里是一个例子:

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
  with:
    node-version: '10.x'
    registry-url: 'https://registry.npmjs.org'
- run: npm install
  env:
    NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

它会创建一个本地 .npmrc 文件,该文件使用环境变量来获取身份验证令牌:

//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}
@youraccount:registry=https://registry.npmjs.org

您可以使用 if 来定位任何私有注册表,例如 GitHub 包

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-25
    • 2019-10-29
    • 2021-11-24
    • 2021-10-23
    • 2020-04-06
    • 1970-01-01
    • 2021-12-15
    • 2022-11-04
    相关资源
    最近更新 更多