-
Notifications
You must be signed in to change notification settings - Fork 362
623 lines (517 loc) · 19.8 KB
/
cxx-ci.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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
#
# This workflow contains all necessary steps to build, test and release the cxx plugin
#
name: cxx plugin CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
defaults:
run:
# use bash only, makes it easier to write steps for Windows & Linux
shell: bash
jobs:
# -----------------------------------------------------------------------------------------------------------
# Verify SonarQube rule definition files with HTML Tidy
# - Do they contain valid HTML?
# -----------------------------------------------------------------------------------------------------------
verify-rules:
strategy:
matrix:
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
# checkout code
#
- name: Checkout repository
uses: actions/checkout@v4
# setup Python
#
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.7'
# setup Tidy
#
- name: Install xmllint
run: |
sudo apt-get update -y
sudo apt-get install -y libxml2-utils
- name: Install HTML Tidy
run: |
wget -nv --timeout=10 https://github.com/htacg/tidy-html5/releases/download/5.8.0/tidy-5.8.0-Linux-64bit.deb
sudo dpkg -i tidy-5.8.0-Linux-64bit.deb
# verify SonarQube rule definition files with HTML Tidy
#
- name: Verify rule files
run: bash ./cxx-sensors/src/tools/check_rules.sh
# -----------------------------------------------------------------------------------------------------------
# Going through the Maven cycles 'validate', 'compile', 'test', 'package' in all combinations to be supported
# The result of 'package' is uploaded as artifact for Ubuntu Linux Java 17 Temurin
# -----------------------------------------------------------------------------------------------------------
build-linux:
strategy:
matrix:
os: [ubuntu-latest]
java: [ '17' ]
distribution: [ 'temurin' ]
runs-on: ${{ matrix.os }}
steps:
# context information
#
- name: Dump GitHub Context
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: echo "$GITHUB_CONTEXT"
- name: Dump Matrix Context
env:
MATRIX_CONTEXT: ${{ toJSON(matrix) }}
run: echo "$MATRIX_CONTEXT"
# checkout code
# - to provide complete SCM information to the sonar scanner,
# all historical data for all branches and tags must be retrieved (fetch-depth: 0)
#
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
# setup Java
#
- name: Set up JDK Java ${{ matrix.java }} | ${{ matrix.distribution }} | ${{ matrix.os }}
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java }}
distribution: ${{ matrix.distribution }}
cache: maven
# read version number from POM
#
- name: get-pom-version
id: pom-version
uses: andreacomo/maven-gav-extractor@v2
# remove -SNAPSHOT from POM version (major.minor.patch-SNAPSHOT)
#
- run: echo "CXX_POM_VERSION=${{ steps.pom-version.outputs.version }}" >> $GITHUB_ENV
- run: echo "CXX_VERSION=${CXX_POM_VERSION%-*}" >> $GITHUB_ENV
# set version number of plugin JAR
# - 'major.minor.patch' and 'build' number from actions run number
#
- name: Sets the current project's version
run: mvn versions:set -DartifactId='cxx' -DnewVersion='${{ env.CXX_VERSION }}.${{ github.run_number }}'
- name: Dump environment variables
run: env
# Build and test with with Maven
# - use phase 'verify' to aggregate coverage results (part of integration-tests)
# - use phase 'install' to resolve dependencies (necessary for sonar-scanner)
#
- name: Build and test with Maven
run: mvn -B -e -V verify --file pom.xml
# create artifacts from Linux, Java 17 Temurin
#
- name: Collect JAR files
if: matrix.os == 'ubuntu-latest' && matrix.java == '17' && matrix.distribution == 'temurin'
run: |
mkdir staging
cp sonar-cxx-plugin/target/*.jar staging
cp cxx-sslr-toolkit/target/*.jar staging
rm -f staging/original-*.jar
rm -f staging/*-sources.jar
# upload JARs as artifact
#
- name: Packaging workflow data as artifacts
if: hashFiles('staging') != ''
uses: actions/upload-artifact@v4
with:
name: JAR_Files
path: staging
# -----------------------------------------------------------------------------------------------------------
# Going through the Maven cycles 'validate', 'compile', 'test', 'package' in all combinations to be supported
# The result of 'package' is uploaded as artifact for Ubuntu Linux Java 17 Temurin
# -----------------------------------------------------------------------------------------------------------
build-windows:
strategy:
matrix:
os: [windows-latest]
java: [ '17' ]
distribution: [ 'temurin' ]
runs-on: ${{ matrix.os }}
steps:
# context information
#
- name: Dump GitHub Context
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: echo "$GITHUB_CONTEXT"
- name: Dump Matrix Context
env:
MATRIX_CONTEXT: ${{ toJSON(matrix) }}
run: echo "$MATRIX_CONTEXT"
# checkout code
#
- name: Checkout repository
uses: actions/checkout@v4
# setup Java
#
- name: Set up JDK Java ${{ matrix.java }} | ${{ matrix.distribution }} | ${{ matrix.os }}
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java }}
distribution: ${{ matrix.distribution }}
cache: maven
# for tests on Windows we need a valid TMP folder
# - necessary for org.junit.rules.TemporaryFolder
#
- name: Adapt TMP folder on Windows OS
run: |
echo "TMP=$USERPROFILE\AppData\Local\Temp" >> $GITHUB_ENV
echo "TEMP=$USERPROFILE\AppData\Local\Temp" >> $GITHUB_ENV
- name: Dump environment variables
run: env
# Build and test with with Maven
# - use phase 'verify' to aggregate coverage results (part of integration-tests)
# - use phase 'install' to resolve dependencies (necessary for sonar-scanner)
#
- name: Build and test with with Maven
run: mvn -B -e -V verify --file pom.xml
# -----------------------------------------------------------------------------------------------------------
# Update SonarCloud results
# - Java 11 is no longer supported as scanner runtime environment
# -----------------------------------------------------------------------------------------------------------
sonar-cloud:
strategy:
matrix:
os: [ubuntu-latest]
java: [ '17' ]
distribution: [ 'temurin' ]
if: github.event_name == 'push'
runs-on: ${{ matrix.os }}
steps:
# context information
#
- name: Dump GitHub Context
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: echo "$GITHUB_CONTEXT"
- name: Dump Matrix Context
env:
MATRIX_CONTEXT: ${{ toJSON(matrix) }}
run: echo "$MATRIX_CONTEXT"
# checkout code
# - to provide complete SCM information to the sonar scanner,
# all historical data for all branches and tags must be retrieved (fetch-depth: 0)
#
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
# setup Java
#
- name: Set up JDK Java ${{ matrix.java }} | ${{ matrix.distribution }} | ${{ matrix.os }}
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java }}
distribution: ${{ matrix.distribution }}
cache: maven
# read version number from POM
#
- name: get-pom-version
id: pom-version
uses: andreacomo/maven-gav-extractor@v2
# remove -SNAPSHOT from POM version (major.minor.patch-SNAPSHOT)
#
- run: echo "CXX_POM_VERSION=${{ steps.pom-version.outputs.version }}" >> $GITHUB_ENV
- run: echo "CXX_VERSION=${CXX_POM_VERSION%-*}" >> $GITHUB_ENV
# set version number of plugin JAR
# - 'major.minor.patch' and 'build' number from actions run number
#
- name: Sets the current project's version
run: mvn versions:set -DartifactId='cxx' -DnewVersion='${{ env.CXX_VERSION }}.${{ github.run_number }}'
- name: Dump environment variables
run: env
# Build and test with with Maven
# - use phase 'verify' to aggregate coverage results (part of integration-tests)
# - use phase 'install' to resolve dependencies (necessary for sonar-scanner)
#
- name: Build and test with Maven
run: mvn -B -e -V install --file pom.xml
# Update SonarCloud results
# - Secrets are not passed to the runner when a workflow is triggered from a forked repository!
#
- name: Update SonarCloud results
run: mvn sonar:sonar -B -e -V -Dsonar.organization=sonaropencommunity -Dsonar.host.url=https://sonarcloud.io -Dsonar.token=$SONAR_TOKEN -Dsonar.python.version=3.8
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# -----------------------------------------------------------------------------------------------------------
# test cxx plugin with SonarQube (Linux)
# -----------------------------------------------------------------------------------------------------------
integration-linux:
strategy:
matrix:
os: [ubuntu-latest]
java: [ '17' ]
distribution: [ 'temurin' ]
sonarqube: [ '9.9.7.96285', '24.12.0.100206' ]
sonarscanner: [ '6.2.1.4610' ]
runs-on: ${{ matrix.os }}
needs: [build-linux, verify-rules]
steps:
# context information
#
- name: Dump Matrix context
run: echo '${{ toJSON(matrix) }}'
# checkout code
#
- name: Checkout repository
uses: actions/checkout@v4
# setup Java
#
- name: Set up JDK Java ${{ matrix.java }} | ${{ matrix.distribution }} | ${{ matrix.os }}
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java }}
distribution: ${{ matrix.distribution }}
cache: maven
# setup Python
#
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.7'
# cache not working with 2.7?
#cache: 'pip'
- run: pip install -r "$GITHUB_WORKSPACE/integration-tests/requirements.txt"
# target folder
#
- name: Create root folder
run: mkdir test
# Download & install SonarQube
#
#- name: Set up SonarQube (Cache)
# id: sonar-qube
# uses: actions/cache@v3
# with:
# path: test/sonarqube-${{ matrix.sonarqube }}
# key: install-sonarqube-${{ matrix.sonarqube }}-${{ runner.os }}
- name: Set up SonarQube (Download)
#if: steps.sonar-qube.outputs.cache-hit != 'true'
run: |
pushd test
wget -nv --timeout=10 https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-${{ matrix.sonarqube }}.zip
unzip -qq sonarqube-${{ matrix.sonarqube }}.zip
popd
# Download & install SonarScanner
#
#- name: Set up SonarScanner (Cache)
# id: sonar-scanner
# uses: actions/cache@v3
# with:
# path: test/sonar-scanner-${{ matrix.sonarscanner }}
# key: install-sonar-scanner-cli-${{ matrix.sonarscanner }}-${{ runner.os }}
- name: Set up SonarScanner (Download)
#if: steps.sonar-scanner.outputs.cache-hit != 'true'
run: |
pushd test
wget -nv --timeout=10 https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${{ matrix.sonarscanner }}.zip
unzip -qq sonar-scanner-cli-${{ matrix.sonarscanner }}.zip
popd
# download & install cxx plugin
# - copy it to target folder, behave script expect it there
#
- name: Download cxx plugin
uses: actions/download-artifact@v4
with:
name: JAR_Files
- name: restore cxx plugin
run: |
mkdir -p $GITHUB_WORKSPACE/sonar-cxx-plugin/target
cp sonar-cxx-plugin*.jar $GITHUB_WORKSPACE/sonar-cxx-plugin/target
# setup test environment
# - for the tests it is important that path seperator are correct for the OS
#
- name: Set test environment (Linux)
run: |
echo "SONAR_JAVA_PATH=$JAVA_HOME/bin/java" >> $GITHUB_ENV
echo "SONARHOME=$GITHUB_WORKSPACE/test/sonarqube-${{ matrix.sonarqube }}" >> $GITHUB_ENV
echo "SONARLOG=$GITHUB_WORKSPACE/test/sonarqube-${{ matrix.sonarqube }}/logs" >> $GITHUB_ENV
echo "$GITHUB_WORKSPACE/test/sonar-scanner-${{ matrix.sonarscanner }}/bin" >> $GITHUB_PATH
echo "TestDataFolder=$GITHUB_WORKSPACE/integration-tests/testdata" >> $GITHUB_ENV
- name: Dump environment variables
run: env
# prepare test data
# - tests with absolute paths must be aligend with CI workspace
#
- name: Prepare test data (Linux)
run: |
find "$TestDataFolder" -name '*.xml' -exec sed -i "s|/home/travis/build/SonarOpenCommunity/sonar-cxx|$GITHUB_WORKSPACE|g" '{}' \;
# run integration tests
# - use OS specific shell to start behave
#
- name: Run integration tests (Linux)
shell: bash
run: behave --no-capture --tags=SqApi79
# collect and upload LOG files
#
- name: Collect LOG files
if: always()
run: cp -v *.log "$SONARLOG"
- name: Upload LOG files as artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: "LOG_sonarqube_${{ matrix.sonarqube }}_java_${{ matrix.java }}_os_${{ matrix.os }}"
path: "${{ env.SONARLOG }}"
# -----------------------------------------------------------------------------------------------------------
# test cxx plugin with SonarQube (Windows)
# -----------------------------------------------------------------------------------------------------------
integration-windows:
strategy:
matrix:
os: [windows-latest]
java: [ '17' ]
distribution: [ 'temurin' ]
sonarqube: [ '9.9.7.96285', '24.12.0.100206' ]
sonarscanner: [ '6.2.1.4610' ]
runs-on: ${{ matrix.os }}
# needs build-linux because of JAR artifacts
needs: [build-linux, build-windows, verify-rules]
steps:
# context information
#
- name: Dump Matrix context
run: echo '${{ toJSON(matrix) }}'
# checkout code
#
- name: Checkout repository
uses: actions/checkout@v4
# setup Java
#
- name: Set up JDK Java ${{ matrix.java }} | ${{ matrix.distribution }} | ${{ matrix.os }}
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java }}
distribution: ${{ matrix.distribution }}
cache: maven
# setup Python
#
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.7'
# cache not working with 2.7?
#cache: 'pip'
- run: pip install -r "$GITHUB_WORKSPACE/integration-tests/requirements.txt"
# target folder
#
- name: Create root folder
run: mkdir test
# Download & install SonarQube
#
#- name: Set up SonarQube (Cache)
# id: sonar-qube
# uses: actions/cache@v3
# with:
# path: test/sonarqube-${{ matrix.sonarqube }}
# key: install-sonarqube-${{ matrix.sonarqube }}-${{ runner.os }}
- name: Set up SonarQube (Download)
#if: steps.sonar-qube.outputs.cache-hit != 'true'
shell: cmd
run: |
pushd test
C:\msys64\usr\bin\wget.exe -nv --timeout=10 https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-${{ matrix.sonarqube }}.zip
unzip -qq sonarqube-${{ matrix.sonarqube }}.zip
popd
# Download & install SonarScanner
#
#- name: Set up SonarScanner (Cache)
# id: sonar-scanner
# uses: actions/cache@v3
# with:
# path: test/sonar-scanner-${{ matrix.sonarscanner }}
# key: install-sonar-scanner-cli-${{ matrix.sonarscanner }}-${{ runner.os }}
- name: Set up SonarScanner for Windows (Download)
#if: steps.sonar-scanner.outputs.cache-hit != 'true'
shell: cmd
run: |
pushd test
C:\msys64\usr\bin\wget -nv --timeout=10 https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${{ matrix.sonarscanner }}.zip
unzip -qq sonar-scanner-cli-${{ matrix.sonarscanner }}.zip
popd
# download & install cxx plugin
# - copy it to target folder, behave script expect it there
#
- name: Download cxx plugin
uses: actions/download-artifact@v4
with:
name: JAR_Files
- name: restore cxx plugin
run: |
mkdir -p $GITHUB_WORKSPACE/sonar-cxx-plugin/target
cp sonar-cxx-plugin*.jar $GITHUB_WORKSPACE/sonar-cxx-plugin/target
# setup test environment
# - for the tests it is important that path seperator are correct for the OS
#
- name: Set Up SonarQube environment (Windows)
run: |
echo "SONAR_JAVA_PATH=$JAVA_HOME\bin\java.exe" >> $GITHUB_ENV
echo "SONARHOME=$GITHUB_WORKSPACE\test\sonarqube-${{ matrix.sonarqube }}" >> $GITHUB_ENV
echo "SONARLOG=$GITHUB_WORKSPACE\test\sonarqube-${{ matrix.sonarqube }}\logs" >> $GITHUB_ENV
echo "$GITHUB_WORKSPACE\test\sonar-scanner-${{ matrix.sonarscanner }}\bin" >> $GITHUB_PATH
echo "TestDataFolder=$GITHUB_WORKSPACE\integration-tests\testdata" >> $GITHUB_ENV
echo "TMP=$USERPROFILE\AppData\Local\Temp" >> $GITHUB_ENV
echo "TEMP=$USERPROFILE\AppData\Local\Temp" >> $GITHUB_ENV
- name: Dump environment variables
run: env
# prepare test data
# - tests with absolute paths must be aligend with CI workspace
#
- name: Prepare test data (Windows)
shell: pwsh
run: |
Get-ChildItem "$env:TestDataFolder\*.log" -Recurse | ForEach { (Get-Content $_).Replace('C:\projects\sonar-cxx', "$env:GITHUB_WORKSPACE") | Set-Content $_ }
# run integration tests
# - use OS specific shell to start behave
#
- name: Run integration tests (Windows)
shell: cmd
run: behave --no-capture --tags=SqApi79
# collect and upload LOG files
#
- name: Collect LOG files
if: always()
run: cp -v *.log "$SONARLOG"
- name: Upload LOG files as artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: "LOG_sonarqube_${{ matrix.sonarqube }}_java_${{ matrix.java }}_os_${{ matrix.os }}"
path: "${{ env.SONARLOG }}"
# -----------------------------------------------------------------------------------------------------------
# success
# -----------------------------------------------------------------------------------------------------------
successfully-finished:
strategy:
matrix:
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
needs: [integration-windows, integration-linux]
steps:
# download JAR files
#
- name: Download JAR files
if: github.event_name == 'push'
uses: actions/download-artifact@v4
with:
name: JAR_Files
# create pre-release
#
- uses: "marvinpinto/action-automatic-releases@latest"
if: github.event_name == 'push'
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: "latest-snapshot"
prerelease: true
title: "Latest Snapshot"
files: |
./*.jar
- run: echo SUCCESS