-
Notifications
You must be signed in to change notification settings - Fork 0
506 lines (236 loc) · 11.6 KB
/
Copy pathcicd.yml
File metadata and controls
506 lines (236 loc) · 11.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
name: Build and Deploy UPM
on:
push:
branches:
- master
pull_request:
branches:
- master
permissions:
contents: write
jobs:
build-and-test:
runs-on: windows-2022
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
lfs: true
- name: Check for Plugin Changes
id: check_plugin_changes
shell: pwsh
run: |
# For push to master, always build to ensure artifacts are up to date
if ($env:GITHUB_EVENT_NAME -eq "push" -and $env:GITHUB_REF -eq "refs/heads/master") {
Write-Host "Push to master detected - forcing native DLL build"
echo "plugin_changed=true" >> $env:GITHUB_OUTPUT
exit 0
}
# For PRs, check if plugin files changed
if ($env:GITHUB_EVENT_NAME -eq "pull_request") {
$baseRef = "origin/${{ github.base_ref }}"
Write-Host "Comparing PR against base branch: $baseRef"
# Ensure we have the latest base branch
git fetch origin ${{ github.base_ref }} --quiet
# Get list of changed files using three-dot diff (merge-base comparison)
$changedFiles = git diff --name-only "$baseRef...HEAD"
Write-Host "Changed files:"
$changedFiles | ForEach-Object { Write-Host " - $_" }
# Check if any files in WebViewToolkitPlugin directory changed
$pluginChanged = $false
foreach ($file in $changedFiles) {
if ($file -like "WebViewToolkitPlugin/*") {
$pluginChanged = $true
break
}
}
if ($pluginChanged) {
Write-Host ""
Write-Host "✓ Plugin source code changes detected - native DLL will be built"
echo "plugin_changed=true" >> $env:GITHUB_OUTPUT
} else {
Write-Host ""
Write-Host "○ No plugin changes detected - skipping native DLL build"
echo "plugin_changed=false" >> $env:GITHUB_OUTPUT
}
}
- name: Setup MSVC
if: steps.check_plugin_changes.outputs.plugin_changed == 'true'
uses: ilammy/msvc-dev-cmd@v1
- name: Restore VCPKG Baseline
if: steps.check_plugin_changes.outputs.plugin_changed == 'true'
shell: pwsh
run: |
$json = Get-Content "WebViewToolkitPlugin/vcpkg.json" | ConvertFrom-Json
$json | Add-Member -MemberType NoteProperty -Name "builtin-baseline" -Value "f14401ca0f2754347c3864da7488a9b955b4e47a"
$json | ConvertTo-Json -Depth 10 | Set-Content "WebViewToolkitPlugin/vcpkg.json"
- name: Setup vcpkg
if: steps.check_plugin_changes.outputs.plugin_changed == 'true'
uses: lukka/run-vcpkg@v11
with:
vcpkgDirectory: ${{ github.workspace }}/../vcpkg
vcpkgJsonGlob: "WebViewToolkitPlugin/vcpkg.json"
- name: Get Current Version
id: get_version
shell: pwsh
run: |
$packageJson = Get-Content "WebViewToolkit/package.json" | ConvertFrom-Json
$version = $packageJson.version
echo "VERSION=$version" >> $env:GITHUB_ENV
echo "version=$version" >> $env:GITHUB_OUTPUT
- name: Validate Version Bump
shell: pwsh
run: |
$currentVersion = [version]$env:VERSION
Write-Host "Current version: $currentVersion"
# Try to get the latest tag from the upm branch
git fetch origin upm --tags
$latestTag = git tag -l "v*" --sort=-v:refname | Select-Object -First 1
if ($latestTag) {
$previousVersion = [version]($latestTag -replace "^v", "")
Write-Host "Previous version: $previousVersion"
if ($currentVersion -le $previousVersion) {
Write-Error "Version [ $currentVersion ] must be greater than latest tag [ $previousVersion ]. Please update package.json."
exit 1
}
} else {
Write-Host "No previous tags found. Skipping bump validation."
}
- name: Verify Changelog Update
if: github.event_name == 'pull_request'
shell: pwsh
run: |
$changedFiles = git diff --name-only origin/master...HEAD
if ($changedFiles -notcontains "WebViewToolkit/CHANGELOG.md") {
Write-Error "CHANGELOG.md has not been updated in this PR. Please document your changes."
exit 1
}
Write-Host "CHANGELOG.md update verified."
- name: Configure CMake
if: steps.check_plugin_changes.outputs.plugin_changed == 'true'
run: cmake -S WebViewToolkitPlugin --preset release
- name: Build Native DLL
if: steps.check_plugin_changes.outputs.plugin_changed == 'true'
run: cmake --build WebViewToolkitPlugin/build/release --config Release
- name: Install Native Artifacts
if: steps.check_plugin_changes.outputs.plugin_changed == 'true'
shell: pwsh
run: |
$pluginDir = "WebViewToolkit/Runtime/Plugins/x86_64"
if (!(Test-Path $pluginDir)) { New-Item -ItemType Directory -Force $pluginDir }
# Copy DLL and PDB for tests
Copy-Item "WebViewToolkitPlugin/build/release/bin/Release/WebViewToolkit.dll" "$pluginDir/WebViewToolkit.dll" -Force
if (Test-Path "WebViewToolkitPlugin/build/release/bin/Release/WebViewToolkit.pdb") {
Copy-Item "WebViewToolkitPlugin/build/release/bin/Release/WebViewToolkit.pdb" "$pluginDir/WebViewToolkit.pdb" -Force
}
Write-Host "Native artifacts installed to $pluginDir"
- name: Ensure Native Artifacts Exist
if: github.event_name == 'pull_request' && steps.check_plugin_changes.outputs.plugin_changed == 'false'
shell: pwsh
run: |
$pluginDir = "WebViewToolkit/Runtime/Plugins/x86_64"
$dllPath = "$pluginDir/WebViewToolkit.dll"
# Check if DLL already exists in the repository (from previous commit)
if (Test-Path $dllPath) {
Write-Host "✓ Using existing DLL from repository (no plugin changes detected)"
} else {
Write-Host "⚠ No DLL found and plugin hasn't changed"
Write-Host "Attempting to download from latest release..."
# Get the latest release
$latestRelease = gh release list --limit 1 --json tagName --jq '.[0]' 2>$null
if ($latestRelease) {
$releaseData = $latestRelease | ConvertFrom-Json
$tagName = $releaseData.tagName
# Download the DLL from the latest release
if (!(Test-Path $pluginDir)) { New-Item -ItemType Directory -Force $pluginDir }
Write-Host "Attempting to download DLL from release $tagName..."
gh release download $tagName --pattern "WebViewToolkit.dll" --dir $pluginDir 2>$null
$dllDownloadExitCode = $LASTEXITCODE
# Check if download was successful
if (Test-Path $dllPath) {
Write-Host "✓ Downloaded DLL from release $tagName"
# Try to download PDB as well (optional)
gh release download $tagName --pattern "WebViewToolkit.pdb" --dir $pluginDir 2>$null
if (Test-Path "$pluginDir/WebViewToolkit.pdb") {
Write-Host "✓ Downloaded PDB from release $tagName"
}
} else {
Write-Host "⚠ DLL not available in release $tagName (exit code: $dllDownloadExitCode)"
Write-Host "This is expected if the release was created before DLL artifacts were added."
Write-Host "The PR can proceed - DLL will be built when merged to master."
}
} else {
Write-Host "⚠ No releases available to download from"
Write-Host "This is expected for the first PR. The DLL will be built when merged to master."
}
}
# Ensure the step exits successfully even if gh commands failed
exit 0
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Prepare Release Artifacts
if: github.event_name == 'push' && github.ref == 'refs/heads/master' && steps.check_plugin_changes.outputs.plugin_changed == 'false'
shell: pwsh
run: |
# If we didn't build the DLL, copy it from the plugin dir to the build location for the release step
# Note: With current logic, this step should not run since push to master always builds
$pluginDir = "WebViewToolkit/Runtime/Plugins/x86_64"
$buildDir = "WebViewToolkitPlugin/build/release/bin/Release"
if (!(Test-Path $buildDir)) { New-Item -ItemType Directory -Force $buildDir }
if (Test-Path "$pluginDir/WebViewToolkit.dll") {
Copy-Item "$pluginDir/WebViewToolkit.dll" "$buildDir/WebViewToolkit.dll" -Force
Write-Host "Copied DLL to build directory for release"
}
if (Test-Path "$pluginDir/WebViewToolkit.pdb") {
Copy-Item "$pluginDir/WebViewToolkit.pdb" "$buildDir/WebViewToolkit.pdb" -Force
Write-Host "Copied PDB to build directory for release"
}
- name: Extract Release Notes
id: extract_notes
shell: pwsh
run: |
$version = $env:VERSION
$changelog = Get-Content "WebViewToolkit/CHANGELOG.md" -Raw
# Extract between ## [version] and next ##
$pattern = "(?s)## \[$version\].*?\n(.*?)(?=\n## \[|$)"
if ($changelog -match $pattern) {
$notes = $matches[1].Trim()
$notes | Out-File "RELEASE_NOTES.md" -Encoding utf8
Write-Host "Extracted notes for v$version"
} else {
"Initial release of v$version" | Out-File "RELEASE_NOTES.md" -Encoding utf8
Write-Warning "Could not find changelog entry for v$version."
}
- name: Publish UPM Branch
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
shell: pwsh
run: |
$version = $env:VERSION
$pluginDir = "WebViewToolkit/Runtime/Plugins/x86_64"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Force add the DLL/PDB that we processed in the Install Native Artifacts step
git add -f "$pluginDir/WebViewToolkit.dll"
if (Test-Path "$pluginDir/WebViewToolkit.pdb") {
git add -f "$pluginDir/WebViewToolkit.pdb"
}
git commit -m "chore: include native artifacts for v$version [skip ci]"
# Split only the WebViewToolkit folder to root of new branch
git subtree split --prefix=WebViewToolkit -b upm-split
# Force push to upm branch
git push origin upm-split:upm --force
# Tag the upm commit
git tag "v$version" upm-split
git push origin "v$version"
- name: Create GitHub Release
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ env.VERSION }}
body_path: RELEASE_NOTES.md
files: |
WebViewToolkitPlugin/build/release/bin/Release/WebViewToolkit.dll
WebViewToolkitPlugin/build/release/bin/Release/WebViewToolkit.pdb
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}