使用 GitHub 操作时发布模块引发 401

问题描述 投票:0回答:1

我尝试使用 Publish-Module cmdlet 将具有 github 操作的模块发布到 github 包目录。我起诉 Windows Server 2022,它是空白安装,其中安装了 github 操作运行程序。

我的 github 工作流程中的部分如下:

jobs:
  pwslmanage:
    name: pswslmanage
    runs-on: [self-hosted]
    permissions:
      actions: read
      packages: write
    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          path: ./pswslmanage

      - name: Publish
        run: |
          $_repo_name = "SAPSGallery"
          $_repo_owner = "myorg"
          $_feed = "https://nuget.pkg.github.com/$_repo_owner/index.json"
          $_user = "user-myorg"
          $_token = "$($env:GH_TOKEN)" | ConvertTo-SecureString -AsPlainText -Force
          $_creds = New-Object System.Management.Automation.PSCredential -ArgumentList @($_user, $_token)
          $_module_name = "pswslmanage"
          $_repo_dir = "{0}\myorg-pswslmanage\pswslmanage" -f $($env:RUNNER_WORKSPACE)

          Register-PSRepository -Name $_repo_name -SourceLocation $_feed -PublishLocation $_feed -InstallationPolicy 'Trusted' -Credential $_creds -Verbose
          Publish-Module -Path "$_repo_dir" -Repository "$_repo_name" -NuGetApiKey "$($env:GH_TOKEN)" -Verbose
        env:
          GH_TOKEN: ${{secrets.GITHUB_TOKEN}}

无论我尝试什么,都会出现错误

Unable to load the service index for source https://nuget.pkg.github.com/myorg/index.json. 401 (Unauthorized)
。我使用 Powershell 5.1 和 PSCore 7.3.6 进行了测试。下面您还将看到发布模块的详细输出(但我认为只有最后几行很有趣)。

我尝试使用给定的 GH_TOKEN (和随机用户名)在浏览器中下载 index.json,该文件有效。我还尝试使用具有完全权限的 PAT(而不是 Secret.GITHUB_TOKEN 提供的内置令牌)。

编辑:必须禁用“TLS1.3”,并且必须将“nuget”下载到“$($env:PROGRAMDATA)\Microsoft\Windows\PowerShell\PowerShellGet”才能到达发生 401 错误的位置。

有什么想法吗?

提前致谢

戴夫

VERBOSE: Acquiring providers for assembly: C:\program files\powershell\7\Modules\PackageManagement\coreclr\netstandard2.0\Microsoft.PackageManagement.NuGetProvider.dll 
VERBOSE: Acquiring providers for assembly: C:\program files\powershell\7\Modules\PackageManagement\coreclr\netstandard2.0\Microsoft.PackageManagement.MetaProvider.PowerShell.dll 
VERBOSE: Acquiring providers for assembly: C:\program files\powershell\7\Modules\PackageManagement\coreclr\netstandard2.0\Microsoft.PackageManagement.ArchiverProviders.dll 
VERBOSE: Acquiring providers for assembly: C:\program files\powershell\7\Modules\PackageManagement\coreclr\netstandard2.0\Microsoft.PackageManagement.CoreProviders.dll 
VERBOSE: Suppressed Verbose Repository details, Name = 'SAPSGallery', Location = 'https://nuget.pkg.github.com/myorg/index.json'; IsTrusted = 'True'; IsRegistered = 'True'. 
VERBOSE: Repository details, Name = 'SAPSGallery', Location = 'https://nuget.pkg.github.com/myorg/index.json'; IsTrusted = 'True'; IsRegistered = 'True'. 
VERBOSE: Repository details, Name = 'SAPSGallery', Location = 'https://nuget.pkg.github.com/myorg/index.json'; IsTrusted = 'True'; IsRegistered = 'True'. 
VERBOSE: Publish Location:'https://nuget.pkg.github.com/myorg/index.json'. VERBOSE: Module 'pswslmanage' was found in 'C:\ProgramData\GitHub-Actions-Runner_work\myorg-pswslmanage\myorg-pswslmanage\pswslmanage'. 
VERBOSE: Suppressed Verbose Repository details, Name = 'SAPSGallery', Location = 'https://nuget.pkg.github.com/myorg/index.json'; IsTrusted = 'True'; IsRegistered = 'True'. 
VERBOSE: Repository details, Name = 'SAPSGallery', Location = 'https://nuget.pkg.github.com/myorg/index.json'; IsTrusted = 'True'; IsRegistered = 'True'. 
VERBOSE: Using the provider 'PowerShellGet' for searching packages. 
VERBOSE: Using the specified source names : 'SAPSGallery'. 
VERBOSE: Getting the provider object for the PackageManagement Provider 'NuGet'. 
VERBOSE: The specified Location is 'https://nuget.pkg.github.com/myorg/index.json' and PackageManagementProvider is 'NuGet'. 
VERBOSE: Retry downloading 'https://nuget.pkg.github.com/myorg/query' for '2' more times 
VERBOSE: Retry downloading 'https://nuget.pkg.github.com/myorg/query' for '1' more times 
VERBOSE: Retry downloading 'https://nuget.pkg.github.com/myorg/query' for '0' more times 
VERBOSE: Retry downloading 'https://nuget.pkg.github.com/myorg/pswslmanage/index.json' for '0' more times 
VERBOSE: Retry downloading 'https://nuget.pkg.github.com/myorg/pswslmanage/index.json' for '0' more times 
VERBOSE: Retry downloading 'https://nuget.pkg.github.com/myorg/pswslmanage/index.json' for '0' more times 
VERBOSE: Total package yield:'0' for the specified package 'pswslmanage'. 
VERBOSE: Performing the operation "Publish-Module" on target "Version '1.0.0' of module 'pswslmanage'". 
VERBOSE: Calling Publish-PSArtifactUtility VERBOSE: Calling New-NuspecFile VERBOSE: Calling New-NugetPackage 
VERBOSE: Calling C:\ProgramData\Microsoft\Windows\PowerShell\PowerShellGet\NuGet.exe pack "C:\Users\Administrator\AppData\Local\Temp\1989646393\pswslmanage\pswslmanage.nuspec" -outputdirectory "C:\Users\Administrator\AppData\Local\Temp\1989646393\pswslmanage" -noninteractive 
VERBOSE: C:\ProgramData\Microsoft\Windows\PowerShell\PowerShellGet\NuGet.exe output: VERBOSE: Attempting to build package from 'pswslmanage.nuspec'. 
VERBOSE: WARNING: NU5119: File 'C:\Users\Administrator\AppData\Local\Temp\1989646393\pswslmanage.gitattributes' was not added to the package. Files and folders starting with '.' or ending with '.nupkg' are excluded by default. To include this file, use -NoDefaultExcludes from the commandline 
VERBOSE: WARNING: NU5119: File 'C:\Users\Administrator\AppData\Local\Temp\1989646393\pswslmanage.gitignore' was not added to the package. Files and folders starting with '.' or ending with '.nupkg' are excluded by default. To include this file, use -NoDefaultExcludes from the commandline 
VERBOSE: WARNING: NU5110: The script file 'pswslmanage-helper.ps1' is outside the 'tools' folder and hence will not be executed during installation of this package. Move it into the 'tools' folder. 
VERBOSE: WARNING: NU5110: The script file 'pswslmanage-roles.ps1' is outside the 'tools' folder and hence will not be executed during installation of this package. Move it into the 'tools' folder. 
VERBOSE: WARNING: NU5110: The script file 'pswslmanage-start.ps1' is outside the 'tools' folder and hence will not be executed during installation of this package. Move it into the 'tools' folder. 
VERBOSE: WARNING: NU5110: The script file 'tests\pswslmanage.tests.ps1' is outside the 'tools' folder and hence will not be executed during installation of this package. Move it into the 'tools' folder. 
VERBOSE: WARNING: NU5111: The script file 'pswslmanage-helper.ps1' is not recognized by NuGet and hence will not be executed during installation of this package. Rename it to install.ps1, uninstall.ps1 or init.ps1 and place it directly under 'tools'. 
VERBOSE: WARNING: NU5111: The script file 'pswslmanage-roles.ps1' is not recognized by NuGet and hence will not be executed during installation of this package. Rename it to install.ps1, uninstall.ps1 or init.ps1 and place it directly under 'tools'. 
VERBOSE: WARNING: NU5111: The script file 'pswslmanage-start.ps1' is not recognized by NuGet and hence will not be executed during installation of this package. Rename it to install.ps1, uninstall.ps1 or init.ps1 and place it directly under 'tools'. 
VERBOSE: WARNING: NU5111: The script file 'tests\pswslmanage.tests.ps1' is not recognized by NuGet and hence will not be executed during installation of this package. Rename it to install.ps1, uninstall.ps1 or init.ps1 and place it directly under 'tools'. 
VERBOSE: The package pswslmanage.1.0.0 is missing a readme. Go to https://aka.ms/nuget/authoring-best-practices/readme to learn why package readmes are important. 
VERBOSE: Successfully created package 'C:\Users\Administrator\AppData\Local\Temp\1989646393\pswslmanage\pswslmanage.1.0.0.nupkg'. 
VERBOSE: 
VERBOSE: finished running C:\ProgramData\Microsoft\Windows\PowerShell\PowerShellGet\NuGet.exe with exit code 0 
VERBOSE: Created Nuget Package C:\Users\Administrator\AppData\Local\Temp\1989646393\pswslmanage\pswslmanage.1.0.0.nupkg 
VERBOSE: Successfully created nuget package at C:\Users\Administrator\AppData\Local\Temp\1989646393\pswslmanage\pswslmanage.1.0.0.nupkg 
VERBOSE: Calling Publish-NugetPackage -NupkgPath C:\Users\Administrator\AppData\Local\Temp\1989646393\pswslmanage\pswslmanage.1.0.0.nupkg -Destination https://nuget.pkg.github.com/myorg/index.json -NugetExePath C:\ProgramData\Microsoft\Windows\PowerShell\PowerShellGet\NuGet.exe -UseDotnetCli:FalseWrite-Error: Failed to publish module 'pswslmanage': 'nuget.exe failed to push Unable to load the service index for source https://nuget.pkg.github.com/myorg/index.json. Response status code does not indicate success: 401 (Unauthorized). '.
powershell nuget
1个回答
0
投票

我有一个半答案作为解决方案。也许它会帮助某人走得更远。

v2-Powershell 命令与 GitHub 包不兼容。需要将 v3-PSResourceGet 命令与兼容性模块“CompatPowerShellGet”一起安装。我通过手动运行命令成功了。我能够发布 (

Publish-Module ...
) 模块,找到 (
Find-Module -Name pswslmanage -Repository SAPSGallery
) 并从 GitHub 包安装模块 (
Install-Module ...
)。

但这只是一个半答案,因为相同的命令在作为 GitHub 操作运行时不会成功。这将产生以下输出:

VERBOSE: Performing the operation "Publish-PSResource" on target "Publish resource 'C:\ProgramData\GitHub-Actions-Runner\_work\shiftavenue-pswslmanage\shiftavenue-pswslmanage\pswslmanage' from the machine".
VERBOSE: The newly created nuspec is: C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Temp\233a4e7a-ceca-4894-9705-9001f72f5585\pswslmanage.nuspec
VERBOSE: Successfully packed the resource into a .nupkg
VERBOSE: Not able to publish resource to 'https://nuget.pkg.github.com/shiftavenue/index.json'
VERBOSE: Deleting temporary directory 'C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Temp\233a4e7a-ceca-4894-9705-9001f72f5585'
Publish-PSResource: C:\ProgramData\GitHub-Actions-Runner\_work\_temp\5615f135-c32d-49aa-81ec-3147104bfb1c.ps1:39
Line |
  39 |  Publish-Module -Path "$_repo_dir" -Repository "$_repo_name" -NuGetApi …
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Repository 'SAPSGallery': Response status code does not indicate success: 403 (Forbidden).
Error: Process completed with exit code 1.

我的想法是将开发版本发布到 GitHub 包而不是 PSGallery。现在我将放弃这一点并使用预发行标志发布到 PSGallery。

© www.soinside.com 2019 - 2024. All rights reserved.