-
Notifications
You must be signed in to change notification settings - Fork 163
112 lines (97 loc) · 3.83 KB
/
sonarscan.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
name: SonarCloud
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
workflow_dispatch:
push:
paths-ignore:
- '**/*.md'
- .gitignore
- .editorconfig
pull_request_target:
types: [opened, synchronize]
paths-ignore:
- '**/*.md'
- .gitignore
- .editorconfig
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
sonar:
name: Scan
runs-on: windows-latest
env:
BUILD_PLATFORM: x64
BUILD_CONFIGURATION: Debug
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: '${{ github.event.pull_request.head.sha }}'
- name: Setup environment variables
run: |
echo "SONAR_USER_HOME=${{ github.workspace }}" >> $env:GITHUB_ENV
if ('${{ env.GITHUB_BASE_REF }}' -ne '')
{
echo "BASE_SHA=$(git show -s --format=%H ${{ env.GITHUB_BASE_REF }})" >> $env:GITHUB_ENV
}
echo "NUM_VSVERSION=$($(vswhere -latest -property catalog_productDisplayVersion) -replace '^(\d+)\..+$', '$1')" >> $env:GITHUB_ENV
echo "SCANNER_CLI_VERSION=$(Get-Content tools\SCANNER_CLI_VERSION)" >> $env:GITHUB_ENV
New-Item -Path .sonar -ItemType Directory
- name: Setup MSBuild
uses: microsoft/setup-msbuild@v1
- name: Setup Python3
uses: actions/setup-python@v4
with:
python-version: '3.x'
cache: 'pip' # caching pip dependencies
- run: pip install -r requirements.txt
- name: Install OpenCppCoverage with XmlExporter
working-directory: ${{ runner.temp }}
run: |
choco install OpenCppCoverage -y
Invoke-WebRequest -OutFile XmlExporter-x64.zip https://github.com/berryzplus/XmlExporter/releases/download/v1.0.0/XmlExporter-x64.zip
7z e XmlExporter-x64.zip
Move-Item -Path XmlExporter.dll -Destination "C:\Program Files\OpenCppCoverage\Plugins\Exporter\xml.dll"
echo "C:\Program Files\OpenCppCoverage" >> $env:GITHUB_PATH
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 11
- name: Cache Sonar Analysis
uses: actions/cache@v3
with:
path: |
.sonar\cache
key:
sonar-cache-${{ env.SCANNER_CLI_VERSION }}-${{ github.sha }}
restore-keys:
sonar-cache-${{ env.SCANNER_CLI_VERSION }}-${{ env.BASE_SHA }}
- name: Make BuildDependencies
working-directory: ${{ github.workspace }}
run: .\tools\BuildDependencies.bat
- name: Build with Build-Wrapper
run: .\tools\Build-SakuraEditorWithBuildWrapper.ps1
- name: Run Tests
run: .\tools\Run-Tests.ps1
- name: Fetch SonarScanner
run: .\tools\Fetch-SonarScanner.ps1
- name: Analyze with SonarScanner
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
if: env.SONAR_TOKEN
run: |
if ('${{ github.event_name }}' -eq 'pull_request_target')
{
$env:GITHUB_EVENT_NAME = 'pull_request'
$env:GITHUB_SHA = $(git show -s --format=%H)
$env:GITHUB_REF = 'refs/pull/${{ github.event.number }}/merge'
}
$GitHubRepository = "${{ github.repository }}"
$GitHubOrganization = $($GitHubRepository.Split('/')[0])
$GitHubProjectName = $($GitHubRepository.Split('/')[1])
echo "sonar.organization=$GitHubOrganization" >> ${{ github.workspace }}\.sonar\scanner\conf\sonar-scanner.properties
echo "sonar.projectKey=$GitHubProjectName" >> ${{ github.workspace }}\.sonar\scanner\conf\sonar-scanner.properties
echo "sonar.host.url=https://sonarcloud.io" >> ${{ github.workspace }}\.sonar\scanner\conf\sonar-scanner.properties
.\.sonar\scanner\bin\sonar-scanner.bat