Skip to content

Commit f180d1a

Browse files
ci: Publish workflow
1 parent 5e93a29 commit f180d1a

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

.github/workflows/publish.yaml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Build and Publish NuGet
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- dev
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0
17+
18+
- name: Setup .NET
19+
uses: actions/setup-dotnet@v4
20+
with:
21+
dotnet-version: '9.0.x'
22+
23+
- name: Install GitVersion
24+
uses: GitTools/actions/gitversion/setup@v0.10.2
25+
with:
26+
versionSpec: '5.x'
27+
28+
- name: Run GitVersion
29+
id: gitversion
30+
uses: GitTools/actions/gitversion/execute@v0.10.2
31+
32+
- name: Check if version changed
33+
id: version_check
34+
run: |
35+
echo "SemVer: ${{ steps.gitversion.outputs.semVer }}"
36+
if [ "${{ steps.gitversion.outputs.CommitDate }}" = "" ]; then
37+
echo "No new version, skipping."
38+
echo "##[set-output name=changed;]false"
39+
else
40+
echo "New version detected."
41+
echo "changed=true" >> $GITHUB_OUTPUT
42+
fi
43+
44+
- name: Build
45+
if: steps.version_check.outputs.changed == 'true'
46+
run: dotnet build -c Release
47+
working-directory: src
48+
49+
- name: Pack
50+
if: steps.version_check.outputs.changed == 'true'
51+
run: dotnet pack -c Release /p:PackageVersion=${{ steps.gitversion.outputs.nuGetVersionV2 }} -o nupkg
52+
working-directory: src
53+
54+
- name: Push to NuGet
55+
if: steps.version_check.outputs.changed == 'true'
56+
run: dotnet nuget push "nupkg/*.nupkg" -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json
57+
working-directory: src
58+
59+
- name: Tag
60+
if: steps.version_check.outputs.changed == 'true'
61+
run: |
62+
git tag ${{ steps.gitversion.outputs.semVer }}
63+
git push origin ${{ steps.gitversion.outputs.semVer }}
64+

0 commit comments

Comments
 (0)