-
Notifications
You must be signed in to change notification settings - Fork 27
124 lines (106 loc) · 4.95 KB
/
sonar_cloud.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
name: SonarCloud C/C++ CI
run-name: "SonarCloud C/C++ CI (Trigger #${{ github.event.workflow_run.run_number }})"
on:
workflow_run:
workflows: [ SonarCloud Trigger ]
types: [ completed ]
jobs:
run:
name: sonar_cloud
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion == 'success'
env:
BUILD_WRAPPER_OUT_DIR: build_wrapper
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# checkout out the proper repository in case of pull request
repository: ${{ github.event.workflow_run.head_repository.full_name }}
ref: ${{ github.event.workflow_run.head_branch }}
fetch-depth: 0 # shallow clones should be disabled for a better relevancy of analysis
submodules: recursive
# BEGIN PULL REQUEST
- name: Download pull request number artifact
if: github.event.workflow_run.event == 'pull_request'
uses: dawidd6/action-download-artifact@v6
with:
workflow: sonar_cloud_trigger
run_id: ${{ github.event.workflow_run.id }}
name: pull_request_number
- name: "Read pull request number"
if: github.event.workflow_run.event == 'pull_request'
id: pull_request_number
uses: juliangruber/read-file-action@v1
with:
path: ./pull_request_number.txt
- name: Request GitHub API for pull_request data
if: github.event.workflow_run.event == 'pull_request'
uses: octokit/[email protected]
id: get_pull_request_data
with:
route: GET /repos/${{ github.event.repository.full_name }}/pulls/${{ steps.pull_request_number.outputs.content }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout upstream base branch and checkout pull request head branch
if: github.event.workflow_run.event == 'pull_request'
run: |
git remote add upstream ${{ github.event.repository.clone_url }}
git fetch upstream
git checkout -B ${{ fromJson(steps.get_pull_request_data.outputs.data).base.ref }} \
upstream/${{ fromJson(steps.get_pull_request_data.outputs.data).base.ref }}
git checkout origin/${{ github.event.workflow_run.head_branch }}
git clean -ffdx && git reset --hard HEAD
- name: Set pull request variables
if: github.event.workflow_run.event == 'pull_request'
run: |
echo "PULL_REQUEST_KEY=${{ fromJson(steps.get_pull_request_data.outputs.data).number }}" >> ${GITHUB_ENV}
echo "PULL_REQUEST_BRANCH=${{ fromJson(steps.get_pull_request_data.outputs.data).head.ref }}" >> ${GITHUB_ENV}
echo "PULL_REQUEST_BASE=${{ fromJson(steps.get_pull_request_data.outputs.data).base.ref }}" >> ${GITHUB_ENV}
# END PULL REQUEST
- name: Install sonar-scanner and build-wrapper
uses: SonarSource/sonarcloud-github-c-cpp@v2
- name: Set up Java 8
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 8
- name: Install dependencies
run: sudo apt-get install cmake doxygen graphviz
- name: Build Zserio compiler with C++ extension
run: |
scripts/build.sh core cpp zserio
scripts/release.sh -p zserio
- name: Build C++ runtime and C++ tests under build-wrapper
run: |
cat > build_and_test.sh << EOF
#!/bin/bash
scripts/build.sh cpp_rt-linux64-gcc && scripts/release.sh -p runtime_libs && \
scripts/test.sh cpp-linux64-gcc
EOF
chmod a+x build_and_test.sh
build-wrapper-linux-x86-64 --out-dir ${{env.BUILD_WRAPPER_OUT_DIR}} ./build_and_test.sh
env:
CMAKE_EXTRA_ARGS: "-DCMAKE_BUILD_TYPE=Release"
CMAKE_BUILD_OPTIONS: "-j4"
- name: Run sonar-scanner
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
sonar-scanner \
--define sonar.projectKey="ndsev_zserio" \
--define sonar.organization="ndsev" \
--define sonar.sourceEncoding="UTF-8" \
--define sonar.sources="compiler/extensions/cpp/runtime/src,build/test/cpp/linux64-gcc/release" \
--define sonar.inclusions="**/*.h,**/*.cpp" \
--define sonar.exclusions="**/CMakeFiles/**/*" \
--define sonar.tests="compiler/extensions/cpp/runtime/test,test" \
--define sonar.test.inclusions="compiler/**/test/**/*.h,compiler/**/test/**/.cpp,test/**/*.h,test/**/*.cpp" \
--define sonar.scm.exclusions.disabled="true" \
--define sonar.cfamily.compile-commands="${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json" \
--define sonar.scm.revision="${{ github.event.workflow_run.head_sha }}" \
--define sonar.branch.name="${{ github.event.workflow_run.head_branch }}" \
--define sonar.pullrequest.key="${{ env.PULL_REQUEST_KEY }}" \
--define sonar.pullrequest.branch="${{ env.PULL_REQUEST_BRANCH }}" \
--define sonar.pullrequest.base="${{ env.PULL_REQUEST_BASE }}"