-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
105 lines (103 loc) · 3.61 KB
/
action.yml
File metadata and controls
105 lines (103 loc) · 3.61 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
name: Build, Test & Analyze
description: Builds, runs tests on a .NET codebase and run analysis with Sonar
inputs:
dotnet-test-args:
description: .NET test arguments
required: false
default: ""
java-version:
description: Java version that will be installed (for Sonar CLI)
required: false
default: "21"
sonar-exclusions:
description: Files or directories that should be excluded from Sonar analysis
required: false
default: "**/node_modules/**"
report-folder:
description: Folder where report files will be generated
required: false
default: report
sonar-host-url:
description: Sonar host URL
required: false
default: ""
sonar-organization:
description: Sonar organization
required: false
default: ""
sonar-project-key:
description: Sonar project key
required: false
default: ""
sonar-project-name:
description: Sonar project name
required: false
default: ""
sonar-token:
description: Sonar token for login
required: false
default: ""
runs:
using: "composite"
steps:
- name: Set up JDK for Sonar
uses: actions/setup-java@v4
with:
java-version: ${{ inputs.java-version }}
distribution: "zulu"
- name: Cache Sonar packages
uses: actions/cache@v4
with:
path: ~/sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Sonar scanner
id: cache-sonar-scanner
uses: actions/cache@v4
with:
path: ./.sonar/scanner
key: ${{ runner.os }}-sonar-scanner
restore-keys: ${{ runner.os }}-sonar-scanner
- name: Install Sonar scanner
if: ${{ steps.cache-sonar-scanner.outputs.cache-hit != 'true' }}
run: |
mkdir -p ./.sonar/scanner
dotnet tool update dotnet-sonarscanner --tool-path ./.sonar/scanner
shell: bash
- name: Start code analysis
run: |
./.sonar/scanner/dotnet-sonarscanner begin \
/k:"${{ inputs.sonar-project-key }}" \
/o:"${{ inputs.sonar-organization }}" \
/n:"${{ inputs.sonar-project-name }}" \
/d:sonar.token="${{ inputs.sonar-token}}" \
/d:sonar.host.url="${{ inputs.sonar-host-url }}" \
/d:sonar.cpd.exclusions="**/*Generated*.cs,${{ inputs.report-folder }}/**" \
/d:sonar.exclusions="${{ inputs.report-folder }}/**,${{ inputs.sonar-exclusions }}" \
/d:sonar.coverageReportPaths="${{ inputs.report-folder }}/SonarQube.xml" \
/d:sonar.cs.vstest.reportsPaths="${{ inputs.report-folder }}/TestResults/*.trx"
shell: bash
- name: Build .NET solution
run: dotnet build --no-restore --configuration Debug
shell: bash
env:
BUILD_SOURCEBRANCHNAME: ${{ github.ref_name }}
BUILD_BUILDID: ${{ github.run_id }}
- name: Run tests
run: |
dotnet test --no-build --verbosity normal --configuration Debug \
--results-directory "${{ inputs.report-folder }}/TestResults" \
${{ inputs.dotnet-test-args }}
shell: bash
env:
ASPNETCORE_ENVIRONMENT: Development
- name: Generate test report
if: ${{ always() && hashFiles(format('{0}/TestResults/*.cobertura.xml', inputs.report-folder)) != '' }}
run: |
reportgenerator "-reports:${{ inputs.report-folder }}/TestResults/*.cobertura.xml" \
"-targetdir:${{ inputs.report-folder }}" \
"-reporttypes:Cobertura;Html;TextSummary;SonarQube"
shell: bash
- name: Complete code analysis
run: ./.sonar/scanner/dotnet-sonarscanner end /d:sonar.token="${{ inputs.sonar-token }}"
shell: bash