-
Notifications
You must be signed in to change notification settings - Fork 3
137 lines (115 loc) · 5.45 KB
/
build-and-test.yml
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
name: Build and Test
on:
push:
branches:
- master
- dev
- epic/*
pull_request:
types:
- opened
- synchronize
- reopened
jobs:
build_and_test:
runs-on: windows-latest
env:
DOTNET_VERSION: '6.0.x'
## Include all git history (fetch depth 0) for enhanced SonarCloud analysis (default is 1 for most recent commit)
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
## SonarCloud Setup
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'zulu'
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~\sonar\cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache SonarCloud scanner
id: cache-sonar-scanner
uses: actions/cache@v3
with:
path: .\.sonar\scanner
key: ${{ runner.os }}-sonar-scanner
restore-keys: ${{ runner.os }}-sonar-scanner
- name: Install SonarCloud scanner
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
shell: powershell
run: |
New-Item -Path .\.sonar\scanner -ItemType Directory
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner
## C-Sharp Setup
- name: Setup .NET Core SDK ${{ env.DOTNET_VERSION }}
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Setup MSBuild
uses: microsoft/setup-msbuild@v1
- name: Setup NuGet
uses: NuGet/[email protected]
- name: Setup VSTest
uses: darenm/Setup-VSTest@v1
- name: Restore Packages
working-directory: ./Web
run: nuget restore EdubaseWeb.sln
- name: Restore Packages
working-directory: ./Web
run: dotnet tool install --global dotnet-coverage
## Clean build and test
## Currently manually specifying the tests to trigger -- unclear if these can be picked up automatically?
- name: Build, Test, and Analyse
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
working-directory: ./Web
run: |
$env:EXIT_CODE=0
..\.sonar\scanner\dotnet-sonarscanner begin /k:"DFE-Digital_get-information-about-schools" /o:"dfe-digital" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths="**\TestResults\**\*.xml"
msbuild.exe EdubaseWeb.sln /t:Rebuild /p:platform="Any CPU" /p:configuration="Release"
if ($LASTEXITCODE -ne 0) { $env:EXIT_CODE=$LASTEXITCODE }
vstest.console.exe /Enablecodecoverage /Collect:"Code Coverage;Format=Xml" /ResultsDirectory:".\TestResults" .\Edubase.CommonUnitTests\bin\Release\Edubase.CommonUnitTests.dll
if ($LASTEXITCODE -ne 0) {
Write-Host "CommonUnitTests failed with exit code $LASTEXITCODE"
$env:EXIT_CODE=$LASTEXITCODE
}
vstest.console.exe /Enablecodecoverage /Collect:"Code Coverage;Format=Xml" /ResultsDirectory:".\TestResults" .\Edubase.DataUnitTests\bin\Release\Edubase.DataUnitTests.dll
if ($LASTEXITCODE -ne 0) {
Write-Host "DataUnitTests failed with exit code $LASTEXITCODE"
$env:EXIT_CODE=$LASTEXITCODE
}
vstest.console.exe /Enablecodecoverage /Collect:"Code Coverage;Format=Xml" /ResultsDirectory:".\TestResults" .\Edubase.ServicesUnitTests\bin\Release\Edubase.ServicesUnitTests.dll
if ($LASTEXITCODE -ne 0) {
Write-Host "ServicesUnitTests failed with exit code $LASTEXITCODE"
$env:EXIT_CODE=$LASTEXITCODE
}
vstest.console.exe /Enablecodecoverage /Collect:"Code Coverage;Format=Xml" /ResultsDirectory:".\TestResults" .\Edubase.Web.ResourcesUnitTests\bin\Release\net48\Edubase.Web.ResourcesUnitTests.dll
if ($LASTEXITCODE -ne 0) {
Write-Host "Web.ResourcesUnitTests failed with exit code $LASTEXITCODE"
$env:EXIT_CODE=$LASTEXITCODE
}
vstest.console.exe /Enablecodecoverage /Collect:"Code Coverage;Format=Xml" /ResultsDirectory:".\TestResults" .\Edubase.Web.UIUnitTests\bin\Release\net48\Edubase.Web.UIUnitTests.dll
if ($LASTEXITCODE -ne 0) {
Write-Host "Web.UIUnitTests failed with exit code $LASTEXITCODE"
$env:EXIT_CODE=$LASTEXITCODE
}
..\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
## If any test errors, exit the job step and fail the build
## Note each individual command doesn't seem to cause the job step to return with a non-zero exit code
## Also note that if there are multiple errors returned from multiple test commands, only the last one will be stored in EXIT_CODE
if ($env:EXIT_CODE -ne 0) {
Write-Host "Test failures detected. Exiting with code $env:EXIT_CODE"
exit $env:EXIT_CODE
}
- name: Upload dotnet test results
uses: actions/[email protected]
with:
name: dotnet-results-${{ env.DOTNET_VERSION }}
path: ./Web/TestResults
if: ${{ always() }}