简体   繁体   中英

GITHUB_TOKEN 403 forbidden when publishing a nuget package to GitHub packages

I followed these resources to setup a GitHub Actions workflow to build, test, and publish a do.net library to GitHub packages:

These articles were really helpful, however I ran into a problem that none of them discussed:

Pushing MagicLibrary.0.1.3.nupkg to 'https://nuget.pkg.github.com/vivere-dally'... PUT https://nuget.pkg.github.com/vivere-dally/ warn: Your request could not be authenticated by the GitHub Packages service. Please ensure your access token is valid and has the appropriate scopes configured. Forbidden https://nuget.pkg.github.com/vivere-dally/ 218ms error: Response status code does not indicate success: 403 (Forbidden).

This is my workflow file:

# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net

name: Release

on:
  push:
    tags:
    - "v[0-9]+.[0-9]+.[0-9]+"

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3

    - name: Verify commit exists in origin/main
      run: |
        git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/*
        git branch --remote --contains | grep origin/main
    
    - name: Set VERSION env var from tag
      run: echo "VERSION=${GITHUB_REF/refs\/tags\/v/}" >> $GITHUB_ENV
    

    - name: Setup .NET
      uses: actions/setup-dotnet@v3
      with:
        dotnet-version: 6.0.x

    - name: Restore dependencies
      run: dotnet restore
      working-directory: ./MagicLibrary

    - name: Build
      run: dotnet build --configuration Release /p:Version=${VERSION} --no-restore
      working-directory: ./MagicLibrary

    - name: Test
      run: dotnet test --configuration Release /p:Version=${VERSION} --no-build --verbosity normal
      working-directory: ./MagicLibrary

    - name: Pack
      run: dotnet pack --configuration Release /p:Version=${VERSION} --no-build --output .
      working-directory: ./MagicLibrary

    - name: Push
      run: dotnet nuget push MagicLibrary.${VERSION}.nupkg --source "https://nuget.pkg.github.com/vivere-dally/index.json" --api-key ${{ secrets.GITHUB_TOKEN }}
      working-directory: ./MagicLibrary

Why does the GITHUB_TOKEN not have the required permissions?

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