-
Notifications
You must be signed in to change notification settings - Fork 10
89 lines (77 loc) · 2.55 KB
/
build-and-test.yml
File metadata and controls
89 lines (77 loc) · 2.55 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
name: Build and Test (Reusable)
on:
workflow_call:
inputs:
dotnet-version:
description: '.NET version to use (can be multi-line for multiple versions)'
required: false
type: string
default: |
8.0.x
9.0.x
10.0.x
configuration:
description: 'Build configuration'
required: false
type: string
default: 'Release'
upload-test-results:
description: 'Whether to upload test results as artifacts'
required: false
type: boolean
default: false
create-pack:
description: 'Whether to pack NuGet packages'
required: false
type: boolean
default: false
outputs:
version:
description: 'The calculated version from NBGV'
value: ${{ jobs.build.outputs.version }}
jobs:
build:
name: Build and Test
runs-on: ubuntu-latest
outputs:
version: ${{ steps.nbgv.outputs.SemVer2 }}
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0 # Required for GitVersion
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: ${{ inputs.dotnet-version }}
global-json-file: ./global.json
- name: Calculate Version with NBGV
uses: dotnet/nbgv@master
id: nbgv
with:
setAllVars: true
- name: Version Info
run: |
echo "Calculated version: ${{ steps.nbgv.outputs.SemVer2 }}"
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration ${{ inputs.configuration }} --no-restore /p:Version=${{ steps.nbgv.outputs.SemVer2 }}
- name: Test
run: dotnet test --configuration ${{ inputs.configuration }} --no-build --verbosity normal --logger "trx;LogFileName=test-results.trx"
- name: Upload test results
if: always() && inputs.upload-test-results
uses: actions/upload-artifact@v6
with:
name: test-results-${{ inputs.dotnet-version }}
path: '**/TestResults/**/*.trx'
- name: Pack NuGet packages
if: inputs.create-pack
run: dotnet pack --configuration ${{ inputs.configuration }} --no-build --output ./artifacts /p:PackageVersion=${{ steps.nbgv.outputs.SemVer2 }}
- name: Upload NuGet packages
if: inputs.create-pack
uses: actions/upload-artifact@v6
with:
name: nuget-packages
path: ./artifacts/*.nupkg
retention-days: 30