npm发布包到 github packages 的精简配置

172 阅读1分钟

通过GitHub Action 可以将包发布(npm publish)到 GitHub Packages 并将存储在 GitHub Packages 上的包用作 npm 项目中的依赖项,详细Action的yml文件如下:


jobs:
  deploy:
    name: Deploy
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [17.x]
      
    steps:          
    - name: Checkout
      uses: actions/checkout@v3
      
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v3
      with:
        node-version: ${{ matrix.node-version }}
        registry-url: https://npm.pkg.github.com/
 
    - run: npm install 
    - run: npm run build --if-present 
    - name: npm publish
      run: |
          npm publish
      env:
          NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}