如何在Github Action中使用yarn安装私有软件包?

时间:2019-10-17 10:15:57

标签: github npm yarnpkg github-actions

我当前的工作流程:

name: Node CI

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [10.x]

    steps:
      - uses: actions/checkout@v1
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node-version }}
      - name: npm install, build, and test
        run: |
          npm install yarn -g
          yarn
          yarn test
        env:
          CI: true
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

我已在回购秘密区域中设置了NPM_TOKEN

该令牌还在Netlify上使用,并且netlify构建过程正常工作。

运行此工作流程时,我的任何私有软件包都收到404。

我在做什么错了?

3 个答案:

答案 0 :(得分:3)

找到了解决方法:

在工作中写出.npmrc而不是依赖env变量。

name: Node CI

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [10.x]

    steps:
      - uses: actions/checkout@v1
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node-version }}
      - name: npm install, build, and test
        run: |
          echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc
          npm install yarn -g
          yarn
          yarn test
        env:
          CI: true

答案 1 :(得分:0)

我认为以下问题/答案可能与之相关。

Yarn can't find private Github npm registry

如果这是相同的问题,则npm注册表中的程序包代理还不适用于yarn。

答案 2 :(得分:0)

如果您有一个现有的 .npmrc 并且只想将令牌附加到现有文件中而不是覆盖它,这对我有用。

*** 注意:echo 包含一个 -e 参数和一个 \n 以添加换行符。此外,不是覆盖 > 文件的 .npmrc,而是附加到 >> 文件的 .npmrc

      - name: npm install, build, and test
        run: |
          echo -e "\n//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" >> .npmrc
          npm install yarn
          yarn
          yarn test
        env:
          CI: true
相关问题