-
Notifications
You must be signed in to change notification settings - Fork 0
54 lines (45 loc) · 1.52 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
name: Auto-version and Publish
on:
push:
branches:
- main
jobs:
version-and-publish:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Update Version and Create Tag
run: |
CSPROJ_FILE="$(find . -name "*.csproj" | head -n 1)"
CURRENT_VERSION=$(grep -oP '(?<=<Version>)[^<]+' "$CSPROJ_FILE")
IFS='.' read -ra VERSION_PARTS <<< "$CURRENT_VERSION"
NEW_VERSION="${VERSION_PARTS[0]}.${VERSION_PARTS[1]}.$((VERSION_PARTS[2] + 1))"
sed -i "s|<Version>$CURRENT_VERSION</Version>|<Version>$NEW_VERSION</Version>|" "$CSPROJ_FILE"
git config user.name "GitHub Actions"
git config user.email "[email protected]"
git add "$CSPROJ_FILE"
git commit -m "bump version to $NEW_VERSION"
git tag "v$NEW_VERSION"
git push && git push --tags
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '9.0.x'
- name: Build and Test
run: |
dotnet restore
dotnet build --configuration Release
dotnet test --no-restore
- name: Pack
run: dotnet pack --configuration Release --no-build --output nupkgs
- name: Push to NuGet
run: |
cd nupkgs
for f in *.nupkg
do
dotnet nuget push $f --api-key ${{secrets.NUGET_API_KEY}} --source https://api.nuget.org/v3/index.json --skip-duplicate
done