-
-
Notifications
You must be signed in to change notification settings - Fork 154
232 lines (191 loc) · 7.88 KB
/
code-qa-sonarcloud.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
name: Code QA - SonarCloud
on:
workflow_dispatch:
push:
branches:
- master
- sonarcloud-scan
tags:
- '*'
paths-ignore:
- '.github/**'
- '.gitignore'
- 'ChangeLog'
- 'COPYING'
- 'configure.scan'
- 'packaging/**'
- 'dev-tools/**'
# - '!dev-tools/libexec/get-release-*.sh'
- 'doc/**'
- 'etc/**'
- 'install/**'
- 'lib/*/IMPORT.defs'
- 'lib/*/LICENSE'
- 'README.md'
pull_request_target:
types:
- labeled
- opened
- synchronize
branches:
- master
paths-ignore:
- '.github/**'
- '.gitignore'
- 'ChangeLog'
- 'COPYING'
- 'configure.scan'
- 'packaging/**'
- 'dev-tools/**'
# - '!dev-tools/libexec/get-release-*.sh'
- 'doc/**'
- 'etc/**'
- 'install/**'
- 'lib/*/IMPORT.defs'
- 'lib/*/LICENSE'
- 'README.md'
jobs:
code-qa-sonarcloud:
name: Static code analysis submission
runs-on: ubuntu-20.04
container: ciready/ubuntu:20.04-ci-c
# For PRs, start the execution only when a specific label is added
if: |
(
(github.event_name == 'workflow_dispatch')
||
(github.event_name == 'push')
||
(
(github.event_name == 'pull_request_target')
&&
(
((github.event.pull_request.action == 'labeled') && contains(github.event.pull_request.labels.*.name, '/ci run additional tests'))
||
(github.actor == 'bostjan')
)
)
)
steps:
### Fetch the code
#
- name: Checkout branch ${{ github.ref }}
uses: actions/checkout@v2
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
if: |
(
(github.event_name == 'workflow_dispatch')
||
(github.event_name == 'push')
)
# In the PR-related operation mode, unlike regular github's CI workflows (where
# the workflow operates on a (preview) merge commit (as if PR was merged into the base
# branch already), we're operating on PR's HEAD (last commit of the PR) itself here.
- name: Checkout (preview) merge commit for PR ${{ github.event.pull_request.number }}
uses: actions/checkout@v2
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
repository: ${{github.event.pull_request.head.repo.full_name}}
ref: ${{github.event.pull_request.head.ref}}
if: ${{ github.event_name == 'pull_request_target' }}
# Work around the fix for CVE-2022-24765
- run: git config --global --add safe.directory $GITHUB_WORKSPACE || true
### Install build environment tools + unzip
#
- run: ./dev-tools/install-dev-software.sh
- run: DEBIAN_FRONTEND=noninteractive apt-get install -y unzip
### Bootstrap & configure the code
#
- run: ./bootstrap.sh
- run: ./configure --enable-option-checking=fatal --enable-everything --enable-code-coverage
### Install SonarCloud build & scan tools
#
- name: Install SonarCloud build wrapper
run: |
wget https://sonarcloud.io/static/cpp/build-wrapper-linux-x86.zip
unzip build-wrapper-linux-x86.zip
working-directory: /opt
### Build with SonarCloud wrapper
#
- name: Build with SonarCloud build wrapper
run: |
/opt/build-wrapper-linux-x86/build-wrapper-linux-x86-64 \
--out-dir ../snoopy-sonarcloud-build-wrapper-output \
make -j4
### Generate coverage info
#
# No need to run `make check`, as the test suite is started by
# the `coverage` target in Makefile.
#
- name: Run tests and generate coverage information
run: make coverage
### Install SonarCloud scanner
#
# The installation of the scanner is deferred to this point for security reasons,
# as the build is done on a PR code that can easily mess with the scanner
# installation to reveal the tokens.
#
- name: Install SonarClound scanner
run: |
rm -rf sonar-scanner*
# Temporarily disabling using the latest SonarScanner version (5.0.0.2966),
# as it is producing the following error:
# java.io.IOException: Cannot run program ".../.scannerwork/.sonartmp/5786710878849275698/subprocess" (in directory "..."): error=13, Permission denied
#
#LATEST_SONAR_SCANNER_VERSION=`wget -q -O - --header "Accept: application/vnd.github.v3+json" https://api.github.com/repos/SonarSource/sonar-scanner-cli/releases/latest | grep '"tag_name"' | head -n1 | cut -d '"' -f4`
#
# Replacing it with this static definition for now:
LATEST_SONAR_SCANNER_VERSION="4.8.0.2856"
echo "Got the latest Sonar Scanner version: $LATEST_SONAR_SCANNER_VERSION"
LATEST_SONAR_SCANNER_ZIP="sonar-scanner-cli-$LATEST_SONAR_SCANNER_VERSION-linux.zip"
LATEST_SONAR_SCANNER_DIR="sonar-scanner-$LATEST_SONAR_SCANNER_VERSION-linux"
wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/$LATEST_SONAR_SCANNER_ZIP
unzip $LATEST_SONAR_SCANNER_ZIP
ln -s $LATEST_SONAR_SCANNER_DIR/bin/sonar-scanner /opt/sonar-scanner
working-directory: /opt
### Trigger the SonarCloudscan and submission
#
- name: Scan and submit to SonarCloud - on push
run: |
CURRENT_BRANCH_NAME=`git branch --show-current`
SONARCLOUD_TAG=`./dev-tools/libexec/get-sonarcloud-tag.sh`
/opt/sonar-scanner \
-Dsonar.organization=a2o \
-Dsonar.projectKey=snoopy \
-Dsonar.sources=. \
-Dsonar.coverage.exclusions=tests/**/*,src/entrypoint/execve-wrapper* \
-Dsonar.cpd.exclusions=tests/**/*,src/entrypoint/* \
-Dsonar.branch.name=$CURRENT_BRANCH_NAME \
-Dsonar.projectVersion=$SONARCLOUD_TAG \
-Dsonar.cfamily.build-wrapper-output=../snoopy-sonarcloud-build-wrapper-output \
-Dsonar.cfamily.gcov.reportsPath=. \
-Dsonar.host.url=https://sonarcloud.io
echo "Submission tag: $SONARCLOUD_TAG (branch: $CURRENT_BRANCH_NAME)"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
if: ${{ github.event_name == 'push' }}
- name: Scan and submit to SonarCloud - on PR
run: |
CURRENT_BRANCH_NAME=`git branch --show-current`
SONARCLOUD_TAG=`./dev-tools/libexec/get-sonarcloud-tag.sh`
/opt/sonar-scanner \
-Dsonar.organization=a2o \
-Dsonar.projectKey=snoopy \
-Dsonar.sources=. \
-Dsonar.coverage.exclusions=tests/**/*,src/entrypoint/execve-wrapper* \
-Dsonar.cpd.exclusions=tests/**/*,src/entrypoint/* \
-Dsonar.pullrequest.provider=github \
-Dsonar.pullrequest.key=${{ github.event.pull_request.number }} \
-Dsonar.pullrequest.branch=${{github.event.pull_request.head.repo.owner.login}}:$PR_HEAD_REF \
-Dsonar.pullrequest.github.repository=${{ github.event.pull_request.base.repo.full_name }} \
-Dsonar.pullrequest.base=${{ github.event.pull_request.base.ref }} \
-Dsonar.cfamily.build-wrapper-output=../snoopy-sonarcloud-build-wrapper-output \
-Dsonar.cfamily.gcov.reportsPath=. \
-Dsonar.host.url=https://sonarcloud.io
echo "Submission tag: $SONARCLOUD_TAG (branch: $CURRENT_BRANCH_NAME)"
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
PR_HEAD_REF: ${{ github.event.pull_request.head.ref }}
if: ${{ github.event_name == 'pull_request_target' }}