1- # Backtesting C++ Workflow
2- # To build, test and perform SonarCloud analysis
3- name : Build
4-
51on :
2+ # Trigger analysis when pushing in master or pull requests, and when creating
3+ # a pull request.
64 push :
75 branches :
8- - main # Trigger on pushes to main branch
6+ - main
97 pull_request :
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
8+ types : [opened, synchronize, reopened]
9+ name : Build
1410
15- # Environment variables used across jobs
1611env :
17- BUILD_TYPE : Release # Set CMake build configuration
18- BUILD_WRAPPER_OUT_DIR : build_wrapper_output_directory # Output directory for build wrapper
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
1915
2016jobs :
17+
2118 build :
2219 name : Build & Test
23- runs-on : macos-14 # Use macOS 14 (Sonoma) runner
24-
20+ runs-on : macos-14
2521 steps :
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
22+ - uses : actions/checkout@v4
3123 - name : Set up Homebrew
3224 id : set-up-homebrew
3325 uses : Homebrew/actions/setup-homebrew@master
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
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
5334 - name : Run tests
5435 run : >
5536 CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO
@@ -58,29 +39,22 @@ jobs:
5839 -destination 'platform=macOS'
5940 -resultBundlePath TestResult/
6041 -enableCodeCoverage YES
61- -derivedDataPath "/tmp"
42+ -derivedDataPath "${RUNNER_TEMP}/Build/DerivedData"
6243 HEADER_SEARCH_PATHS="./external/libpqxx/include/pqxx/internal ./external/libpqxx/include/ ./external/libpqxx/build/include/ ./external/" \
6344 LIBRARY_SEARCH_PATHS="./external/libpqxx/src/ ./external/libpqxx/build/src/" \
6445 OTHER_LDFLAGS="-L./external/libpqxx/build/src -lpqxx -lpq -L/opt/homebrew/Cellar/pkgconf/2.3.0_1/lib -L/opt/homebrew/Cellar/pkgconf/2.3.0_1/lib/pkgconfig -L/opt/homebrew/Cellar/postgresql@14/14.15/lib/postgresql@14 -L/opt/homebrew/Cellar/postgresql@14/14.15/lib/postgresql@14/pgxs -L/opt/homebrew/Cellar/postgresql@14/14.15/lib/postgresql@14/pkgconfig"
6546 clean build test
6647 | xcpretty -r junit && exit ${PIPESTATUS[0]}
67- - name : Export coverage report
68- run : |
69- sh ./.github/workflows/cpp_coverage.sh
70- # - name: Convert coverage report to sonarqube format
71- # run: >
72- # bash ./.github/workflows/xccov-to-sonarqube-generic.sh *.xcresult/ > sonarqube-generic-coverage.xml
73- # Artifact will be available only for 1 day, this is because
74- # it's only used to pass test data to SonarCloud only
48+ - name : Convert coverage report to sonarqube format
49+ run : >
50+ bash ./.github/workflows/xccov-to-sonarqube-generic.sh *.xcresult/ > sonarqube-generic-coverage.xml
7551 - name : Upload coverage report
7652 uses : actions/upload-artifact@v4
7753 with :
78- path : coverage.txt
79- retention-days : 1
80-
81- # This block takes the artifact generated from the build step and uses it for SonarCloud analysis
54+ path : sonarqube-generic-coverage.xml
55+ retention-days : 1 # Artifact will be available only for 5 days.
8256 sonar-scan :
83- name : SonarCloud Scan
57+ name : Sonar scan
8458 runs-on : ubuntu-latest
8559 needs : build
8660 steps :
@@ -89,58 +63,39 @@ jobs:
8963 with :
9064 ref : ${{ github.HEAD_REF }}
9165 fetch-depth : 0
92- - name : Check compiler version, for debugging
66+ - name : Check compiler version
9367 run : |
9468 g++ --version
9569 cmake --version
96- - name : Build C++ Libraries
70+ - name : Build libraries
9771 run : >
9872 bash ./.github/workflows/build.sh
99- - name : Install Python 3.12 for gcovr
73+ - name : Set up Python 3.8 for gcovr
10074 uses : actions/setup-python@v5
10175 with :
102- python-version : 3.12
103- # Gcovr provides a utility for managing the use of the GNU gcov utility and generating
104- # summarized code coverage results. This command is inspired by the Python coverage.py
105- # package, which provides a similar utility for Python.
106- # https://pypi.org/project/gcovr/
107- - name : Install gcovr
76+ python-version : 3.8
77+ - name : install gcovr 5.0
10878 run : |
109- pip install gcovr==8.3
110- # SonarQube Server and Cloud (formerly SonarQube and SonarCloud) is a widely used static
111- # analysis solution for continuous code quality and security inspection.
112- # This action now supports and is the official entrypoint for scanning C++ projects via GitHub actions.
113- # https://github.com/SonarSource/sonarqube-scan-action
114- - name : Install Build Wrapper
115- uses :
SonarSource/sonarqube-scan-action/[email protected] 116- # This step installs the SonarQube build wrapper, which is necessary for analyzing C/C++ projects.
117-
118- # Downloads all artifacts generated by previous steps in the workflow
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
11982 - name : Download all workflow run artifacts
12083 uses : actions/download-artifact@v4
121-
122- - name : Check artifacts
123- run : |
84+ - name : Unpack Artifact
85+ run : >
12486 ls -l ./
125- ls -l ./artifact/
126-
127- # Configures the CMake build system, specifying the source directory and build directory, and setting the build type
12887 - 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
12990 run : cmake -S ${{github.workspace}} -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
130-
131- # Runs the build wrapper to capture build commands and outputs them to the specified directory. Then builds the project using CMake
13291 - name : Run build-wrapper
13392 run : |
13493 build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
135-
136- # Performs the SonarQube scan using the scan action. Uses captured build commands for analysis and requires GitHub and SonarQube tokens for authentication
137- - name : SonarQube Scan
138- uses :
SonarSource/[email protected] 94+ - name : Run sonar-scanner
13995 env :
14096 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
141- SONAR_TOKEN : ${{ secrets.SONAR_TOKEN }}
142- with :
143- args : >
144- --define sonar.cfamily.compile-commands="${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json"
145- --define sonar.cfamily.llvm-cov.reportPath=artifact/coverage.txt
146-
97+ SONAR_TOKEN : ${{ secrets.SONAR_TOKEN }} # Put the name of your token here
98+ run : |
99+ sonar-scanner \
100+ --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" \
101+ -Dsonar.coverageReportPaths=artifact/sonarqube-generic-coverage.xml
0 commit comments