This repository has been archived by the owner on Sep 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
98 lines (88 loc) · 3.02 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
name: dotnet-sonar-scanner
author: 'Peter Jokumsen'
description: 'Use SonarScanner to analyze .NET project and publish to a sonarcloud project.'
branding:
icon: 'upload-cloud'
color: 'blue'
inputs:
sonar-project-key:
description: 'Key for Sonar project'
required: true
sonar-org-key:
description: 'Key for Sonar organisation'
required: true
token:
description: 'GitHub token'
required: true
sonar-token:
description: 'Sonar token to use for authenticating with Sonar'
working-directory:
description: 'Directory to execute `dotnet build` in'
required: false
default: '.'
dotnet-version:
description: '.NET SDK to be used'
required: false
default: '6.0.x'
project-version:
description: 'Project version to use for scan'
required: false
default: ''
checkout:
description: 'Should action perform checkout of repo itself'
required: false
default: 'true'
runs:
using: 'composite'
steps:
- uses: actions/setup-java@v3
name: Set up JDK 11
with:
distribution: 'zulu'
java-version: '11'
- uses: actions/setup-dotnet@v3
name: Setup dotnet
with:
dotnet-version: ${{ inputs.dotnet-version }}
- uses: actions/checkout@v3
if: inputs.checkout == 'true'
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- uses: actions/cache@v3
name: Cache SonarCloud packages
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- uses: actions/cache@v3
name: Cache SonarCloud scanner
id: cache-sonar-scanner
with:
path: ${{ inputs.working-directory }}/.sonar/scanner
key: ${{ runner.os }}-sonar-scanner
restore-keys: ${{ runner.os }}-sonar-scanner
- shell: pwsh
name: Install SonarCloud scanner
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
run: |
New-Item -Path ${{ inputs.working-directory }}/.sonar/scanner -ItemType Directory
dotnet tool update dotnet-sonarscanner --tool-path ${{ inputs.working-directory }}/.sonar/scanner
- shell: pwsh
name: Build and analyze
working-directory: ${{ inputs.working-directory }}
env:
GITHUB_TOKEN: ${{ inputs.token }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ inputs.sonar-token }}
run: |
dotnet tool update --global dotnet-coverage
./.sonar/scanner/dotnet-sonarscanner begin `
/k:"${{ inputs.sonar-project-key }}" `
/o:"${{ inputs.sonar-org-key }}" `
/d:sonar.login="${{ inputs.sonar-token }}" `
/d:sonar.host.url="https://sonarcloud.io" `
/d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml `
/v:${{ inputs.project-version }}
dotnet build
dotnet-coverage collect 'dotnet test' -f xml -o 'coverage.xml'
./.sonar/scanner/dotnet-sonarscanner end `
/d:sonar.login="${{ inputs.sonar-token }}"