11name : SonarCloud
22
3- # Controls when the action will run. Triggers the workflow on push or pull request
4- # events but only for the master branch
53on :
6- workflow_dispatch :
7- push :
8- paths-ignore :
9- - ' **/*.md'
10- - .gitignore
11- - .editorconfig
12- pull_request_target :
13- types : [opened, synchronize]
14- paths-ignore :
15- - ' **/*.md'
16- - .gitignore
17- - .editorconfig
18- schedule :
19- - cron : ' 45 7 * * FRI'
4+ workflow_run :
5+ workflows : ['build sakura']
6+ types : [completed]
207
21- # A workflow run is made up of one or more jobs that can run sequentially or in parallel
228jobs :
239 sonar :
2410 name : Scan
2511 runs-on : windows-latest
26-
27- env :
28- BUILD_PLATFORM : x64
29- BUILD_CONFIGURATION : Debug
12+ if : github.event.workflow_run.conclusion == 'success'
3013
3114 steps :
3215 - name : Checkout
3316 uses : actions/checkout@v6
3417 with :
35- ref : ' ${{ github.event.pull_request.head.sha }}'
18+ ref : ${{ github.event.workflow_run.head_sha }}
3619 fetch-depth : 0
3720 submodules : true
3821
39- - name : Setup environment variables
40- id : setup-base-env
41- run : |
42- $projectKey = $('${{ github.repository }}' -replace '/', '_')
43- echo "project-key=$projectKey" >> $env:GITHUB_OUTPUT
44- echo "branch-name=-Dsonar.branch.name=${{ github.ref_name }}" >> $env:GITHUB_OUTPUT
45- echo "output-directory=${{ github.workspace }}\${{ env.BUILD_PLATFORM }}\${{ env.BUILD_CONFIGURATION }}" >> $env:GITHUB_OUTPUT
46-
47- - name : Setup PR environment variables
48- id : setup-pr-env
49- env :
50- PR_HEAD_REF : ${{ github.event.pull_request.head.ref }}
51- PR_BASE_REF : ${{ github.event.pull_request.base.ref }}
52- if : github.event_name == 'pull_request' || github.event_name == 'pull_request_target'
53- run : |
54- echo "project-key=${{ steps.setup-base-env.outputs.project-key }}" >> $env:GITHUB_OUTPUT
55- echo "pull-request-key=-Dsonar.pullrequest.key=${{ github.event.pull_request.number }}" >> $env:GITHUB_OUTPUT
56- echo "branch-name=-Dsonar.pullrequest.branch=$env:PR_HEAD_REF" >> $env:GITHUB_OUTPUT
57- echo "branch-base=-Dsonar.pullrequest.base=$env:PR_BASE_REF" >> $env:GITHUB_OUTPUT
58- echo "output-directory=${{ steps.setup-base-env.outputs.output-directory }}" >> $env:GITHUB_OUTPUT
59- shell : pwsh
22+ - name : Download sonar-input artifact
23+ uses : actions/download-artifact@v4
24+ with :
25+ name : sonar-input
26+ path : ${{ github.workspace }}
27+ github-token : ${{ secrets.GITHUB_TOKEN }}
28+ run-id : ${{ github.event.workflow_run.id }}
6029
61- - name : Merge environment variables
62- id : setup-env
30+ - name : Setup sonar variables
31+ id : sonar-vars
6332 run : |
64- if ('${{ github.event_name }}' -eq 'pull_request' -or '${{ github.event_name }}' -eq 'pull_request_target') {
65- echo "project-key=${{ steps.setup-pr-env.outputs.project-key }}" >> $env:GITHUB_OUTPUT
66- echo "pull-request-key=${{ steps.setup-pr-env.outputs.pull-request-key }}" >> $env:GITHUB_OUTPUT
67- echo "branch-name=${{ steps.setup-pr-env.outputs.branch-name }}" >> $env:GITHUB_OUTPUT
68- echo "branch-base=${{ steps.setup-pr-env.outputs.branch-base }}" >> $env:GITHUB_OUTPUT
69- echo "output-directory=${{ steps.setup-pr-env.outputs.output-directory }}" >> $env:GITHUB_OUTPUT
33+ $meta = Get-Content sonar-metadata.json | ConvertFrom-Json
34+ $projectKey = ('${{ github.repository }}' -replace '/', '_')
35+ echo "project-key=$projectKey" >> $env:GITHUB_OUTPUT
36+ if ($meta.event_name -eq 'pull_request') {
37+ echo "pull-request-key=-Dsonar.pullrequest.key=$($meta.pr_number)" >> $env:GITHUB_OUTPUT
38+ echo "branch-name=-Dsonar.pullrequest.branch=$($meta.pr_head_ref)" >> $env:GITHUB_OUTPUT
39+ echo "branch-base=-Dsonar.pullrequest.base=$($meta.pr_base_ref)" >> $env:GITHUB_OUTPUT
7040 } else {
71- echo "project-key=${{ steps.setup-base-env.outputs.project-key }}" >> $env:GITHUB_OUTPUT
72- echo "branch-name=${{ steps.setup-base-env.outputs.branch-name }}" >> $env:GITHUB_OUTPUT
73- echo "output-directory=${{ steps.setup-base-env.outputs.output-directory }}" >> $env:GITHUB_OUTPUT
41+ echo "branch-name=-Dsonar.branch.name=$($meta.ref_name)" >> $env:GITHUB_OUTPUT
7442 }
7543 shell : pwsh
7644
77- - name : Setup MSBuild
78- uses : microsoft/setup-msbuild@v3
79-
80- - name : Set up Python
81- uses : actions/setup-python@v6
82-
83- - name : Install AutoHotKey
84- run : |
85- $AutohotkeyDir = "$HOME\autohotkey"
86- if (!(Test-Path $AutohotkeyDir)) { New-Item -ItemType Directory -Path $AutohotkeyDir }
87- $ProgressPreference = 'SilentlyContinue'
88- Invoke-WebRequest -Uri https://github.com/AutoHotkey/AutoHotkey/releases/download/v2.0.19/AutoHotkey_2.0.19.zip -OutFile "AutoHotkey.zip"
89- Expand-Archive -Path "AutoHotkey.zip" -DestinationPath $AutohotkeyDir -Force
90- echo "AutoHotKey=$HOME\autohotkey\AutoHotkey32.exe" >> $env:GITHUB_ENV
91-
92- - name : Install Locale Emulator
93- run : |
94- $LEExpandDir = "${{ github.workspace }}\tools\LocaleEmulator"
95- $LEInitScript = "${{ github.workspace }}\tools\LocaleEmulator\init-locale-emulator.ahk"
96- Expand-Archive "${{ github.workspace }}\externals\LocaleEmulator\locale-emulator.zip" "${LEExpandDir}"
97- Start-Process $env:AutoHotKey "${LEInitScript}"
98- Start-Process "${LEExpandDir}\LEInstaller.exe"
99- echo "${LEExpandDir}" >> $env:GITHUB_PATH
100- shell : pwsh
101-
102- - name : Run the normal MSBuild process
103- env :
104- SONAR_TOKEN : ${{ secrets.SONAR_TOKEN }}
105- if : env.SONAR_TOKEN
106- run : build-sln.bat ${{ env.BUILD_PLATFORM }} ${{ env.BUILD_CONFIGURATION }}
107- shell : cmd
108-
109- - name : Install Build Wrapper
110- uses : SonarSource/sonarqube-scan-action/install-build-wrapper@v8.2.0
111-
112- - name : Build with Build-Wrapper
113- env :
114- SONAR_TOKEN : ${{ secrets.SONAR_TOKEN }}
115- if : env.SONAR_TOKEN
116- run : build-wrapper-win-x86-64.exe
117- --out-dir bw-output
118- MsBuild.exe
119- /p:Platform=${{ env.BUILD_PLATFORM }}
120- /p:Configuration=${{ env.BUILD_CONFIGURATION }}
121- /t:ReBuild
122-
123- - name : Install OpenCppCoverage
124- env :
125- SONAR_TOKEN : ${{ secrets.SONAR_TOKEN }}
126- if : env.SONAR_TOKEN
127- working-directory : ${{ runner.temp }}
128- run : |
129- $Installer = "OpenCppCoverageSetup.exe"
130- Invoke-WebRequest -Uri "https://github.com/OpenCppCoverage/OpenCppCoverage/releases/download/release-0.9.9.0/OpenCppCoverageSetup-x64-0.9.9.0.exe" -OutFile $Installer
131- Start-Process -FilePath .\$Installer -ArgumentList "/VERYSILENT", "/SUPPRESSMSGBOXES" -Wait
132- echo "C:\Program Files\OpenCppCoverage" >> $env:GITHUB_PATH
133-
134- - name : Run Tests
135- env :
136- SONAR_TOKEN : ${{ secrets.SONAR_TOKEN }}
137- if : env.SONAR_TOKEN
138- run : |
139- $env:CMD_TESTS1 = $(Get-ChildItem -Recurse tests1.exe)[0].FullName
140- OpenCppCoverage.exe `
141- --export_type cobertura:tests1-coverage.xml `
142- --modules $env:CMD_TESTS1 `
143- --sources ${{ github.workspace }} `
144- --working_dir ${{ steps.setup-env.outputs.output-directory }} `
145- --cover_children `
146- -- `
147- $env:CMD_TESTS1 `
148- --gtest_output=xml:${{ github.workspace }}\tests1-googletest.xml
149-
150- - name : Upload test result
45+ - name : Publish test result
15146 uses : EnricoMi/publish-unit-test-result-action/windows@v2
152- env :
153- SONAR_TOKEN : ${{ secrets.SONAR_TOKEN }}
154- if : env.SONAR_TOKEN
15547 with :
48+ commit : ${{ github.event.workflow_run.head_sha }}
49+ event_file : github-event.json
50+ event_name : ${{ github.event.workflow_run.event }}
15651 files : |
15752 *-googletest.xml
15853
@@ -166,11 +61,11 @@ jobs:
16661 with :
16762 args : >
16863 "-Dsonar.organization=${{ github.repository_owner }}"
169- "-Dsonar.projectKey=${{ steps.setup-env .outputs.project-key }}"
64+ "-Dsonar.projectKey=${{ steps.sonar-vars .outputs.project-key }}"
17065 "-Dsonar.host.url=https://sonarcloud.io"
171- ${{ steps.setup-env .outputs.pull-request-key }}
172- ${{ steps.setup-env .outputs.branch-name }}
173- ${{ steps.setup-env .outputs.branch-base }}
66+ ${{ steps.sonar-vars .outputs.pull-request-key }}
67+ ${{ steps.sonar-vars .outputs.branch-name }}
68+ ${{ steps.sonar-vars .outputs.branch-base }}
17469 "-Dsonar.cfamily.compile-commands=bw-output/compile_commands.json"
17570 "-Dsonar.cfamily.cppunit.reportPath=*-googletest.xml"
17671 "-Dsonar.cfamily.cobertura.reportPaths=tests1-coverage.xml"
0 commit comments