GITHUB_TOKEN 403禁止发布nuget包到GitHub包



我按照这些资源设置了一个GitHub Actions工作流来构建、测试和发布一个dotnet库到GitHub包:

  • 使用NuGet注册表
  • 使用GitHub Actions的NuGet包工作流
  • 发布NuGet包到GitHub Packages

这些文章确实很有帮助,但是我遇到了一个他们都没有讨论的问题:

推动MagicLibrary.0.1.3。Nupkg到'https://nuget.pkg.github.com/vivere-dally'…将https://nuget.pkg.github.com/vivere-dally/你的请求无法通过GitHub Packages服务进行身份验证。请确保您的访问令牌是有效的,并配置了适当的范围。禁止https://nuget.pkg.github.com/vivere-dally/218mserror: Response status code does not indicate success: 403 (Forbidden).

这是我的工作流文件:
# 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

为什么GITHUB_TOKEN没有权限?

默认情况下,GITHUB_TOKEN不包含发布包所需的权限。将以下内容添加到您的作业中:

permissions:
packages: write

看到https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-nuget-registry authenticating-in-a-github-actions-workflow

和https://docs.github.com/en/actions/security-guides/automatic-token-authentication using-the-github_token-in-a-workflow

相关内容

  • 没有找到相关文章

最新更新