1- ---
21name : Analysis - SonarCloud
32
43on :
1211 VCPKG_BUILD_TYPE : release
1312 CMAKE_BUILD_PARALLEL_LEVEL : 2
1413 MAKEFLAGS : ' -j 2'
15- NUMBER_OF_PROCESSORS : 2
1614
1715jobs :
1816 sonarcloud :
1917 name : SonarCloud
2018 runs-on : ubuntu-22.04
2119
2220 steps :
23- - uses : actions/checkout@main
24- if : ${{ github.event_name == 'pull_request' || github.event_name == 'pull_request_target' }}
25- with :
26- fetch-depth : 0
27- ref : ${{github.event.pull_request.head.ref}}
28- repository : ${{github.event.pull_request.head.repo.full_name}}
29-
30- - uses : actions/checkout@main
31- if : ${{ github.event_name == 'push' }}
21+ - name : Checkout repository
22+ uses : actions/checkout@v4
3223 with :
3324 fetch-depth : 0
25+ ref : ${{ github.event_name == 'push' && github.ref || github.event.pull_request.head.ref }}
26+ repository : ${{ github.event_name == 'push' && github.repository || github.event.pull_request.head.repo.full_name }}
3427
3528 - name : Install Linux Dependencies
36- run : >
37- sudo apt-get update && sudo apt-get install ccache libglew-dev libx11-dev linux-headers-$(uname -r)
29+ run : |
30+ sudo apt-get update
31+ sudo apt-get install -y ccache libglew-dev libx11-dev linux-headers-$(uname -r)
3832
39- - name : Switch to gcc- 11
33+ - name : Switch to GCC 11
4034 run : |
41- sudo apt install gcc-11 g++-11
42- sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 100 --slave /usr/bin/g++ g++ /usr/bin/g++-11 --slave /usr/bin/gcov gcov /usr/bin/gcov-11
35+ sudo apt install -y gcc-11 g++-11
36+ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 100 \
37+ --slave /usr/bin/g++ g++ /usr/bin/g++-11 \
38+ --slave /usr/bin/gcov gcov /usr/bin/gcov-11
4339 sudo update-alternatives --set gcc /usr/bin/gcc-11
4440
45- - name : CCache
46- id : ccache
47- uses : actions/cache@main
41+ - name : Detect CPU core count
42+ id : cpu-count
43+ run : echo "count=$(nproc)" >> "$GITHUB_OUTPUT"
44+
45+ - name : Cache CCache
46+ uses : actions/cache@v4
4847 with :
4948 path : $HOME/.ccache
50- key : ccache-${{ runner.os }}-${{ hashFiles('**/src') }}
49+ key : ccache-${{ runner.os }}-${{ hashFiles('CMakeLists.txt', 'vcpkg.json', 'src/ **/*.cpp', ' src/**/*.h ') }}
5150 restore-keys : |
52- ccache-${{ runner.os}}-
51+ ccache-${{ runner.os }}-
5352
54- - name : Sonar cache
55- uses : actions/cache@main
53+ - name : Cache SonarCloud analysis data
54+ uses : actions/cache@v4
5655 with :
5756 path : $HOME/.cfamily
58- key : sonar-${{ runner.os}}-${{ hashFiles('**/src') }}
57+ key : sonar-cfamily- ${{ runner.os }}-${{ hashFiles('CMakeLists.txt', 'vcpkg.json', 'src/ **/*.cpp', ' src/**/*.h ') }}
5958 restore-keys : |
60- sonar-${{ runner.os}}-
59+ sonar-cfamily- ${{ runner.os }}-
6160
6261 - name : Cache SonarCloud packages
63- uses : actions/cache@main
62+ uses : actions/cache@v4
6463 with :
6564 path : $HOME/.sonar/cache
66- key : sonar-${{ runner.os}}-${{ hashFiles('**/src') }}
65+ key : sonar-packages- ${{ runner.os }}
6766 restore-keys : |
68- sonar-${{ runner.os}}-
67+ sonar-packages- ${{ runner.os }}-
6968
70- - name : Restore artifacts and install vcpkg
69+ - name : Extract vcpkg commit ID
7170 id : vcpkg-step
7271 run : |
7372 vcpkgCommitId=$(grep '.builtin-baseline' vcpkg.json | awk -F: '{print $2}' | tr -d '," ')
74- echo "vcpkg commit ID: $vcpkgCommitId"
75- echo "name=vcpkgGitCommitId::$vcpkgCommitId" >> $env:GITHUB_OUTPUT
73+ echo "vcpkgGitCommitId=$vcpkgCommitId" >> "$GITHUB_OUTPUT"
74+
75+ - name : Cache vcpkg installed packages
76+ uses : actions/cache@v4
77+ with :
78+ path : build/vcpkg_installed
79+ key : vcpkg-installed-${{ runner.os }}-${{ steps.vcpkg-step.outputs.vcpkgGitCommitId }}
80+ restore-keys : |
81+ vcpkg-installed-${{ runner.os }}-
7682
77- - name : Get vcpkg commit id from vcpkg.json
78- uses : lukka/run-vcpkg@main
83+ - name : Setup vcpkg with baseline
84+ uses : lukka/run-vcpkg@v11
7985 with :
80- vcpkgGitURL : " https://github.com/microsoft/vcpkg.git"
8186 vcpkgGitCommitId : ${{ steps.vcpkg-step.outputs.vcpkgGitCommitId }}
8287 vcpkgJsonIgnores : " ['**/vcpkg/**', '**/browser/overlay-ports/**']"
8388
8792 - name : Generate compilation database
8893 run : |
8994 mkdir -p build
90- cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" -DOPTIONS_ENABLE_CCACHE=ON -DSPEED_UP_BUILD_UNITY=OFF -S . -B build
95+ cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
96+ -DCMAKE_BUILD_TYPE=Debug \
97+ -DCMAKE_TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" \
98+ -DOPTIONS_ENABLE_CCACHE=ON \
99+ -DSPEED_UP_BUILD_UNITY=OFF \
100+ -S . -B build
91101
92102 - name : Run PR sonar-scanner
93103 if : ${{ github.event_name == 'pull_request' || github.event_name == 'pull_request_target' }}
@@ -97,13 +107,13 @@ jobs:
97107 BRANCH : ${{ github.event.pull_request.head.ref }}
98108 run : |
99109 sonar-scanner \
100- --define sonar.cfamily.threads=" ${{ env.NUMBER_OF_PROCESSORS }}" \
110+ --define sonar.cfamily.threads=${{ steps.cpu-count.outputs.count }} \
101111 --define sonar.cfamily.cache.enabled=true \
102112 --define sonar.cfamily.cache.path="$HOME/.cfamily" \
103113 --define sonar.cfamily.compile-commands=build/compile_commands.json \
104114 --define sonar.pullrequest.key=${{ github.event.pull_request.number }} \
105115 --define sonar.pullrequest.branch=$BRANCH \
106- --define sonar.pullrequest.base=${{ github.event.pull_request.base_ref }}
116+ --define sonar.pullrequest.base=${{ github.event.pull_request.base.ref }}
107117
108118 - name : Run sonar-scanner
109119 if : ${{ github.event_name == 'push' }}
@@ -112,7 +122,7 @@ jobs:
112122 SONAR_TOKEN : ${{ secrets.SONAR_TOKEN }}
113123 run : |
114124 sonar-scanner \
115- --define sonar.cfamily.threads=" ${{ env.NUMBER_OF_PROCESSORS }}" \
125+ --define sonar.cfamily.threads=${{ steps.cpu-count.outputs.count }} \
116126 --define sonar.cfamily.cache.enabled=true \
117127 --define sonar.cfamily.cache.path="$HOME/.cfamily" \
118128 --define sonar.cfamily.compile-commands=build/compile_commands.json
0 commit comments