-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
242 lines (230 loc) · 9.25 KB
/
action.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
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
name: "Warren - Run Tests and SonarQube Analysis"
description: "Run .NET Tests and sends the result to SonarQube"
branding:
icon: "activity"
color: "red"
inputs:
sonar-token:
description: "SonarQube token"
required: true
sonar-host-url:
description: "SonarQube URL"
required: true
sonar-project-key:
description: "SonarQube project key"
required: true
sonar-organization:
description: "SonarQube organization name"
required: true
solution:
description: "Solution file name without the .sln extension (do not use with project input parameter)"
required: false
default: ""
project:
description: "The path of test project to be tested (do not use with solution input parameter)"
required: false
default: ""
code-exclusions:
description: "The matching path for code that should be excluded from coverage (absolute, relative and pattern paths are acceptable)"
required: false
default: ""
pull-request:
description: "Boolean to change behavior of dotnet-sonarscanner for pull requests"
required: true
branch-name:
description: "Branch name to be displayed on SonarQube (required when pull-request is false)"
required: false
pull-request-number:
description: "The number of the pull request (required when pull-request is true)"
required: false
pull-request-base:
description: "The target branch name from the pull request (required when pull-request is true)"
required: false
pull-request-head:
description: "The target source name from the pull request (required when pull-request is true)"
required: false
quality-gate-wait:
description: "Poll to SonarQube instance until the Quality Gate status is available"
required: false
default: true
verbosity:
description: "Verbosity level for dotnet test command"
required: false
default: m
enable-dotnet-restore:
description: "Runs dotnet restore before dotnet test"
required: false
default: true
dotnet-restore-flags:
description: "Add flags to dotnet restore command"
required: false
default: ""
enable-dotnet-build:
description: "Runs dotnet build with no restore before dotnet test"
required: false
default: true
dotnet-build-flags:
description: "Add flags to dotnet build command"
required: false
default: "--no-restore"
dotnet-test-flags:
description: "Add flags to dotnet test command"
required: false
default: "--no-build --no-restore"
runs:
using: composite
steps:
- name: Install JDK
uses: actions/setup-java@v4
with:
distribution: "microsoft"
java-version: "17"
- name: Create Tool Directory
shell: bash
run: mkdir -p $HOME/sonar-scanner
- name: Install SonarQube Scanner
shell: bash
run: dotnet tool install dotnet-sonarscanner --tool-path $HOME/sonar-scanner || true
- name: Begin SonarQube Scan for Pull Request
if: ${{ inputs.pull-request == 'true' && inputs.code-exclusions != '' }}
shell: bash
env:
SONAR_TOKEN: ${{ inputs.sonar-token }}
SONAR_HOST_URL: ${{ inputs.sonar-host-url }}
SONAR_PROJECT_KEY: ${{ inputs.sonar-project-key }}
SONAR_ORGANIZATION: ${{ inputs.sonar-organization }}
CODE_EXCLUSIONS: ${{ inputs.code-exclusions }}
PR_NUMBER: ${{ inputs.pull-request-number }}
PR_BASE: ${{ inputs.pull-request-base }}
PR_HEAD: ${{ inputs.pull-request-head }}
COVERAGE_REPORTS_DIR: ${{ github.workspace }}/reports
QUALITY_GATE_WAIT: ${{inputs.quality-gate-wait }}
run: |
$HOME/sonar-scanner/dotnet-sonarscanner begin \
/k:"$SONAR_PROJECT_KEY" \
/o:"$SONAR_ORGANIZATION" \
/d:sonar.pullrequest.key="$PR_NUMBER" \
/d:sonar.pullrequest.branch="$PR_HEAD" \
/d:sonar.pullrequest.base="$PR_BASE" \
/d:sonar.login="$SONAR_TOKEN" \
/d:sonar.host.url="$SONAR_HOST_URL" \
/d:sonar.qualitygate.wait=$QUALITY_GATE_WAIT \
/d:sonar.coverage.exclusions="$CODE_EXCLUSIONS" \
/d:sonar.cs.opencover.reportsPaths="$COVERAGE_REPORTS_DIR/**/*.opencover.xml"
- name: Begin SonarQube Scan for Pull Request
if: ${{ inputs.pull-request == 'true' && inputs.code-exclusions == '' }}
shell: bash
env:
SONAR_TOKEN: ${{ inputs.sonar-token }}
SONAR_HOST_URL: ${{ inputs.sonar-host-url }}
SONAR_PROJECT_KEY: ${{ inputs.sonar-project-key }}
SONAR_ORGANIZATION: ${{ inputs.sonar-organization }}
PR_NUMBER: ${{ inputs.pull-request-number }}
PR_BASE: ${{ inputs.pull-request-base }}
PR_HEAD: ${{ inputs.pull-request-head }}
COVERAGE_REPORTS_DIR: ${{ github.workspace }}/reports
QUALITY_GATE_WAIT: ${{inputs.quality-gate-wait }}
run: |
$HOME/sonar-scanner/dotnet-sonarscanner begin \
/k:"$SONAR_PROJECT_KEY" \
/o:"$SONAR_ORGANIZATION" \
/d:sonar.pullrequest.key="$PR_NUMBER" \
/d:sonar.pullrequest.branch="$PR_HEAD" \
/d:sonar.pullrequest.base="$PR_BASE" \
/d:sonar.login="$SONAR_TOKEN" \
/d:sonar.host.url="$SONAR_HOST_URL" \
/d:sonar.qualitygate.wait=$QUALITY_GATE_WAIT \
/d:sonar.cs.opencover.reportsPaths="$COVERAGE_REPORTS_DIR/**/*.opencover.xml"
- name: Begin SonarQube Scan
if: ${{ inputs.pull-request == 'false' && inputs.code-exclusions != '' }}
shell: bash
env:
SONAR_TOKEN: ${{ inputs.sonar-token }}
SONAR_HOST_URL: ${{ inputs.sonar-host-url }}
SONAR_PROJECT_KEY: ${{ inputs.sonar-project-key }}
SONAR_ORGANIZATION: ${{ inputs.sonar-organization }}
CODE_EXCLUSIONS: ${{ inputs.code-exclusions }}
BRANCH_NAME: ${{ inputs.branch-name }}
COVERAGE_REPORTS_DIR: ${{ github.workspace }}/reports
QUALITY_GATE_WAIT: ${{inputs.quality-gate-wait }}
run: |
$HOME/sonar-scanner/dotnet-sonarscanner begin \
/k:"$SONAR_PROJECT_KEY" \
/o:"$SONAR_ORGANIZATION" \
/d:sonar.branch.name="$BRANCH_NAME" \
/d:sonar.login="$SONAR_TOKEN" \
/d:sonar.host.url="$SONAR_HOST_URL" \
/d:sonar.coverage.exclusions="$CODE_EXCLUSIONS" \
/d:sonar.qualitygate.wait=$QUALITY_GATE_WAIT \
/d:sonar.cs.opencover.reportsPaths="$COVERAGE_REPORTS_DIR/**/*.opencover.xml"
- name: Begin SonarQube Scan
if: ${{ inputs.pull-request == 'false' && inputs.code-exclusions == '' }}
shell: bash
env:
SONAR_TOKEN: ${{ inputs.sonar-token }}
SONAR_HOST_URL: ${{ inputs.sonar-host-url }}
SONAR_PROJECT_KEY: ${{ inputs.sonar-project-key }}
SONAR_ORGANIZATION: ${{ inputs.sonar-organization }}
BRANCH_NAME: ${{ inputs.branch-name }}
COVERAGE_REPORTS_DIR: ${{ github.workspace }}/reports
QUALITY_GATE_WAIT: ${{inputs.quality-gate-wait }}
run: |
$HOME/sonar-scanner/dotnet-sonarscanner begin \
/k:"$SONAR_PROJECT_KEY" \
/o:"$SONAR_ORGANIZATION" \
/d:sonar.branch.name="$BRANCH_NAME" \
/d:sonar.login="$SONAR_TOKEN" \
/d:sonar.host.url="$SONAR_HOST_URL" \
/d:sonar.qualitygate.wait=$QUALITY_GATE_WAIT \
/d:sonar.cs.opencover.reportsPaths="$COVERAGE_REPORTS_DIR/**/*.opencover.xml"
- name: Restore
if: ${{ inputs.enable-dotnet-restore == 'true' }}
shell: bash
env:
FLAGS: ${{ inputs.dotnet-restore-flags }}
run: |
dotnet restore $FLAGS
- name: Build
if: ${{ inputs.enable-dotnet-build == 'true' }}
shell: bash
env:
FLAGS: ${{ inputs.dotnet-build-flags }}
run: |
dotnet build $FLAGS
- name: Run tests
if: ${{ inputs.solution != '' && inputs.project == '' }}
shell: bash
env:
SOLUTION: ${{ inputs.solution }}
COVERAGE_REPORTS_DIR: ${{ github.workspace }}/reports
FLAGS: ${{ inputs.dotnet-test-flags }}
VERBOSITY: ${{ inputs.verbosity }}
run: |
dotnet test $SOLUTION.sln \
--collect:"XPlat Code Coverage" \
--results-directory:"$COVERAGE_REPORTS_DIR/" \
$FLAGS \
--logger "GitHubActions;report-warnings=false" \
--verbosity $VERBOSITY -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover \
DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.ExcludeByAttribute=CompilerGeneratedAttribute
- name: Run tests
if: ${{ inputs.solution == '' && inputs.project != '' }}
shell: bash
env:
PROJECT: ${{ inputs.project }}
COVERAGE_REPORTS_DIR: ${{ github.workspace }}/reports
FLAGS: ${{ inputs.dotnet-test-flags }}
VERBOSITY: ${{ inputs.verbosity }}
run: |
dotnet test $PROJECT \
--collect:"XPlat Code Coverage" \
--results-directory:"$COVERAGE_REPORTS_DIR/" \
$FLAGS \
--logger "GitHubActions;report-warnings=false" \
--verbosity $VERBOSITY -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover \
DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.ExcludeByAttribute=CompilerGeneratedAttribute
- name: End Sonar Scan
shell: bash
env:
SONAR_TOKEN: ${{ inputs.sonar-token }}
run: $HOME/sonar-scanner/dotnet-sonarscanner end /d:sonar.login="$SONAR_TOKEN"