Skip to content

Commit 8451dbd

Browse files
committed
Add multi-targeting and GitHub Actions for auto NuGet publishing
1 parent caceee7 commit 8451dbd

File tree

2 files changed

+47
-13
lines changed

2 files changed

+47
-13
lines changed

.github/workflows/publish-nuget.yml

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ name: Publish NuGet Package
22

33
on:
44
push:
5+
branches:
6+
- main
57
tags:
68
- 'v*.*.*'
79

@@ -13,16 +15,19 @@ jobs:
1315
- name: Checkout code
1416
uses: actions/checkout@v3
1517

16-
- name: Setup .NET
18+
- name: Setup .NET SDK
1719
uses: actions/setup-dotnet@v4
1820
with:
1921
dotnet-version: |
2022
6.0.x
2123
8.0.x
2224
23-
- name: Extract version from tag
24-
id: tag
25-
run: echo "VERSION=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
25+
- name: Install GitVersion
26+
uses: gittools/actions/gitversion/[email protected]
27+
28+
- name: Use GitVersion to get version info
29+
id: gitversion
30+
run: gitversion /output json /showvariable SemVer
2631

2732
- name: Restore dependencies
2833
run: dotnet restore
@@ -31,14 +36,8 @@ jobs:
3136
run: dotnet build --configuration Release --no-restore
3237

3338
- name: Pack NuGet
34-
run: |
35-
dotnet pack --configuration Release \
36-
-p:PackageVersion=${{ steps.tag.outputs.VERSION }} \
37-
--no-build -o out
39+
run: dotnet pack --configuration Release -p:PackageVersion=${{ steps.gitversion.outputs.SemVer }} --no-build -o out
3840

3941
- name: Push to NuGet
40-
if: success() && steps.tag.outputs.VERSION != ''
41-
run: |
42-
dotnet nuget push out/*.nupkg \
43-
--api-key ${{ secrets.NUGET_API_KEY }} \
44-
--source https://api.nuget.org/v3/index.json
42+
if: success() && github.event_name == 'push'
43+
run: dotnet nuget push out/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json

GitVersion.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
mode: ContinuousDelivery
2+
3+
branches:
4+
main:
5+
regex: ^main$
6+
increment: Minor
7+
prevent-increment-of-merged-branch-version: true
8+
track-merge-target: false
9+
tag: ''
10+
11+
develop:
12+
regex: ^develop$
13+
increment: Patch
14+
tag: 'beta'
15+
16+
feature:
17+
regex: ^feature[/-]
18+
increment: Patch
19+
tag: 'alpha'
20+
21+
bugfix:
22+
regex: ^bugfix[/-]
23+
increment: Patch
24+
tag: 'alpha'
25+
26+
release:
27+
regex: ^release[/-]
28+
increment: Patch
29+
tag: 'rc'
30+
31+
ignore:
32+
sha: []
33+
34+
commit-message-incrementing: Enabled
35+

0 commit comments

Comments
 (0)