-
Notifications
You must be signed in to change notification settings - Fork 168
291 lines (252 loc) · 14.3 KB
/
check-dotnet-updates.yml
File metadata and controls
291 lines (252 loc) · 14.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
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 supported .NET versions from the releases index
# - Only active support-phase channels (3.0+)
# - Exclude legacy .NET Core 1.x and 2.x versions (not supported by this project)
$supportedVersions = $releasesIndex.'releases-index' | Where-Object {
$_.'channel-version' -match '^\d+\.\d+$' -and
[int]($_.'channel-version' -split '\.')[0] -ge 3 -and
$_.'support-phase' -eq 'active'
} | Sort-Object { [int]($_.'channel-version' -split '\.')[0] }
Write-Host "Supported .NET versions: $($supportedVersions.'channel-version' -join ', ')"
# 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|arm64)\.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|arm64)\.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|arm64)\.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
$runtimeArm64 = ($runtimeFiles | Where-Object { $_.name -match "win-arm64\.exe$" }).url
$aspNetX86 = ($aspNetFiles | Where-Object { $_.name -match "win-x86\.exe$" }).url
$aspNetX64 = ($aspNetFiles | Where-Object { $_.name -match "win-x64\.exe$" }).url
$aspNetArm64 = ($aspNetFiles | Where-Object { $_.name -match "win-arm64\.exe$" }).url
$desktopX86 = ($desktopFiles | Where-Object { $_.name -match "win-x86\.exe$" }).url
$desktopX64 = ($desktopFiles | Where-Object { $_.name -match "win-x64\.exe$" }).url
$desktopArm64 = ($desktopFiles | Where-Object { $_.name -match "win-arm64\.exe$" }).url
Write-Host "Runtime x86: $runtimeX86"
Write-Host "Runtime x64: $runtimeX64"
Write-Host "Runtime arm64: $runtimeArm64"
Write-Host "ASP.NET x86: $aspNetX86"
Write-Host "ASP.NET x64: $aspNetX64"
Write-Host "ASP.NET arm64: $aspNetArm64"
Write-Host "Desktop x86: $desktopX86"
Write-Host "Desktop x64: $desktopX64"
Write-Host "Desktop arm64: $desktopArm64"
# 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 ($runtimeArm64) {
$issContent = $issContent -replace `
"https://[^']+dotnet-runtime-$major\.0\.$currentPatch-win-arm64\.exe", `
$runtimeArm64
}
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 ($aspNetArm64) {
$issContent = $issContent -replace `
"https://[^']+aspnetcore-runtime-$major\.0\.$currentPatch-win-arm64\.exe", `
$aspNetArm64
}
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
}
if ($desktopArm64) {
$issContent = $issContent -replace `
"https://[^']+windowsdesktop-runtime-$major\.0\.$currentPatch-win-arm64\.exe", `
$desktopArm64
}
} 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)
# Set outputs for the next step
$summaryText = $updateSummary -join ", "
"updates_found=true" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
"summary=$summaryText" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
Write-Host "Updates found: $summaryText"
} else {
"updates_found=false" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
Write-Host "No updates found"
}
- name: Create Pull Request
id: create-pr
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 }}"
title: "Update to .NET ${{ steps.check-updates.outputs.summary }}"
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
- name: Enable auto-merge
if: steps.create-pr.outputs.pull-request-number
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh pr merge --auto --squash ${{ steps.create-pr.outputs.pull-request-number }} --repo ${{ github.repository }}