1
+ name : Publish to NuGet
2
+
3
+ on :
4
+ push :
5
+ tags :
6
+ - ' v*.*.*'
7
+ - ' v*.*.*-*' # Trigger on tags matching vX.Y.Z or vX.Y.Z-prerelease
8
+
9
+ jobs :
10
+ build :
11
+ name : Build and Test
12
+ runs-on : ubuntu-latest
13
+
14
+ steps :
15
+ - name : Checkout code
16
+ uses : actions/checkout@v4
17
+
18
+ - name : Setup .NET SDK
19
+ uses : actions/setup-dotnet@v4
20
+ with :
21
+ dotnet-version : ' 8.0.x'
22
+
23
+ - name : Restore dependencies
24
+ run : dotnet restore
25
+
26
+ - name : Build
27
+ run : dotnet build --configuration Release
28
+
29
+ # - name: Test
30
+ # run: dotnet test --configuration Release --no-build --verbosity normal
31
+
32
+ pack :
33
+ name : Pack
34
+ needs : build
35
+ runs-on : ubuntu-latest
36
+
37
+ steps :
38
+ - name : Checkout code
39
+ uses : actions/checkout@v4
40
+
41
+ - name : Setup .NET SDK
42
+ uses : actions/setup-dotnet@v4
43
+ with :
44
+ dotnet-version : ' 8.0.x' # Ensure this matches the build job
45
+
46
+ - name : Restore dependencies
47
+ run : dotnet restore
48
+
49
+ - name : Build
50
+ run : dotnet build --configuration Release
51
+
52
+ - name : Determine version
53
+ id : version
54
+ run : echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
55
+
56
+ - name : Pack
57
+ run : dotnet pack --configuration Release --output . --include-symbols /p:Version=${{ steps.version.outputs.VERSION }}
58
+
59
+ - name : Upload NuGet package artifact
60
+ uses : actions/upload-artifact@v4
61
+ with :
62
+ name : nuget-package
63
+ path : ' *.nupkg'
64
+
65
+ publish :
66
+ name : Publish to NuGet.org
67
+ needs : pack
68
+ runs-on : ubuntu-latest
69
+ permissions :
70
+ packages : write
71
+ steps :
72
+ - name : Download NuGet package artifact
73
+ uses : actions/download-artifact@v4
74
+ with :
75
+ name : nuget-package
76
+ path : .
77
+
78
+ - name : Determine if prerelease
79
+ id : prerelease
80
+ run : |
81
+ VERSION="${GITHUB_REF#refs/tags/}"
82
+ if [[ "$VERSION" == *"-"* ]]; then
83
+ echo "IS_PRERELEASE=true" >> $GITHUB_OUTPUT
84
+ else
85
+ echo "IS_PRERELEASE=false" >> $GITHUB_OUTPUT
86
+ fi
87
+
88
+ - name : Publish to NuGet.org
89
+ if : steps.prerelease.outputs.IS_PRERELEASE == 'true'
90
+ run : dotnet nuget push "*.nupkg" --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }} --prerelease
91
+
92
+ - name : Publish release to NuGet.org
93
+ if : steps.prerelease.outputs.IS_PRERELEASE == 'false'
94
+ run : dotnet nuget push "*.nupkg" --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }}
0 commit comments