4

已经有很多类似的问题在流传:

但是,我们的问题似乎不同,因为:

  • yarn install在本地机器上运行良好
  • 问题仅在使用 Github Actions 时出现
  • yarn install 如果我们删除,则在 GH Actions 上成功yarn.lock

有没有人遇到过这个?特别是它不适用于yarn.lock文件?

万一这很重要,这是设置:

build.yml

    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-node@v1
      with:
        node-version: '10.x'
        registry-url: 'https://npm.pkg.github.com'
    - name: Install
      run: yarn install
      env:
        # GITHUB_TOKEN can't access packages hosted in private repos,
        # even within the same organisation
        NODE_AUTH_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
    - name: Build
      run: yarn build
    - name: Test
      run: yarn test --forbid-only

我们还有一个.npmrc用于本地安装的文件:

@<org>:registry=https://npm.pkg.github.com

但是没有 .yarnrc文件。

4

2 回答 2

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

将 @you-scope 替换为您的 github 用户或您在 github 中的组织的LowerCase

为此存储库创建一个 PACKAGES_TOKEN 秘密令牌,用于访问您的 github 访问权限。

于 2021-05-11T00:38:50.877 回答
0

我们设法通过在配置中显式复制.npmrc配置来解决这个问题build.yml

      - uses: actions/setup-node@v1
        with:
          node-version: '10.x'
          registry-url: 'https://npm.pkg.github.com'
          # These following two lines are the key:
          always-auth: true
          scope: '@reedsy'
于 2020-09-23T12:56:01.557 回答