77 branches :
88 - ' main' # Run the workflow when pushing to the main branch
99 - ' develop' # Also run on develop, but skip publishing
10+ pull_request :
11+ branches :
12+ - ' main' # Run tests on PRs targeting main
13+ - ' develop' # Run tests on PRs targeting develop
1014
1115env :
1216 DOTNET_SKIP_FIRST_TIME_EXPERIENCE : 1
1317 DOTNET_NOLOGO : true
1418 NuGetDirectory : ${{ github.workspace}}/.nuget
1519
1620jobs :
17- publish :
18- runs-on : ubuntu-latest
21+ build :
22+ runs-on : &runner ubuntu-latest
1923
2024 steps :
2125 - name : Checkout
2226 uses : actions/checkout@v4
23-
27+
2428 - name : Setup .NET
2529 uses : actions/setup-dotnet@v4
2630 with :
@@ -35,11 +39,31 @@ jobs:
3539 run : dotnet build --configuration Release --no-restore
3640
3741 - name : Run tests
38- run : dotnet test --no-restore
39-
42+ run : dotnet test --configuration Release --no-build -- no-restore
43+
4044 - name : Create NuGet package
45+ if : github.event_name == 'push'
4146 run : dotnet pack --configuration Release --no-restore --output ${{ env.NuGetDirectory }}
4247
48+ - name : Upload package artifact
49+ if : github.event_name == 'push'
50+ uses : actions/upload-artifact@v4
51+ with :
52+ name : nuget-packages
53+ path : ${{ env.NuGetDirectory }}/*.nupkg
54+ if-no-files-found : error
55+
56+ publish :
57+ needs : build
58+ if : github.event_name == 'push' && github.ref_name == 'main'
59+ runs-on : *runner
60+
61+ steps :
62+ - name : Download package artifact
63+ uses : actions/download-artifact@v4
64+ with :
65+ name : nuget-packages
66+ path : ${{ env.NuGetDirectory }}
67+
4368 - name : Publish NuGet package
44- if : github.ref_name == 'main'
4569 run : dotnet nuget push ${{ env.NuGetDirectory }}/*.nupkg --api-key ${{ secrets.NUGET_APIKEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
0 commit comments