簡體   English   中英

登錄MyGet for GitHub Actions 安裝私有包

[英]Logging in to MyGet for GitHub Actions to install Private package

我正在嘗試設置一個 GitHub 操作工作流,該工作流將在創建 PR 時運行項目的測試。 這是操作的 YAML; 這真的很簡單。

steps:
    - uses: actions/checkout@v1

    - name: Use Node.js
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}
        registry-url: https://www.myget.org/F/hsa/npm/
        scope: '@hsa'
      env:
        NODE_AUTH_TOKEN: ${{ secrets.MYGET_TOKEN }}

    - name: set always auth
      run: |
        npm config set always-auth true

    - name: Install
      run: |
        npm install

    - name: Run lint
      shell: bash
      run: |
        if [[ $GITHUB_BASE_REF ]]
        then
            export NX_BASE=remotes/origin/$GITHUB_BASE_REF
        else
            export NX_BASE=$(git rev-parse HEAD~1)
        fi
        echo "Base => $NX_BASE"
        npm run affected:test -- --base=$NX_BASE

“使用 Node.js”步驟為@hsa范圍設置注冊表 URL; MYGET_TOKEN是使用 repo 的秘密設置的。 “set always auth”步驟是必要的,因為它不是自動完成的。 這似乎足以允許操作安裝私有包,但它不起作用。 這是我在“安裝”步驟中遇到的錯誤:

npm ERR! code E401
npm ERR! Unable to authenticate, need: Basic realm="MyGet - hsa"

我已經輸出了在 Action 中創建的臨時.npmrc文件,它看起來確實正確,為給定范圍設置了注冊表,所以一切都應該正常工作。 但是我無法通過 NPM 安裝步驟來實際運行測試。

對我在身份驗證中缺少的任何幫助將不勝感激。 謝謝!

來自https://github.com/actions/setup-node/

steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
  with:
    node-version: '10.x'
    registry-url: 'https://registry.npmjs.org'
# Skip post-install scripts here, as a malicious
# script could steal NODE_AUTH_TOKEN.
- run: npm install --ignore-scripts
  env:
    NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# `npm rebuild` will run all those post-install scripts for us.
- run: npm rebuild && npm run prepare --if-present

嘗試在 actions/setup-node 中使用 npm install。

這是我最終使用的用於安裝私有包的工作流配置文件:

name: Nx Affected CI

on:
  push:
    branches: [master]
  pull_request:
    branches: [master]

jobs:
  build:
    runs-on: ubuntu-latest

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

    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node-version }}
      - run: git fetch origin master
      - run: cp npmrc_file .npmrc
      - name: npm install
        run: npm install
        env:
          NPM_TOKEN: ${{ secrets.MYGET_TOKEN }}
      - run: rm .npmrc
      - run: npm run affected:test --base=origin/master

npmrc_file應如下所示:

@hsa:registry=https://www.myget.org/path/to/repository
always-auth=true
//www.myget.org/path/to/repository/:_authToken=${NPM_TOKEN}

我將它復制到工作流中,安裝了私有包,然后將其刪除,因為它在嘗試運行npm run命令時會導致NPM_TOKEN出現問題。

此外, MYGET_TOKEN存儲在存儲庫設置的 secrets 部分。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM