Skip to content

Commit ffa5e18

Browse files
authored
Update dotnet.yml
1 parent e216e97 commit ffa5e18

File tree

1 file changed

+54
-10
lines changed

1 file changed

+54
-10
lines changed

.github/workflows/dotnet.yml

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
1+
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
2+
13
# This workflow will build a .NET project
24
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
35

4-
name: .NET
6+
name: Build And Publish
57

68
on:
79
workflow_dispatch: # Allow running the workflow manually from the GitHub UI
810
push:
9-
branches: [ "master" ]
11+
branches:
12+
- 'master'
1013
pull_request:
11-
branches: [ "master" ]
14+
branches:
15+
- '*' # Run the workflow for all pull requests
16+
release:
17+
types:
18+
- published # Run the workflow when a new GitHub release is published
1219

1320
env:
1421
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
1522
DOTNET_NOLOGO: true
23+
NuGetDirectory: ${{ github.workspace }}/nuget
1624

1725
defaults:
1826
run:
@@ -25,19 +33,55 @@ jobs:
2533

2634
steps:
2735
- uses: actions/checkout@v3
36+
with:
37+
fetch-depth: 0 # Get all history to allow automatic versioning using MinVer
38+
39+
# Install the .NET SDK indicated in the global.json file
2840
- name: Setup .NET
2941
uses: actions/setup-dotnet@v3
3042
with:
3143
dotnet-version: 6.0.x
44+
45+
# Restore package dependencies
3246
- name: Restore dependencies
3347
run: dotnet restore ./src
48+
49+
# Build everything
3450
- name: Build
35-
run: dotnet build ./src --no-restore
51+
run: dotnet build ./src --configuration Release --no-restore
52+
53+
# Run unit tests
3654
- name: Test
37-
run: dotnet test ./src --no-build --verbosity normal
38-
- name: Publish NuGet package
39-
run: |
40-
foreach($file in (Get-ChildItem "./src" -Recurse -Include *.nupkg)) {
41-
dotnet nuget push $file --api-key "${{ secrets.NUGET_APIKEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate
42-
}
55+
run: dotnet test ./src --configuration Release --no-build --verbosity normal
56+
57+
# Create the NuGet package in the folder from the environment variable NuGetDirectory
58+
- name: Pack
59+
run: dotnet pack ./src --configuration Release --no-build --no-restore --output ${{ env.NuGetDirectory }}
60+
61+
# Publish the NuGet package as an artifact, so they can be used in the publish job
62+
- uses: actions/upload-artifact@v3
63+
with:
64+
name: nuget
65+
if-no-files-found: error
66+
retention-days: 7
67+
path: ${{ env.NuGetDirectory }}/*.nupkg
68+
69+
publish:
70+
# Publish only when creating a GitHub Release
71+
if: github.event_name == 'release'
72+
runs-on: ubuntu-latest
73+
needs: [ build ]
74+
steps:
75+
# Download the NuGet package created in the previous job
76+
- uses: actions/download-artifact@v3
77+
with:
78+
name: nuget
79+
path: ${{ env.NuGetDirectory }}
80+
81+
- name: Publish NuGet package
82+
run: |
83+
foreach($file in (Get-ChildItem "${{ env.NuGetDirectory }}" -Recurse -Include *.nupkg)) {
84+
# dotnet nuget push $file --api-key "${{ secrets.NUGET_APIKEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate
85+
write-host "dotnet nuget push $file etc..."
86+
}
4387

0 commit comments

Comments
 (0)