推送到 git 包失败并显示有效的 GITHUB_TOKEN

use*_*204 3 github nuget github-actions github-package-registry github-packages

充分研究了有关将包推送到 Git 的 github 文档。我正在使用的讲师的代码中满足了文档中的所有要点。

寻找错别字等。

这是课程 YAML,它与讲师版本完全比较:

name: Push to GitHub Packages

on:
  push:
  workflow_dispatch:

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: Setup .NET
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 5.0.x
    - name: Restore dependencies
      run: dotnet restore
    - name: Build
      run: dotnet build --configuration Release --no-restore 

    - name: Pack
      run: dotnet pack --configuration Release --no-build --output .
      
    - name: Push
      run: |
        dotnet nuget add source --username *** --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/***/index.json"
        dotnet nuget push ./*.nupkg --skip-duplicate --source "github" --api-key ${GITHUB_TOKEN}
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Run Code Online (Sandbox Code Playgroud)

这是我将包推送到 Git 时遇到的错误,敏感信息已被编辑。作业运行的 Push 部分显示包已成功添加。

我正在使用GITHUB_TOKEN有效的组织/用户名。

Run dotnet nuget add source --username *** -*** --store-password-in-clear-text --name github "https://nuget.pkg.github.com/***/index.json"
  dotnet nuget add source --username *** -*** --store-password-in-clear-text --name github "https://nuget.pkg.github.com/***/index.json"
  dotnet nuget push ./*.nupkg --skip-duplicate --source "github" --api-key ${GITHUB_TOKEN}
  shell: /usr/bin/bash -e {0}
  env:
    DOTNET_ROOT: /home/runner/.dotnet
    GITHUB_TOKEN: ***
Package source with Name: github added successfully.
Pushing MyCoolClassLibrary.1.0.1.nupkg to 'https://nuget.pkg.github.com/***'...
  PUT https://nuget.pkg.github.com/***/
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/***/ 224ms
error: Response status code does not indicate success: 403 (Forbidden).
Run Code Online (Sandbox Code Playgroud)

正如老话所说,这不是火箭科学,但它确实有一些移动部件。

这段代码已经被解析过很多次了。我一定错过了一些东西,只是不明白那是什么。

jes*_*ing 7

首先,添加一个

\n
permissions:\n  packages: write\n  contents: read\n
Run Code Online (Sandbox Code Playgroud)\n

看:

\n\n

您的存储库的默认值可能设置为只读(存储库 - \xe2\x9a\x99\xef\xb8\x8f 设置 - \xe2\x96\xb6\xef\xb8\x8f 操作 - 常规):

\n

在此输入图像描述

\n

并确保将包链接到存储库

\n
\n

如果您使用 GitHub Actions 工作流来管理包,则可以使用包设置中“管理操作访问权限”下的“添加存储库”按钮向存储工作流的存储库授予访问角色。有关详细信息,请参阅“配置包的访问控制和可见性”。

\n
\n
\n

在包的登陆页面的右侧,单击 \xe2\x9a\x99\xef\xb8\x8f 包设置。

\n

在此输入图像描述

\n

为了确保您的工作流程可以访问您的包,您必须添加存储工作流程的存储库。在“管理操作访问权限”下,单击Add repository并搜索要添加的存储库。

\n

在此输入图像描述

\n

使用“角色”下拉菜单选择您希望存储库对您的包具有的默认访问级别。

\n
\n