From 16a333b973cdf71240b008e3f071bc9a303ab5d1 Mon Sep 17 00:00:00 2001 From: Connor Colenso Date: Sat, 31 Aug 2024 01:41:56 +0100 Subject: [PATCH] Update buildscript --- .github/workflows/build-on-tag.yml | 65 ++++++++++++++++++------------ 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/.github/workflows/build-on-tag.yml b/.github/workflows/build-on-tag.yml index d7ee809..baa88a3 100644 --- a/.github/workflows/build-on-tag.yml +++ b/.github/workflows/build-on-tag.yml @@ -1,35 +1,48 @@ -name: Build on Tag - +name: Build on: push: - tags: - - 'v*' # Triggers the workflow on tags starting with 'v', e.g., 'v1.0.0' - + branches: + - main + pull_request: + types: [opened, synchronize, reopened] jobs: build: + name: Build runs-on: windows-latest - + env: + BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed + COVERAGE_RESULTS: coverage_results # Directory where coverage results will be placed steps: - - name: Checkout the code - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - - name: Locate MSBuild - run: | - $msbuildPath = vswhere -latest -products * -requires Microsoft.Component.MSBuild -property installationPath - echo "MSBuild located at $msbuildPath" - echo "MSBUILD_PATH=$msbuildPath\MSBuild\Current\Bin\MSBuild.exe" >> $GITHUB_ENV + - name: Set up msbuild + uses: microsoft/setup-msbuild@v2 + - name: Setup VSTest.console.exe # Needed to run tests and generate coverage + uses: darenm/Setup-VSTest@v1.2 - - name: Build the solution - run: | - &"${{ env.MSBUILD_PATH }}" /t:Build /p:Configuration=Release /p:Platform=x64 YourSolution.sln + - name: Install sonar-scanner and build-wrapper + uses: sonarsource/sonarcloud-github-c-cpp@v3 - - name: Archive build artifacts - uses: actions/upload-artifact@v3 - with: - name: build - path: | - **/*.exe - **/*.dll - **/*.pdb - **/*.lib - # Add any other files you want to keep + - name: Run build-wrapper + run: | + build-wrapper-win-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} msbuild sonar_scanner_example.vcxproj /t:rebuild /nodeReuse:false + - name: Build tests + run: | + msbuild test1\test1.vcxproj + msbuild test2\test2.vcxproj + - name: Run tests with coverage + run: > + vstest.console.exe test1\*\test1.dll test2\*\test2.dll + /EnableCodeCoverage + /Collect:"Code Coverage;Format=Xml" + /ResultsDirectory:"${{ env.COVERAGE_RESULTS }}" + - name: Run sonar-scanner + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }} # Put the name of your token here + run: > + sonar-scanner + --define sonar.cfamily.compile-commands="${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json" + --define sonar.cfamily.vscoveragexml.reportsPath="${{ env.COVERAGE_RESULTS }}/*/*.xml" \ No newline at end of file