-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdotnet-nuget-build-multi-sdk.yml
More file actions
100 lines (82 loc) · 3.08 KB
/
dotnet-nuget-build-multi-sdk.yml
File metadata and controls
100 lines (82 loc) · 3.08 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
name: myCSharp .NET setup and build workflow
# this workflow creates and publishes a NuGet package when a release is created
on:
workflow_call:
inputs:
configuration:
required: false
type: string
default: 'Release'
description: 'The build configuration. Eg debug/release'
dotnet-sdks:
required: true
type: string
description: 'JSON array of .NET SDK versions to set up.'
secrets:
NUGET_API_KEY:
required: true
env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.
- name: Setup Multiple .NET SDKs
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ inputs.dotnet-sdks }}
- name: Restore dependencies
run: dotnet restore
- name: Setup Git Versioning
uses: dotnet/nbgv@master
id: nbgv
- name: Show Version Info
run: |
echo 'SemVer2: ${{ steps.nbgv.outputs.SemVer2 }}'
- name: Build with dotnet
run: dotnet build
--no-restore --configuration ${{ inputs.configuration }}
/p:Version=${{ steps.nbgv.outputs.AssemblyVersion }}
- name: Test with dotnet
run: dotnet test
--no-build --configuration ${{ inputs.configuration }}
--logger "trx;LogFileName=test-results.trx" --results-directory ./artifacts/test-results
continue-on-error: true
- name: Pack NuGet
run: dotnet pack
--configuration ${{ inputs.configuration }}
--output ./artifacts/nuget-packages
/p:ContinuousIntegrationBuild=true
/p:Version=${{ steps.nbgv.outputs.NuGetPackageVersion }}
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: artifacts
path: ./artifacts/**/*
# the deploy job runs only when the build job is successful and the event is a release
deploy:
if: github.event_name == 'release'
name: Publish Package
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.
- name: Download build artifacts
uses: actions/download-artifact@v4
- name: Upload release asset
run: gh release upload ${{ github.event.release.tag_name }} ${{ github.workspace }}/artifacts/nuget-packages/*.*nupkg
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ inputs.dotnet-sdks }}
- name: Publish package
run: dotnet nuget push ${{github.workspace}}/artifacts/nuget-packages/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.NUGET_API_KEY }} --skip-duplicate