Skip to content

Commit 203214f

Browse files
authored
Create dotnet-desktop.yml
1 parent 03065d4 commit 203214f

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

.github/workflows/dotnet-desktop.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Build and Publish NuGet Package
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
build-and-publish:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: write
12+
packages: write
13+
env:
14+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
15+
PROJECTS: |
16+
src/Moss.NET.Sdk/Moss.NET.Sdk.csproj
17+
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4.1.7
21+
with:
22+
fetch-depth: 0
23+
ref: main
24+
25+
- name: Set default branch.
26+
run: |
27+
git fetch origin
28+
git remote set-head origin --auto
29+
30+
- name: Prepare repository
31+
run: git checkout main
32+
33+
- name: Setup .NET
34+
uses: actions/setup-dotnet@v3
35+
with:
36+
dotnet-version: '8.x'
37+
38+
- name: Setup .NET
39+
uses: actions/setup-dotnet@v3
40+
with:
41+
dotnet-version: '9.x'
42+
43+
- name: Get release version
44+
id: get_release
45+
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
46+
47+
- name: Update .csproj files
48+
run: |
49+
RELEASE_VERSION=${{ env.RELEASE_VERSION }}
50+
IFS=$'\n' # Set the Internal Field Separator to newline for reading multi-line variable
51+
for PROJECT in $PROJECTS; do
52+
sed -i "s/<Version>.*<\/Version>/<Version>${RELEASE_VERSION}<\/Version>/" "$PROJECT"
53+
done
54+
55+
- name: GIT commit and push overriding conflicts with local changes (verbose)
56+
run: |
57+
git config --global user.name "github-actions[bot]"
58+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
59+
git add src/*.csproj
60+
git commit -m "Update version to ${{ env.RELEASE_VERSION }}"
61+
git fetch origin
62+
git rebase --strategy-option=theirs origin/main
63+
git push
64+
65+
- name: Build and package
66+
run: |
67+
IFS=$'\n' # Set the Internal Field Separator to newline for reading multi-line variable
68+
for PROJECT in $PROJECTS; do
69+
dotnet build -c Release -o ./nuget "$PROJECT"
70+
done
71+
72+
- name: Publish to NuGet
73+
uses: actions/upload-artifact@v4
74+
with:
75+
name: nuget-package
76+
path: ./nuget/*.nupkg
77+
78+
- name: Publish package To Nuget
79+
run: |
80+
dotnet nuget push ./nuget/*.nupkg --api-key "${{ secrets.NUGET_APIKEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate

0 commit comments

Comments
 (0)