-
Notifications
You must be signed in to change notification settings - Fork 0
141 lines (126 loc) · 4.78 KB
/
Copy pathdotnetCi.yml
File metadata and controls
141 lines (126 loc) · 4.78 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
name: .NET CI
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
jobs:
buildAndRunBasicTests:
runs-on: ubuntu-slim
env:
RunNumber: ${{ github.run_number }}.${{ github.run_attempt }}
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 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'
# 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: |
AnyFailures=0
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
AnyFailures=1
fi
done
echo "failures=$AnyFailures" >> $GITHUB_OUTPUT
- 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=1" >> $GITHUB_OUTPUT
else
echo "failures=0" >> $GITHUB_OUTPUT
fi
cd ../..
- name: Stop SonarScanner
run:
dotnet sonarscanner end /d:sonar.token=${{ env.SonarCloudSecretKey }}
- 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: Fail the build if any test failures
if: ${{ steps.dotnet_tests.outputs.failures == 1 || steps.js_tests.outputs.failures == 1 }}
run: |
echo "Failing the build due to test failures"
exit 1
# TODO: Convert Screenplay reports to HTML and upload as an artifact
# buildDocs:
# TODO: Build the docco site and package the result as an artifact, don't publish it
# publishDocs:
# TODO: Take the docco site artifact and publish it to master
# runBrowserTests:
# TODO: Use build-results artifacts and run tests on matrix of browsers