forked from sakura-editor/sakura
-
Notifications
You must be signed in to change notification settings - Fork 0
149 lines (135 loc) · 5.21 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
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
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'
- 'ci/**/*'
- .gitignore
- .editorconfig
- appveyor.yml
- azure-pipelines.yml
pull_request_target:
types: [opened, synchronize]
paths-ignore:
- '**/*.md'
- 'ci/**/*'
- .gitignore
- .editorconfig
- appveyor.yml
- azure-pipelines.yml
schedule:
- cron: '45 7 * * FRI'
# 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
SONAR_QUBE_VERSION: '4.7.0.2747'
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: '${{ github.event.pull_request.head.sha }}'
fetch-depth: 0
- 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
}
New-Item -Path .sonar -ItemType Directory
- name: Cache Sonar Analysis
uses: actions/cache@v2
with:
path: |
.sonar\cache
key:
sonar-cache-${{ env.SONAR_QUBE_VERSION }}-${{ github.sha }}
restore-keys:
sonar-cache-${{ env.SONAR_QUBE_VERSION }}-${{ env.BASE_SHA }}
- name: Setup MSBuild
uses: microsoft/setup-msbuild@v1
- name: Fetch Build-Wrapper
working-directory: ${{ github.workspace }}\.sonar
run: |
Invoke-WebRequest -OutFile build-wrapper-win-x86.zip https://sonarcloud.io/static/cpp/build-wrapper-win-x86.zip
7z rn build-wrapper-win-x86.zip build-wrapper-win-x86 build-wrapper
7z x build-wrapper-win-x86.zip
- name: Build with Build-Wrapper
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
if: env.SONAR_TOKEN
run: .sonar\build-wrapper\build-wrapper-win-x86-64.exe
--out-dir bw-output
MsBuild.exe
/p:Platform=${{ env.BUILD_PLATFORM }}
/p:Configuration=${{ env.BUILD_CONFIGURATION }}
/t:ReBuild
- name: Install OpenCppCoverage with XmlExporter
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
if: env.SONAR_TOKEN
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: Run Tests
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
if: env.SONAR_TOKEN
run: |
$env:CMD_TESTS1 = $(Get-ChildItem -Recurse tests1.exe)[0].FullName
OpenCppCoverage.exe `
--export_type xml:tests1-coverage.xml `
--modules $env:CMD_TESTS1 `
--sources ${{ github.workspace }} `
--excluded_sources ${{ github.workspace }}\tests\googletest `
--working_dir .\${{ env.BUILD_PLATFORM }}\${{ env.BUILD_CONFIGURATION }} `
--cover_children `
-- `
$env:CMD_TESTS1 `
--gtest_output=xml:${{ github.workspace }}\tests1-googletest.xml
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 17
- name: Fetch SonarScanner
working-directory: ${{ github.workspace }}\.sonar
run: |
Invoke-WebRequest -OutFile sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${{ env.SONAR_QUBE_VERSION }}.zip
7z rn sonar-scanner.zip sonar-scanner-${{ env.SONAR_QUBE_VERSION }} scanner
7z x sonar-scanner.zip
- 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'
}
.\.sonar\scanner\bin\sonar-scanner.bat `
-D"sonar.organization=${{ github.repository_owner }}" `
-D"sonar.projectKey=$('${{ github.repository }}' -replace '/', '_')" `
-D"sonar.host.url=https://sonarcloud.io" `
-D"sonar.sourceEncoding=UTF-8" `
-D"sonar.sources=." `
-D"sonar.cfamily.build-wrapper-output=bw-output" `
-D"sonar.cfamily.cppunit.reportPath=tests1-googletest.xml" `
-D"sonar.python.version=3" `
-D"sonar.coverage.exclusions=help\**\*.js,tests\unittests\coverage.cpp,tests\stubs\**\*.cpp,tools\**\*.js" `
-D"sonar.coverageReportPaths=tests1-coverage.xml" `
-D"sonar.exclusions=.sonar\**\*,build\**\*,bw-output\**\*,HeaderMake\**\*,tests\googletest\**\,**\test-*,tests\stubs\**\*,tests*-*.xml*"