Skip to content

Commit a98c7cd

Browse files
authored
Update main.yml
1 parent 9950750 commit a98c7cd

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

.github/workflows/main.yml

+28-12
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,46 @@
1-
name: Publish to NuGet
1+
name: Auto-version and Publish
22

33
on:
44
push:
5-
tags:
6-
- 'v*'
5+
branches:
6+
- main
77

88
jobs:
9-
build:
9+
version-and-publish:
1010
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
1113

1214
steps:
1315
- uses: actions/checkout@v3
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Update Version and Create Tag
20+
run: |
21+
CSPROJ_FILE="$(find . -name "*.csproj" | head -n 1)"
22+
CURRENT_VERSION=$(grep -oP '(?<=<Version>)[^<]+' "$CSPROJ_FILE")
23+
IFS='.' read -ra VERSION_PARTS <<< "$CURRENT_VERSION"
24+
NEW_VERSION="${VERSION_PARTS[0]}.${VERSION_PARTS[1]}.$((VERSION_PARTS[2] + 1))"
25+
sed -i "s|<Version>$CURRENT_VERSION</Version>|<Version>$NEW_VERSION</Version>|" "$CSPROJ_FILE"
26+
27+
git config user.name "GitHub Actions"
28+
git config user.email "[email protected]"
29+
git add "$CSPROJ_FILE"
30+
git commit -m "bump version to $NEW_VERSION"
31+
git tag "v$NEW_VERSION"
32+
git push && git push --tags
1433
1534
- name: Setup .NET
1635
uses: actions/setup-dotnet@v3
1736
with:
1837
dotnet-version: '9.0.x'
1938

20-
- name: Restore dependencies
21-
run: dotnet restore
22-
23-
- name: Build
24-
run: dotnet build --configuration Release --no-restore
25-
26-
- name: Test
27-
run: dotnet test --no-restore --verbosity normal
39+
- name: Build and Test
40+
run: |
41+
dotnet restore
42+
dotnet build --configuration Release
43+
dotnet test --no-restore
2844
2945
- name: Pack
3046
run: dotnet pack --configuration Release --no-build --output nupkgs

0 commit comments

Comments
 (0)