Skip to content

Commit b375ab9

Browse files
authored
Merge pull request #2504 from m-tmatma/advisory-fix-1
CI の改善
2 parents ccf3f11 + 04ee638 commit b375ab9

2 files changed

Lines changed: 125 additions & 135 deletions

File tree

.github/workflows/build-sakura.yml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,98 @@ jobs:
146146
with:
147147
name: Dev ${{ matrix.platform }} ${{ matrix.config }}
148148
path: 'sakura-*-Dev.zip'
149+
150+
sonar-build:
151+
name: MSBuild for SonarCloud (x64/Debug)
152+
runs-on: windows-latest
153+
154+
env:
155+
BUILD_PLATFORM: x64
156+
BUILD_CONFIGURATION: Debug
157+
158+
steps:
159+
- uses: actions/checkout@v6
160+
with:
161+
fetch-depth: 0
162+
submodules: true
163+
164+
- name: Add msbuild to PATH
165+
uses: microsoft/setup-msbuild@30375c66a4eea26614e0d39710365f22f8b0af57 # v3
166+
167+
- name: Set up Python
168+
uses: actions/setup-python@v6
169+
170+
- name: Install AutoHotKey
171+
run: |
172+
$AutohotkeyDir = "$HOME\autohotkey"
173+
if (!(Test-Path $AutohotkeyDir)) { New-Item -ItemType Directory -Path $AutohotkeyDir }
174+
$ProgressPreference = 'SilentlyContinue'
175+
Invoke-WebRequest -Uri https://github.com/AutoHotkey/AutoHotkey/releases/download/v2.0.19/AutoHotkey_2.0.19.zip -OutFile "AutoHotkey.zip"
176+
Expand-Archive -Path "AutoHotkey.zip" -DestinationPath $AutohotkeyDir -Force
177+
echo "AutoHotKey=$HOME\autohotkey\AutoHotkey32.exe" >> $env:GITHUB_ENV
178+
179+
- name: Install Locale Emulator
180+
run: |
181+
$LEExpandDir = "${{ github.workspace }}\tools\LocaleEmulator"
182+
$LEInitScript = "${{ github.workspace }}\tools\LocaleEmulator\init-locale-emulator.ahk"
183+
Expand-Archive "${{ github.workspace }}\externals\LocaleEmulator\locale-emulator.zip" "${LEExpandDir}"
184+
Start-Process $env:AutoHotKey "${LEInitScript}"
185+
Start-Process "${LEExpandDir}\LEInstaller.exe"
186+
echo "${LEExpandDir}" >> $env:GITHUB_PATH
187+
shell: pwsh
188+
189+
- name: Install Build Wrapper
190+
uses: SonarSource/sonarqube-scan-action/install-build-wrapper@713881670b6b3676cda39549040e2d88c70d582e # v8.2.0
191+
192+
- name: Build with Build-Wrapper
193+
run: build-wrapper-win-x86-64.exe --out-dir bw-output MsBuild.exe /p:Platform=%BUILD_PLATFORM% /p:Configuration=%BUILD_CONFIGURATION% /t:ReBuild
194+
shell: cmd
195+
196+
- name: Install OpenCppCoverage
197+
working-directory: ${{ runner.temp }}
198+
run: |
199+
$ProgressPreference = 'SilentlyContinue'
200+
Invoke-WebRequest -Uri "https://github.com/OpenCppCoverage/OpenCppCoverage/releases/download/release-0.9.9.0/OpenCppCoverageSetup-x64-0.9.9.0.exe" -OutFile OpenCppCoverageSetup.exe
201+
Start-Process -FilePath .\OpenCppCoverageSetup.exe -ArgumentList "/VERYSILENT", "/SUPPRESSMSGBOXES" -Wait
202+
echo "C:\Program Files\OpenCppCoverage" >> $env:GITHUB_PATH
203+
shell: pwsh
204+
205+
- name: Run Tests with coverage
206+
run: |
207+
$env:CMD_TESTS1 = $(Get-ChildItem -Recurse tests1.exe)[0].FullName
208+
OpenCppCoverage.exe `
209+
--export_type cobertura:tests1-coverage.xml `
210+
--modules $env:CMD_TESTS1 `
211+
--sources ${{ github.workspace }} `
212+
--working_dir ${{ github.workspace }}\${{ env.BUILD_PLATFORM }}\${{ env.BUILD_CONFIGURATION }} `
213+
--cover_children `
214+
-- `
215+
$env:CMD_TESTS1 `
216+
--gtest_output=xml:${{ github.workspace }}\tests1-googletest.xml
217+
shell: pwsh
218+
219+
- name: Save sonar metadata
220+
env:
221+
PR_HEAD_REF: ${{ github.event.pull_request.head.ref }}
222+
PR_BASE_REF: ${{ github.event.pull_request.base.ref }}
223+
run: |
224+
[ordered]@{
225+
event_name = '${{ github.event_name }}'
226+
ref_name = '${{ github.ref_name }}'
227+
pr_number = '${{ github.event.pull_request.number }}'
228+
pr_head_ref = $env:PR_HEAD_REF
229+
pr_base_ref = $env:PR_BASE_REF
230+
} | ConvertTo-Json | Set-Content sonar-metadata.json
231+
Copy-Item "$env:GITHUB_EVENT_PATH" github-event.json
232+
shell: pwsh
233+
234+
- name: Upload sonar-input artifact
235+
uses: actions/upload-artifact@v7
236+
with:
237+
name: sonar-input
238+
path: |
239+
bw-output/
240+
tests1-coverage.xml
241+
tests1-googletest.xml
242+
sonar-metadata.json
243+
github-event.json

.github/workflows/sonarscan.yml

Lines changed: 30 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -1,158 +1,53 @@
11
name: 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
53
on:
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
228
jobs:
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

Comments
 (0)