我正在尝试使用GitHub操作从我的项目中生成NuGet包,并将其推送到(私有)GitHub注册表。
我的脚本([NAME]字段已删除):
name: Update NuGet
on: [push]
jobs:
build:
runs-on: ubuntu-latest
name: Update NuGet
steps:
- uses: actions/checkout@master
- uses: actions/setup-dotnet@v1
with:
dotnet-version: '2.2.105'
- name: Package Release
run: |
cd [SOLUTION_FOLDER]
dotnet pack -c Release -o out
- name: Publish Nuget to GitHub registry
run: dotnet nuget push ./[SOLUTION_FOLDER]/[PROJECT_FOLDER]/out/$(ls ./[SOLUTION_FOLDER]/[PROJECT_FOLDER]/out) -s https://nuget.pkg.github.com/[USERNAME]/index.json -k ${GITHUB_TOKEN}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
日志输出:
info : Pushing [PROJECT_FOLDER].3.4.23.nupkg to 'https://nuget.pkg.github.com/[USERNAME]'... info : PUT https://nuget.pkg.github.com/[USERNAME]/ info : An error was encountered when fetching 'PUT https://nuget.pkg.github.com/[USERNAME]/'. The request will now be retried. info : An error occurred while sending the request. info : The server returned an invalid or unrecognized response. info : PUT https://nuget.pkg.github.com/[USERNAME]/ info : An error was encountered when fetching 'PUT https://nuget.pkg.github.com/[USERNAME]/'. The request will now be retried. info : An error occurred while sending the request. info : The server returned an invalid or unrecognized response. info : PUT https://nuget.pkg.github.com/[USERNAME]/ error: An error occurred while sending the request. error: The server returned an invalid or unrecognized response. ##[error]Process completed with exit code 1.
这是GitHub上最核心的问题(带有解决方法):https : //github.com/NuGet/Home/issues/8580
我切换到Windows映像,并根据@anangaur的示例使其工作。这是我的最终代码:
name: NuGet Generation on: push: branches: - master jobs: build: runs-on: windows-latest name: Update NuGet steps: - name: Checkout repository uses: actions/checkout@master # latest image has .NET already installed! # - name: Setup .NET environment # uses: actions/setup-dotnet@v1 # with: # dotnet-version: '2.2.105' - name: Build solution and generate NuGet package run: | cd SOLUTION_FOLDER dotnet pack -c Release -o out - name: Install NuGet client uses: warrenbuckley/Setup-Nuget@v1 - name: Add private GitHub registry to NuGet run: nuget sources add -name "GPR" -Source https://nuget.pkg.github.com/ORGANIZATION_NAME/index.json -Username ORGANIZATION_NAME -Password ${{ secrets.GITHUB_TOKEN }} - name: Push generated package to GitHub registry run: nuget push .\SOLUTION_FOLDER\PROJECT_FOLDER\out\*.nupkg -Source "GPR" -SkipDuplicate