1+ # yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
2+
13# This workflow will build a .NET project
24# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
35
4- name : .NET
6+ name : Build And Publish
57
68on :
9+ workflow_dispatch : # Allow running the workflow manually from the GitHub UI
710 push :
8- branches : [ "master" ]
11+ branches :
12+ - ' master'
913 pull_request :
10- branches : [ "master" ]
14+ branches :
15+ - ' *' # Run the workflow for all pull requests
16+ release :
17+ types :
18+ - published # Run the workflow when a new GitHub release is published
19+
20+ env :
21+ DOTNET_SKIP_FIRST_TIME_EXPERIENCE : 1
22+ DOTNET_NOLOGO : true
23+ NuGetDirectory : ${{ github.workspace }}/nuget
24+
25+ defaults :
26+ run :
27+ shell : pwsh
1128
1229jobs :
1330 build :
@@ -16,13 +33,55 @@ jobs:
1633
1734 steps :
1835 - uses : actions/checkout@v3
36+ with :
37+ fetch-depth : 0 # Get all history to allow automatic versioning using MinVer
38+
39+ # Install the .NET SDK indicated in the global.json file
1940 - name : Setup .NET
2041 uses : actions/setup-dotnet@v3
2142 with :
2243 dotnet-version : 6.0.x
44+
45+ # Restore package dependencies
2346 - name : Restore dependencies
2447 run : dotnet restore ./src
48+
49+ # Build everything
2550 - name : Build
26- run : dotnet build ./src --no-restore
51+ run : dotnet build ./src --configuration Release --no-restore
52+
53+ # Run unit tests
2754 - name : Test
28- run : dotnet test ./src --no-build --verbosity normal
55+ run : dotnet test ./src --configuration Release --no-build --verbosity normal
56+
57+ # Create the NuGet package in the folder from the environment variable NuGetDirectory
58+ - name : Pack
59+ run : dotnet pack ./src/Cubist.Helium --configuration Release --no-build --no-restore --output ${{ env.NuGetDirectory }}
60+
61+ # Publish the NuGet package as an artifact, so they can be used in the publish job
62+ - uses : actions/upload-artifact@v3
63+ with :
64+ name : nuget
65+ if-no-files-found : error
66+ retention-days : 7
67+ path : ${{ env.NuGetDirectory }}/*.nupkg
68+
69+ publish :
70+ # Publish only when creating a GitHub Release
71+ if : github.event_name == 'release'
72+ runs-on : ubuntu-latest
73+ needs : [ build ]
74+ steps :
75+ # Download the NuGet package created in the previous job
76+ - uses : actions/download-artifact@v3
77+ with :
78+ name : nuget
79+ path : ${{ env.NuGetDirectory }}
80+
81+ - name : Publish NuGet package
82+ run : |
83+ foreach($file in (Get-ChildItem "${{ env.NuGetDirectory }}" -Recurse -Include *.nupkg)) {
84+ # dotnet nuget push $file --api-key "${{ secrets.NUGET_APIKEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate
85+ write-host "dotnet nuget push $file etc..."
86+ }
87+
0 commit comments