forked from icsharpcode/CodeConverter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-testdata-targetframework.ps1
More file actions
57 lines (47 loc) · 2.02 KB
/
update-testdata-targetframework.ps1
File metadata and controls
57 lines (47 loc) · 2.02 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
param()
$ErrorActionPreference = 'Stop'
Write-Host "Creating global.json to enforce .NET 8 for MSBuild"
$globalJson = '{"sdk":{"version":"8.0.0","rollForward":"latestFeature"}}'
[System.IO.File]::WriteAllText('global.json', $globalJson, [System.Text.Encoding]::UTF8)
Write-Host "Searching for project files under Tests/TestData..."
$projFiles = Get-ChildItem -Path Tests/TestData -Recurse -Include *.csproj,*.vbproj,*.fsproj -File -ErrorAction SilentlyContinue
if (-not $projFiles) {
Write-Host "No project files found under Tests/TestData"
exit 0
}
$changed = $false
foreach ($f in $projFiles) {
$path = $f.FullName
Write-Host "Processing: $path"
# Use StreamReader to detect encoding and preserve it when writing back
$sr = [System.IO.StreamReader]::new($path, $true)
try {
$content = $sr.ReadToEnd()
$encoding = $sr.CurrentEncoding
} finally {
$sr.Close()
}
# Replace net10.0 and net10.0-windows with net8.0 / net8.0-windows
$updated = [System.Text.RegularExpressions.Regex]::Replace($content, '<TargetFramework>net10\.0(-windows)?</TargetFramework>', '<TargetFramework>net8.0$1</TargetFramework>')
if ($updated -ne $content) {
Write-Host "Updating TargetFramework in: $path"
# Write back preserving detected encoding and internal newlines
[System.IO.File]::WriteAllText($path, $updated, $encoding)
$changed = $true
}
}
if ($changed) {
Write-Host "Changes detected — committing to local repo so working tree is clean for tests"
git config user.name "github-actions[bot]"
if ($env:GITHUB_ACTOR) {
git config user.email "$($env:GITHUB_ACTOR)@users.noreply.github.com"
} else {
git config user.email "actions@github.com"
}
git add -A
git commit -m "CI: Update Tests/TestData TargetFramework -> net8.0 for .NET 8 run" || Write-Host "No commit created (maybe no staged changes)"
Write-Host "Committed changes locally."
} else {
Write-Host "No TargetFramework updates required."
}
Write-Host "Done."