简体   繁体   中英

how to access a private npm package via github actions?

I think this is a pretty straightforward question. Still, I'm finding lots of different resources suggesting going down different paths, installing different things, and generally speaking, so far everything seems all over the place.

In my case, I made a private package on npm. I'm trying to do a basic on push to main > run ci and build github action. However, I have my own custom private npm package, part of an org I made on npm. When the pipeline triggers I get the following response:

在此处输入图像描述

The current node.js.yml file looks like so:

name: Node.js CI

env:
  NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

on:
  push:
    branches: ['main']
  pull_request:
    branches: ['main']

jobs:
  build:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [14.x]
        # See supported Node.js release schedule at https://nodejs.org/en/about/releases/

    steps:
      - uses: actions/checkout@v3
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node-version }}
          cache: 'npm'
      - run: echo "Running pipeline."
      - run: npm ci
      - run: npm run build --if-present
      - run: npm test

There's not enough information in it yet, other than a read-only key provide (per npm docs), but I don't know if that's a step in the right direction or if I need to do something entirely different. As I said, I'm not too familiar with this space and any help would be appreciated.

结果我需要添加一个.npmrc文件,其中 NPM_TOKEN 作为 github 机密。

//registry.npmjs.org/:_authToken=${NPM_TOKEN}

You have to create an .npmrc file with proper authToken .

Add your authToken to your GitHub Environemnt Secrets (for example as: NPM_TOKEN ) and then use to create a file using bash script for example:

- name: "Create .npmrc"
  run: |
    echo "//npm.pkg.github.com/:_authToken=${{ secrets.NPM_TOKEN }}" > .npmrc
    echo "@raycast:registry=https://npm.pkg.github.com" >> .npmrc

Then you can call npm install .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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