由于各种原因,我们被困在使用纱线管理程序包,因此我们不能依靠package-lock.json将npm与github操作一起使用。
我们无法让Yarn作为github动作的一部分进行身份验证。 我们已经将仓库npmrc配置为:
checkedItems:CheckBoxListItem[] = [];
我们正在使用this action for yarn.
这是一个基本设置,我们只是在尝试安装模块-仅此而已。
@COMPANY:registry=https://npm.pkg.github.com
registry=https://registry.npmjs.org/
默认情况下,此操作将尝试运行install,以便绕过我在“版本”中提供的基本命令,因此它仅显示yarn版本,仅此而已。
运行yarn安装将对所有其他软件包都有效,但是当它进入我们的私有模块时,它将尝试从正确的注册表(github)中获取它们,但会被401击中。
完整错误:
name: CI
on: [push]
jobs:
build:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: borales/actions-yarn@v2.1.0
with:
auth-token: ${{ secrets.GITHUB_TOKEN }}
registry-url: "https://npm.pkg.github.com"
scope: tlabs
cmd: version
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_REGISTRY_URL: https://npm.pkg.github.com
- name: Create NPMRC
run: |
echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" > ~/.npmrc
- name: Install
run: |
yarn install --verbose
答案 0 :(得分:3)
默认GITHUB_TOKEN
仅适用于当前存储库。您不能使用它来访问另一个存储库中的软件包。使用read:packages
和repo
范围内的Personal Access Token代替GITHUB_TOKEN
。
答案 1 :(得分:1)
我正在创建一个文件 .npmrc 和 .yarnrc。 类型:
name: Test
on: push
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
steps:
- uses: actions/checkout@v2
- name: Node ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Create NPMRC
run: |
echo "//npm.pkg.github.com/:_authToken=${{ secrets.PACKAGES_TOKEN }}" >> ~/.npmrc
echo "@you-scope:registry=https://npm.pkg.github.com" >> ~/.npmrc
echo 'registry "https://registry.yarnpkg.com"' >> ~/.yarnrc
- run: yarn install
在LowerCase 中为您的 github 用户或您在 github 中的组织替换 @you-scope。 为此存储库创建一个 PACKAGES_TOKEN screte。
答案 2 :(得分:0)
在项目的根目录中有一个 .npmrc 文件。
.npmrc 的内容:
registry=https://registry.npmjs.org/
@{scope}:registry=https://npm.pkg.github.com/
//npm.pkg.github.com/:_authToken=********** (Token generated from github)
@{scope}
是您的组织名称或用户名。它区分大小写。
此外,要访问 github 注册表中的私有和公共包,您需要有一个令牌。
参考:You need an access token to publish, install, and delete packages.