Skip to content

Commit dc5843c

Browse files
committed
refactoring the workflow, bumping python and gcovr
1 parent 3af698d commit dc5843c

File tree

1 file changed

+57
-41
lines changed

1 file changed

+57
-41
lines changed

.github/workflows/sonarcloud.yml

Lines changed: 57 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,56 @@
1+
# Workflow for building and testing the project
2+
name: Build
3+
4+
# Define when the workflow should run
15
on:
2-
# Trigger analysis when pushing in master or pull requests, and when creating
3-
# a pull request.
46
push:
57
branches:
6-
- main
8+
- main # Trigger on pushes to main branch
79
pull_request:
8-
types: [opened, edited, synchronize, reopened]
9-
name: Build
10+
types:
11+
- opened # When PR is first created
12+
- edited # When PR description/title is edited
13+
- synchronize # When new commits are pushed to the PR
14+
- reopened # When PR is reopened after being closed
1015

16+
# Environment variables used across jobs
1117
env:
12-
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
13-
BUILD_TYPE: Release
14-
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed
18+
BUILD_TYPE: Release # Set CMake build configuration
19+
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Output directory for build wrapper
1520

1621
jobs:
17-
1822
build:
1923
name: Build & Test
20-
runs-on: macos-14
24+
runs-on: macos-14 # Use macOS 14 (Sonoma) runner
25+
2126
steps:
22-
- uses: actions/checkout@v4
27+
# Step 1: Check out the repository code
28+
- name: Checkout repository
29+
uses: actions/checkout@v4
30+
31+
# Step 2: Set up Homebrew package manager
2332
- name: Set up Homebrew
2433
id: set-up-homebrew
2534
uses: Homebrew/actions/setup-homebrew@master
26-
- name: Install packages
27-
run: >
28-
bash ./.github/workflows/brew.sh
35+
36+
# Step 3: Install required dependencies using Homebrew
37+
- name: Install dependencies
38+
run: bash ./.github/workflows/brew.sh
39+
40+
# Step 4: Build project libraries
2941
- name: Build libraries
30-
run: >
31-
bash ./.github/workflows/build.sh
32-
- name: Select Xcode
33-
run: sudo xcode-select -switch /Applications/Xcode_15.2.app && /usr/bin/xcodebuild -version
42+
run: bash ./.github/workflows/build.sh
43+
44+
# Step 5: Configure Xcode version
45+
- name: Select Xcode version
46+
run: |
47+
sudo xcode-select -switch /Applications/Xcode_15.2.app
48+
/usr/bin/xcodebuild -version
49+
# Run XCode tests with specific configurations:
50+
# - Builds and runs the test suite
51+
# - Generates code coverage reports
52+
# - Uses PostgreSQL and libpqxx external dependencies
53+
# - Outputs results in JUnit format
3454
- name: Run tests
3555
run: >
3656
CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO
@@ -48,13 +68,16 @@ jobs:
4868
- name: Convert coverage report to sonarqube format
4969
run: >
5070
bash ./.github/workflows/xccov-to-sonarqube-generic.sh *.xcresult/ > sonarqube-generic-coverage.xml
71+
# Artifact will be available only for 1 day, this is because
72+
# it's only used to pass test data to SonarCloud only
5173
- name: Upload coverage report
5274
uses: actions/upload-artifact@v4
5375
with:
5476
path: sonarqube-generic-coverage.xml
55-
retention-days: 1 # Artifact will be available only for 5 days.
77+
retention-days: 1
78+
5679
sonar-scan:
57-
name: Sonar scan
80+
name: SonarCloud Scan
5881
runs-on: ubuntu-latest
5982
needs: build
6083
steps:
@@ -63,7 +86,7 @@ jobs:
6386
with:
6487
ref: ${{ github.HEAD_REF }}
6588
fetch-depth: 0
66-
- name: Check compiler version
89+
- name: Check compiler version, for debugging
6790
run: |
6891
g++ --version
6992
cmake --version
@@ -73,19 +96,22 @@ jobs:
7396
- name: Set up Python 3.8 for gcovr
7497
uses: actions/setup-python@v5
7598
with:
76-
python-version: 3.8
77-
- name: install gcovr 5.0
99+
python-version: 3.12
100+
# Gcovr provides a utility for managing the use of the GNU gcov utility and generating
101+
# summarized code coverage results. This command is inspired by the Python coverage.py
102+
# package, which provides a similar utility for Python.
103+
# https://pypi.org/project/gcovr/
104+
- name: Install gcovr
78105
run: |
79-
pip install gcovr==5.0 # 5.1 is not supported by sonarcloud
106+
pip install gcovr==8.3
107+
# SonarQube Server and Cloud (formerly SonarQube and SonarCloud) is a widely used static
108+
# analysis solution for continuous code quality and security inspection.
109+
# This action now supports and is the official entrypoint for scanning C++ projects via GitHub actions.
110+
# https://github.com/SonarSource/sonarqube-scan-action
80111
- name: Install Build Wrapper
81-
uses: SonarSource/sonarqube-scan-action/[email protected]
82-
# - name: Install sonar-scanner and build-wrapper
83-
# uses: SonarSource/sonarcloud-github-c-cpp@v3
112+
uses: SonarSource/sonarqube-scan-action/[email protected]
84113
- name: Download all workflow run artifacts
85114
uses: actions/download-artifact@v4
86-
- name: Unpack Artifact
87-
run: >
88-
ls -l ./
89115
- name: Configure CMake
90116
run: cmake -S ${{github.workspace}} -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
91117
- name: Run build-wrapper
@@ -97,15 +123,5 @@ jobs:
97123
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
98124
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
99125
with:
100-
# Consult https://docs.sonarsource.com/sonarqube-server/latest/analyzing-source-code/scanners/sonarscanner/ for more information and options
101126
args: >
102-
--define sonar.cfamily.compile-commands="${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json" \
103-
# -Dsonar.coverageReportPaths=artifact/sonarqube-generic-coverage.xml
104-
# - name: Run sonar-scanner
105-
# env:
106-
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
107-
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
108-
# run: |
109-
# sonar-scanner \
110-
# --define sonar.cfamily.compile-commands="${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json" \
111-
# -Dsonar.coverageReportPaths=artifact/sonarqube-generic-coverage.xml
127+
--define sonar.cfamily.compile-commands="${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json" \

0 commit comments

Comments
 (0)