-
Notifications
You must be signed in to change notification settings - Fork 0
189 lines (172 loc) · 6.93 KB
/
Copy pathdotnetCi.yml
File metadata and controls
189 lines (172 loc) · 6.93 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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
name: .NET CI
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
jobs:
# Summary:
#
# * Installs and configures the environment
# * Builds the solution with SonarScanner analysis
# * In Debug configuration
# * Runs all .NET and JS tests
# * In Debug configuration (.NET tests)
# * Producing code coverage reports, consumed by SonarScanner
# * WebDriver-based tests use a locally-running Chrome browser ONLY
# * Packages test results as build artifacts
# * Builds & packs the solution in Release configuration
# * Uploads the Release config packages as build artifacts
build_test_and_pack:
name: Build, test & package
runs-on: ubuntu-slim
env:
RunNumber: ${{ github.run_number }}.${{ github.run_attempt }}
VersionSuffix: ci.${{ github.run_number }}
SonarCloudProject: csf-dev_CSF.Screenplay
SonarCloudUsername: craigfowler-github
SonarCloudUrl: https://sonarcloud.io
Configuration: Debug
Tfm: net8.0
DotnetVersion: 8.0.x
SonarCloudSecretKey: ${{ secrets.SONARCLOUDKEY }}
BranchName: ${{ github.event_name == 'pull_request' && github.base_ref || github.ref_name }}
BranchParam: ${{ github.event_name == 'pull_request' && 'sonar.pullrequest.branch' || 'sonar.branch.name' }}
PullRequestParam: ${{ github.event_name == 'pull_request' && format('/d:sonar.pullrequest.key={0}', github.event.number) || '' }}
DISPLAY: :99
steps:
- name: Checkout
uses: actions/checkout@v4
# Install build dependencies
- name: Add .NET global tools location to PATH
run: echo "$HOME/.dotnet/tools" >> "$GITHUB_PATH"
- name: Install .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DotnetVersion }}
- name: Install SonarScanner
run: dotnet tool install --global dotnet-sonarscanner
- name: Install Coverlet console
run: dotnet tool install --global coverlet.console
- name: Install DocFX
run: dotnet tool install --global docfx
- name: Install Node.js for building JSON-to-HTML report converter
uses: actions/setup-node@v6.2.0
- name: Install Java JDK for SonarScanner
uses: actions/setup-java@v5.1.0
with:
java-version: 21
distribution: 'zulu'
- name: Install GUI packages so Chrome may run
run: |
sudo apt-get update
sudo apt install -y xorg xvfb gtk2-engines-pixbuf dbus-x11 xfonts-base xfonts-100dpi xfonts-75dpi xfonts-cyrillic xfonts-scalable psmisc
# Environment setup pre-build
- name: Setup Selenium Manager config
run: |
mkdir ~/.cache/selenium
cp Tools/se-config.toml ~/.cache/selenium
- name: Start an Xvfb display so Chrome may run
run: Xvfb -ac $DISPLAY -screen 0 1280x1024x16 &
- name: Restore .NET packages
run: dotnet restore
- name: Restore Node modules
run: |
cd CSF.Screenplay.JsonToHtmlReport.Template/src
npm ci
cd ../..
# Build and test the solution
- name: Start SonarScanner
run: >
dotnet sonarscanner begin
/k:${{ env.SonarCloudProject }}
/v:GitHub_build_${{ env.RunNumber }}
/o:${{ env.SonarCloudUsername }}
/d:sonar.host.url=${{ env.SonarCloudUrl }}
/d:sonar.token=${{ env.SonarCloudSecretKey }}
/d:${{ env.BranchParam }}=${{ env.BranchName }} ${{ env.PullRequestParam }}
/d:sonar.javascript.lcov.reportPaths=CSF.Screenplay.JsonToHtmlReport.Template/src/TestResults/lcov.info
/s:$PWD/.sonarqube-analysisproperties.xml
- name: Build the solution
run: dotnet build -c ${{ env.Configuration }} --no-incremental
- name: Run .NET tests with coverage
id: dotnet_tests
continue-on-error: true
run: |
for proj in Tests/*.Tests
do
projNameArray=(${proj//// })
projName=${projNameArray[1]}
assemblyPath=$proj/bin/$Configuration/$Tfm/$projName.dll
coverlet "$assemblyPath" --target "dotnet" --targetargs "test $proj -c $Configuration --no-build --logger:nunit --test-adapter-path:." -f=opencover -o="TestResults/$projName.opencover.xml"
if [ $? -ne 0 ]
then
echo "failures=true" >> $GITHUB_OUTPUT
fi
done
- name: Run JavaScript tests with coverage
id: js_tests
continue-on-error: true
run: |
cd CSF.Screenplay.JsonToHtmlReport.Template/src
npm test
if [ $? -ne 0 ]
then
echo "failures=true" >> $GITHUB_OUTPUT
fi
cd ../..
# Post-test tasks (artifacts, overall status)
- name: Stop SonarScanner
run:
dotnet sonarscanner end /d:sonar.token=${{ env.SonarCloudSecretKey }}
- name: Gracefully stop Xvfb
run: killall Xvfb
continue-on-error: true
- name: Upload test results artifacts
uses: actions/upload-artifact@v4
with:
name: NUnit test results
path: Tests/*.Tests/**/TestResults.xml
- name: Upload Screenplay JSON report artifact
uses: actions/upload-artifact@v4
with:
name: Screenplay JSON reports
path: Tests/**/ScreenplayReport_*.json
- name: Convert Screenplay reports to HTML
continue-on-error: true
run: |
for report in $(find Tests/ -type f -name "ScreenplayReport_*.json")
do
reportDir=$(dirname "$report")
outputFile="$reportDir/ScreenplayReport.html"
dotnet run --no-build --framework $Tfm --project CSF.Screenplay.JsonToHtmlReport --ReportPath "$report" --OutputPath "$outputFile"
done
- name: Upload Screenplay HTML report artifact
uses: actions/upload-artifact@v4
with:
name: Screenplay HTML reports
path: Tests/**/ScreenplayReport.html
- name: Fail the build if any test failures
if: ${{ steps.dotnet_tests.outputs.failures == 'true' || steps.js_tests.outputs.failures == 'true' }}
run: |
echo "Failing the build due to test failures"
exit 1
# Build the apps in release mode and publish artifacts
- name: Clean the solution ahead of building in release config
run: dotnet clean
- name: Build, in release configuration
run: dotnet pack -p:VersionSuffix=$VersionSuffix -o packages
- name: Upload build result artifacts
uses: actions/upload-artifact@v4
with:
name: Build results (NuGet)
path: packages/*.nupkg
- name: Build docs website
run: dotnet build -c Docs
- name: Upload docs website artifact
uses: actions/upload-artifact@v4
with:
name: Docs website
path: docs/**/*
# runBrowserTests:
# TODO: Use build-results artifacts and run tests on matrix of browsers