1+ # Backtesting C++ Workflow
2+ # To build, test and perform SonarCloud analysis
3+ name : Build
4+
15on :
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, synchronize, reopened]
9- name : Build
10+ types :
11+ - opened # When PR is first created
12+ - synchronize # When new commits are pushed to the PR
13+ - reopened # When PR is reopened after being closed
1014
15+ # Environment variables used across jobs
1116env :
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
17+ BUILD_TYPE : Release # Set CMake build configuration
18+ BUILD_WRAPPER_OUT_DIR : build_wrapper_output_directory # Output directory for build wrapper
1519
1620jobs :
17-
1821 build :
1922 name : Build & Test
20- runs-on : macos-14
23+ runs-on : macos-14 # Use macOS 14 (Sonoma) runner
24+
2125 steps :
22- - uses : actions/checkout@v4
26+ # Step 1: Check out the repository code
27+ - name : Checkout repository
28+ uses : actions/checkout@v4
29+
30+ # Step 2: Set up Homebrew package manager
2331 - name : Set up Homebrew
2432 id : set-up-homebrew
2533 uses : Homebrew/actions/setup-homebrew@master
26- - name : Install packages
27- run : >
28- bash ./.github/workflows/brew.sh
29- - 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
34+
35+ # Step 3: Install required dependencies using Homebrew
36+ - name : Install dependencies
37+ run : bash ./.github/workflows/brew.sh
38+
39+ # Step 4: Build project external libraries
40+ - name : Build C++ Libraries
41+ run : bash ./.github/workflows/build.sh
42+
43+ # Step 5: Configure Xcode version
44+ - name : Select Xcode version
45+ run : |
46+ sudo xcode-select -switch /Applications/Xcode_15.2.app
47+ /usr/bin/xcodebuild -version
48+ # Run XCode tests with specific configurations:
49+ # - Builds and runs the test suite
50+ # - Generates code coverage reports
51+ # - Uses PostgreSQL and libpqxx external dependencies
52+ # - Outputs results in JUnit format
3453 - name : Run tests
3554 run : >
3655 CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO
@@ -48,13 +67,16 @@ jobs:
4867 - name : Convert coverage report to sonarqube format
4968 run : >
5069 bash ./.github/workflows/xccov-to-sonarqube-generic.sh *.xcresult/ > sonarqube-generic-coverage.xml
70+ # Artifact will be available only for 1 day, this is because
71+ # it's only used to pass test data to SonarCloud only
5172 - name : Upload coverage report
5273 uses : actions/upload-artifact@v4
5374 with :
5475 path : sonarqube-generic-coverage.xml
55- retention-days : 1 # Artifact will be available only for 5 days.
76+ retention-days : 1
77+
5678 sonar-scan :
57- name : Sonar scan
79+ name : SonarCloud Scan
5880 runs-on : ubuntu-latest
5981 needs : build
6082 steps :
@@ -63,39 +85,42 @@ jobs:
6385 with :
6486 ref : ${{ github.HEAD_REF }}
6587 fetch-depth : 0
66- - name : Check compiler version
88+ - name : Check compiler version, for debugging
6789 run : |
6890 g++ --version
6991 cmake --version
70- - name : Build libraries
92+ - name : Build C++ Libraries
7193 run : >
7294 bash ./.github/workflows/build.sh
73- - name : Set up Python 3.8 for gcovr
95+ - name : Install Python 3.12 for gcovr
7496 uses : actions/setup-python@v5
7597 with :
76- python-version : 3.8
77- - name : install gcovr 5.0
98+ python-version : 3.12
99+ # Gcovr provides a utility for managing the use of the GNU gcov utility and generating
100+ # summarized code coverage results. This command is inspired by the Python coverage.py
101+ # package, which provides a similar utility for Python.
102+ # https://pypi.org/project/gcovr/
103+ - name : Install gcovr
78104 run : |
79- pip install gcovr==5.0 # 5.1 is not supported by sonarcloud
80- - name : Install sonar-scanner and build-wrapper
81- uses : SonarSource/sonarcloud-github-c-cpp@v3
105+ pip install gcovr==8.3
106+ # SonarQube Server and Cloud (formerly SonarQube and SonarCloud) is a widely used static
107+ # analysis solution for continuous code quality and security inspection.
108+ # This action now supports and is the official entrypoint for scanning C++ projects via GitHub actions.
109+ # https://github.com/SonarSource/sonarqube-scan-action
110+ - name : Install Build Wrapper
111+ uses :
SonarSource/sonarqube-scan-action/[email protected] 82112 - name : Download all workflow run artifacts
83113 uses : actions/download-artifact@v4
84- - name : Unpack Artifact
85- run : >
86- ls -l ./
87114 - name : Configure CMake
88- # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
89- # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
90115 run : cmake -S ${{github.workspace}} -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
91116 - name : Run build-wrapper
92117 run : |
93118 build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
94- - name : Run sonar-scanner
119+ - name : SonarQube Scan
120+ uses :
SonarSource/[email protected] 95121 env :
96122 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
97- SONAR_TOKEN : ${{ secrets.SONAR_TOKEN }} # Put the name of your token here
98- run : |
99- sonar-scanner \
100- --define sonar.cfamily.compile-commands="${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json" \
101- -Dsonar.coverageReportPaths=artifact/sonarqube-generic-coverage.xml
123+ SONAR_TOKEN : ${{ secrets.SONAR_TOKEN }}
124+ with :
125+ args : >
126+ --define sonar.cfamily.compile-commands="${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json" \
0 commit comments