|
1 |
| -name: Auto-version and Publish |
| 1 | +name: Publish to NuGet |
2 | 2 |
|
3 | 3 | on:
|
4 | 4 | push:
|
5 |
| - branches: |
6 |
| - - main |
| 5 | + tags: |
| 6 | + - 'v*' |
7 | 7 |
|
8 | 8 | jobs:
|
9 |
| - version-and-publish: |
| 9 | + build: |
10 | 10 | runs-on: ubuntu-latest
|
11 |
| - permissions: |
12 |
| - contents: write |
13 | 11 |
|
14 | 12 | steps:
|
15 |
| - - 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 |
33 |
| - |
34 |
| - - name: Setup .NET |
35 |
| - uses: actions/setup-dotnet@v3 |
36 |
| - with: |
37 |
| - dotnet-version: '9.0.x' |
38 |
| - |
39 |
| - - name: Build and Test |
40 |
| - run: | |
41 |
| - dotnet restore |
42 |
| - dotnet build --configuration Release |
43 |
| - dotnet test --no-restore |
44 |
| - |
45 |
| - - name: Pack |
46 |
| - run: dotnet pack --configuration Release --no-build --output nupkgs |
47 |
| - |
48 |
| - - name: Push to NuGet |
49 |
| - run: | |
50 |
| - cd nupkgs |
51 |
| - for f in *.nupkg |
52 |
| - do |
53 |
| - dotnet nuget push $f --api-key ${{secrets.NUGET_API_KEY}} --source https://api.nuget.org/v3/index.json --skip-duplicate |
54 |
| - done |
| 13 | + - uses: actions/checkout@v3 |
| 14 | + |
| 15 | + - name: Setup .NET |
| 16 | + uses: actions/setup-dotnet@v3 |
| 17 | + with: |
| 18 | + dotnet-version: '9.0.x' |
| 19 | + |
| 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 |
| 28 | + |
| 29 | + - name: Pack |
| 30 | + run: dotnet pack --configuration Release --no-build --output nupkgs |
| 31 | + |
| 32 | + - name: Push to NuGet |
| 33 | + run: | |
| 34 | + cd nupkgs |
| 35 | + for f in *.nupkg |
| 36 | + do |
| 37 | + dotnet nuget push $f --api-key ${{secrets.NUGET_API_KEY}} --source https://api.nuget.org/v3/index.json --skip-duplicate |
| 38 | + done |
0 commit comments