-
Notifications
You must be signed in to change notification settings - Fork 166
340 lines (290 loc) · 17.3 KB
/
check-dotnet-updates.yml
File metadata and controls
340 lines (290 loc) · 17.3 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
name: Check .NET Updates
on:
schedule:
# Run weekly on Wednesday at 9:00 AM UTC
- cron: '0 9 * * 3'
workflow_dispatch:
# Allow manual triggering
permissions:
contents: write
pull-requests: write
jobs:
check-updates:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Check for .NET updates
id: check-updates
shell: pwsh
run: |
# Base URL for Microsoft's .NET release metadata API
$apiBaseUrl = "https://dotnetcli.azureedge.net/dotnet/release-metadata"
$updatesFound = $false
$updateSummary = @()
# Read the current CodeDependencies.iss file
$issContent = Get-Content -Path "CodeDependencies.iss" -Raw
$readmeContent = Get-Content -Path "README.md" -Raw
# Fetch the releases index to get currently supported versions
Write-Host "Fetching .NET releases index..."
try {
$releasesIndex = Invoke-RestMethod -Uri "$apiBaseUrl/releases-index.json" -ErrorAction Stop
} catch {
Write-Error "Failed to fetch releases index: $_"
exit 1
}
# Get all .NET versions from the releases index
# - Include .NET Core 3.1 and all .NET 5+ versions
# - Exclude legacy .NET Core 1.x and 2.x versions (not supported by this project)
$allVersions = $releasesIndex.'releases-index' | Where-Object {
$_.'channel-version' -match '^\d+\.\d+$' -and
[int]($_.'channel-version' -split '\.')[0] -ge 3
}
$supportedVersions = $allVersions | Where-Object { $_.'support-phase' -eq 'active' } | Sort-Object { [int]($_.'channel-version' -split '\.')[0] }
$eolVersions = $allVersions | Where-Object { $_.'support-phase' -eq 'eol' }
Write-Host "Supported .NET versions: $($supportedVersions.'channel-version' -join ', ')"
Write-Host "End-of-life .NET versions: $($eolVersions.'channel-version' -join ', ')"
# Read ExampleSetup.iss file for EOL version removal
$exampleSetupContent = Get-Content -Path "ExampleSetup.iss" -Raw
$eolMarkedVersions = @()
# Process EOL versions - mark as EOL in README, keep in code, remove from examples
foreach ($versionInfo in $eolVersions) {
$channel = $versionInfo.'channel-version'
$major = [int]($channel -split '\.')[0]
$minor = [int]($channel -split '\.')[1]
Write-Host "`nProcessing EOL .NET $channel to mark as EOL..."
# Determine the procedure name patterns based on version
# .NET Core 3.1 uses "NetCore31", .NET 5+ uses "DotNet{major}0"
if ($major -eq 3 -and $minor -eq 1) {
$procNameBase = "NetCore31"
$versionLabel = ".NET Core 3.1"
} else {
$procNameBase = "DotNet${major}0"
$versionLabel = ".NET ${major}.0"
}
# Check if procedures exist in CodeDependencies.iss
$runtimeProcPattern = "procedure Dependency_Add${procNameBase};"
if ($issContent -match [regex]::Escape($runtimeProcPattern)) {
Write-Host "Found $versionLabel procedures in CodeDependencies.iss - keeping but marking as EOL in README..."
# Escape channel for use in regex patterns
$escapedChannel = [regex]::Escape($channel)
# Define base pattern for matching .NET version entries in README
$basePattern = "\.NET (Core )?${escapedChannel}(\.\d+)? \(Runtime, ASP\.NET, Desktop\)"
# Check if already marked as EOL in README
$eolPattern = "\* ${basePattern} - \*\*EOL\*\*"
$notEolPattern = "(\* ${basePattern})(?! - \*\*EOL\*\*)"
if ($readmeContent -match $eolPattern) {
Write-Host "$versionLabel already marked as EOL in README.md"
} elseif ($readmeContent -match $notEolPattern) {
# Add EOL marker to existing entry
# Note: In PowerShell, `$1 uses backtick (`) to escape $ and reference the first capture group
$readmeContent = $readmeContent -replace $notEolPattern, "`$1 - EOL"
Write-Host "Marked $versionLabel as EOL in README.md"
$updatesFound = $true
$eolMarkedVersions += $versionLabel
} else {
Write-Host "$versionLabel not found in README.md - may need to be added as EOL"
}
# Comment out EOL version calls in ExampleSetup.iss with EOL marker for discoverability
# Keep them in the example so users can discover they exist for legacy applications
# This handles both uncommented and already-commented EOL lines, ensuring consistent format
# Use a loop to avoid code duplication
$suffixes = @("", "Asp", "Desktop")
foreach ($suffix in $suffixes) {
# Pattern only matches lines with no comment or existing EOL comments, preserving other inline comments
$pattern = "(?m)^(\s*)(?://)?Dependency_Add${procNameBase}${suffix};(?:\s*//\s*EOL.*)?$"
$replacement = "`${1}//Dependency_Add${procNameBase}${suffix}; // EOL"
$exampleSetupContent = $exampleSetupContent -replace $pattern, $replacement
}
Write-Host "Kept $versionLabel in CodeDependencies.iss, marked as EOL in README.md, commented out in ExampleSetup.iss"
} else {
Write-Host "$versionLabel not found in CodeDependencies.iss - already removed or not present"
}
}
# Process each supported version
foreach ($versionInfo in $supportedVersions) {
$channel = $versionInfo.'channel-version'
$major = [int]($channel -split '\.')[0]
Write-Host "`nChecking .NET $channel..."
# Fetch detailed release info
$releasesUrl = $versionInfo.'releases.json'
try {
$releases = Invoke-RestMethod -Uri $releasesUrl -ErrorAction Stop
} catch {
Write-Warning "Failed to fetch releases for .NET $channel : $_"
continue
}
# Get the latest stable release (exclude preview/rc versions)
# Sort by release-date descending to ensure we get the most recent release
$latestRelease = $releases.releases |
Where-Object { $_.'release-version' -notmatch '-' } |
Sort-Object { [DateTime]$_.'release-date' } -Descending |
Select-Object -First 1
if (-not $latestRelease) {
Write-Warning "No stable release found for .NET $channel"
continue
}
$latestVersion = $latestRelease.'release-version'
$versionParts = $latestVersion -split '\.'
$latestPatch = [int]$versionParts[2]
Write-Host "Latest .NET $channel version: $latestVersion (patch: $latestPatch)"
# Find current version in CodeDependencies.iss
# Pattern example: Dependency_IsNetCoreInstalled('Microsoft.NETCore.App', 8, 0, 11)
$currentPatchPattern = "Dependency_IsNetCoreInstalled\('Microsoft\.NETCore\.App',\s*$major,\s*0,\s*(\d+)\)"
$currentMatch = [regex]::Match($issContent, $currentPatchPattern)
if ($currentMatch.Success) {
$currentPatch = [int]$currentMatch.Groups[1].Value
Write-Host "Current .NET $major.0 patch in file: $currentPatch"
if ($latestPatch -gt $currentPatch) {
Write-Host "Update available: $major.0.$currentPatch -> $major.0.$latestPatch"
$updatesFound = $true
$updateSummary += "$major.0.$latestPatch"
# Get download URLs for windows runtimes with null checks
$runtimeFiles = @()
$aspNetFiles = @()
$desktopFiles = @()
if ($latestRelease.runtime -and $latestRelease.runtime.files) {
$runtimeFiles = $latestRelease.runtime.files | Where-Object { $_.name -match "win-(x86|x64)\.exe$" }
} else {
Write-Warning ".NET $channel runtime files not found in API response"
}
if ($latestRelease.'aspnetcore-runtime' -and $latestRelease.'aspnetcore-runtime'.files) {
$aspNetFiles = $latestRelease.'aspnetcore-runtime'.files | Where-Object { $_.name -match "win-(x86|x64)\.exe$" }
} else {
Write-Warning ".NET $channel ASP.NET Core runtime files not found in API response"
}
if ($latestRelease.'windowsdesktop' -and $latestRelease.'windowsdesktop'.files) {
$desktopFiles = $latestRelease.'windowsdesktop'.files | Where-Object { $_.name -match "win-(x86|x64)\.exe$" }
} else {
Write-Warning ".NET $channel Windows Desktop runtime files not found in API response"
}
$runtimeX86 = ($runtimeFiles | Where-Object { $_.name -match "win-x86\.exe$" }).url
$runtimeX64 = ($runtimeFiles | Where-Object { $_.name -match "win-x64\.exe$" }).url
$aspNetX86 = ($aspNetFiles | Where-Object { $_.name -match "win-x86\.exe$" }).url
$aspNetX64 = ($aspNetFiles | Where-Object { $_.name -match "win-x64\.exe$" }).url
$desktopX86 = ($desktopFiles | Where-Object { $_.name -match "win-x86\.exe$" }).url
$desktopX64 = ($desktopFiles | Where-Object { $_.name -match "win-x64\.exe$" }).url
Write-Host "Runtime x86: $runtimeX86"
Write-Host "Runtime x64: $runtimeX64"
Write-Host "ASP.NET x86: $aspNetX86"
Write-Host "ASP.NET x64: $aspNetX64"
Write-Host "Desktop x86: $desktopX86"
Write-Host "Desktop x64: $desktopX64"
# Update version checks - Runtime
$issContent = $issContent -replace `
"(Dependency_IsNetCoreInstalled\('Microsoft\.NETCore\.App',\s*$major,\s*0,\s*)$currentPatch(\))", `
"`${1}$latestPatch`${2}"
# Update version checks - ASP.NET
$issContent = $issContent -replace `
"(Dependency_IsNetCoreInstalled\('Microsoft\.AspNetCore\.App',\s*$major,\s*0,\s*)$currentPatch(\))", `
"`${1}$latestPatch`${2}"
# Update version checks - Desktop
$issContent = $issContent -replace `
"(Dependency_IsNetCoreInstalled\('Microsoft\.WindowsDesktop\.App',\s*$major,\s*0,\s*)$currentPatch(\))", `
"`${1}$latestPatch`${2}"
# Update title strings
$issContent = $issContent -replace `
"('\.NET Runtime $major\.0\.)$currentPatch(')", `
"`${1}$latestPatch`${2}"
$issContent = $issContent -replace `
"('ASP\.NET Core Runtime $major\.0\.)$currentPatch(')", `
"`${1}$latestPatch`${2}"
$issContent = $issContent -replace `
"('\.NET Desktop Runtime $major\.0\.)$currentPatch(')", `
"`${1}$latestPatch`${2}"
# Update URLs if we have them
if ($runtimeX86 -and $runtimeX64) {
$issContent = $issContent -replace `
"https://[^']+dotnet-runtime-$major\.0\.$currentPatch-win-x86\.exe", `
$runtimeX86
$issContent = $issContent -replace `
"https://[^']+dotnet-runtime-$major\.0\.$currentPatch-win-x64\.exe", `
$runtimeX64
}
if ($aspNetX86 -and $aspNetX64) {
$issContent = $issContent -replace `
"https://[^']+aspnetcore-runtime-$major\.0\.$currentPatch-win-x86\.exe", `
$aspNetX86
$issContent = $issContent -replace `
"https://[^']+aspnetcore-runtime-$major\.0\.$currentPatch-win-x64\.exe", `
$aspNetX64
}
if ($desktopX86 -and $desktopX64) {
$issContent = $issContent -replace `
"https://[^']+windowsdesktop-runtime-$major\.0\.$currentPatch-win-x86\.exe", `
$desktopX86
$issContent = $issContent -replace `
"https://[^']+windowsdesktop-runtime-$major\.0\.$currentPatch-win-x64\.exe", `
$desktopX64
}
} else {
Write-Host ".NET $major.0 is up to date"
}
# Always ensure README has the correct entry for this supported version
# Use the current patch version (either updated or existing)
$currentVersionForReadme = if ($latestPatch -gt $currentPatch) { $latestPatch } else { $currentPatch }
$readmeVersionEntry = "`n * .NET $major.0.$currentVersionForReadme (Runtime, ASP.NET, Desktop)"
# Pattern matches the entire line including any leading whitespace after a newline
$readmeVersionPattern = "(\r?\n)\s*\* \.NET $major\.0(\.\d+)? \(Runtime, ASP\.NET, Desktop\)"
if ($readmeContent -match $readmeVersionPattern) {
# Entry exists - update it to ensure correct formatting and version
$readmeContent = $readmeContent -replace $readmeVersionPattern, $readmeVersionEntry
Write-Host "Updated README.md entry for .NET $major.0.$currentVersionForReadme"
} else {
# Entry doesn't exist - add it after the last .NET X.0 entry, or after .NET Framework 4.8.1
# First try to find the last .NET X.0 entry (e.g., " * .NET 8.0.22 (Runtime, ASP.NET, Desktop)")
$lastDotNetPattern = "(\* \.NET \d+\.0\.\d+ \(Runtime, ASP\.NET, Desktop\))(\r?\n)"
$matches = [regex]::Matches($readmeContent, $lastDotNetPattern)
if ($matches.Count -gt 0) {
# Insert after the last .NET entry
$lastMatch = $matches[$matches.Count - 1]
$insertPattern = [regex]::Escape($lastMatch.Groups[1].Value) + "(\r?\n)"
$readmeContent = $readmeContent -replace $insertPattern, "`$0 * .NET $major.0.$currentVersionForReadme (Runtime, ASP.NET, Desktop)`$1"
Write-Host "Added README.md entry for .NET $major.0.$currentVersionForReadme (after existing .NET entry)"
$updatesFound = $true
} else {
# No .NET X.0 entries exist, insert after .NET Framework 4.8.1
$insertPattern = "(\* \.NET Framework 4\.8\.1)(\r?\n)"
if ($readmeContent -match $insertPattern) {
$readmeContent = $readmeContent -replace $insertPattern, "`$1`$2 * .NET $major.0.$currentVersionForReadme (Runtime, ASP.NET, Desktop)`$2"
Write-Host "Added README.md entry for .NET $major.0.$currentVersionForReadme (after .NET Framework 4.8.1)"
$updatesFound = $true
}
}
}
} else {
Write-Host ".NET $major.0 not found in CodeDependencies.iss - may need to be added"
}
}
if ($updatesFound) {
# Write the updated content back to the files
[System.IO.File]::WriteAllText("CodeDependencies.iss", $issContent)
[System.IO.File]::WriteAllText("README.md", $readmeContent)
[System.IO.File]::WriteAllText("ExampleSetup.iss", $exampleSetupContent)
# Set outputs for the next step
$summaryText = $updateSummary -join ", "
$eolText = $eolMarkedVersions -join ", "
"updates_found=true" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
"summary=$summaryText" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
"eol=$eolText" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
Write-Host "Updates found: $summaryText"
if ($eolMarkedVersions.Count -gt 0) {
Write-Host "EOL versions marked: $eolText"
}
} else {
"updates_found=false" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
Write-Host "No updates found"
}
- name: Create Pull Request
if: steps.check-updates.outputs.updates_found == 'true'
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "Update to .NET ${{ steps.check-updates.outputs.summary }}${{ steps.check-updates.outputs.eol && format(' | Marked EOL: {0}', steps.check-updates.outputs.eol) || '' }}"
title: "Update to .NET ${{ steps.check-updates.outputs.summary }}${{ steps.check-updates.outputs.eol && format(' | Marked EOL: {0}', steps.check-updates.outputs.eol) || '' }}"
body: |
This PR updates the following .NET runtime dependencies:
.NET ${{ steps.check-updates.outputs.summary || 'No version updates' }}
branch: update-dotnet-dependencies
delete-branch: true
labels: dependencies, automated