Skip to content

Commit 1bf42f4

Browse files
authored
Add winget-pkgs update check for VC++ and SQL
1 parent 2c23450 commit 1bf42f4

1 file changed

Lines changed: 139 additions & 0 deletions

File tree

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
name: Check Winget Manifest Updates
2+
3+
on:
4+
schedule:
5+
# Thursday 9:00 UTC — offset from the .NET check (Wednesday)
6+
- cron: '0 9 * * 4'
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: write
11+
pull-requests: write
12+
13+
jobs:
14+
check-updates:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
20+
- name: Check for updates
21+
id: check-updates
22+
shell: pwsh
23+
run: |
24+
$apiBase = "https://api.github.com/repos/microsoft/winget-pkgs/contents/manifests/m"
25+
$issPath = "CodeDependencies.iss"
26+
$content = Get-Content -Path $issPath -Raw
27+
$updates = @()
28+
29+
# Each target maps a winget-pkgs manifest path to the PackVersionComponents(...)
30+
# call in the .iss. The pattern is scoped by a unique registry-path anchor so
31+
# unrelated checks sharing the same major (e.g. SQL 2017 also uses major 14)
32+
# are not clobbered.
33+
$targets = @(
34+
@{
35+
Name = 'VC++ 2015-2022'
36+
Path = 'Microsoft/VCRedist/2015+/x64'
37+
Major = 14
38+
Pattern = '(VisualStudio\\14\.0\\VC\\Runtimes[\s\S]*?PackVersionComponents\(14,\s*)(\d+),\s*(\d+),\s*(\d+)(\))'
39+
},
40+
@{
41+
Name = 'SQL Server 2022 Express'
42+
Path = 'Microsoft/SQLServer/2022/Express'
43+
Major = 16
44+
Pattern = '(MSSQL16\.MSSQLSERVER[\s\S]*?PackVersionComponents\(16,\s*)(\d+),\s*(\d+),\s*(\d+)(\))'
45+
},
46+
@{
47+
Name = 'SQL Server 2025 Express'
48+
Path = 'Microsoft/SQLServer/2025/Express'
49+
Major = 17
50+
Pattern = '(MSSQL17\.MSSQLSERVER[\s\S]*?PackVersionComponents\(17,\s*)(\d+),\s*(\d+),\s*(\d+)(\))'
51+
}
52+
)
53+
54+
$headers = @{ 'Accept' = 'application/vnd.github.v3+json' }
55+
if ($env:GITHUB_TOKEN) { $headers['Authorization'] = "Bearer $env:GITHUB_TOKEN" }
56+
57+
foreach ($target in $targets) {
58+
Write-Host "`nChecking $($target.Name)..."
59+
60+
try {
61+
$data = Invoke-RestMethod "$apiBase/$($target.Path)" -Headers $headers -ErrorAction Stop
62+
} catch {
63+
Write-Warning " Failed to fetch manifest listing: $_"
64+
continue
65+
}
66+
67+
$versions = @()
68+
foreach ($entry in $data) {
69+
if ($entry.type -ne 'dir') { continue }
70+
try { $versions += [Version]$entry.name } catch { }
71+
}
72+
73+
if ($versions.Count -eq 0) {
74+
Write-Warning " No version folders found under $($target.Path)"
75+
continue
76+
}
77+
78+
$latest = ($versions | Sort-Object | Select-Object -Last 1)
79+
if ($latest.Major -ne $target.Major) {
80+
Write-Warning " Latest version $latest has major $($latest.Major), expected $($target.Major) — skipping"
81+
continue
82+
}
83+
Write-Host " Latest in winget-pkgs: $latest"
84+
85+
$match = [regex]::Match($content, $target.Pattern)
86+
if (-not $match.Success) {
87+
Write-Warning " PackVersionComponents pattern not found in .iss"
88+
continue
89+
}
90+
91+
$currentMinor = [int]$match.Groups[2].Value
92+
$currentBuild = [int]$match.Groups[3].Value
93+
$currentRevision = [int]$match.Groups[4].Value
94+
$current = [Version]"$($target.Major).$currentMinor.$currentBuild.$currentRevision"
95+
Write-Host " Current in .iss: $current"
96+
97+
if ($latest -gt $current) {
98+
Write-Host " Update: $current -> $latest"
99+
$replacement = "`${1}$($latest.Minor), $($latest.Build), $($latest.Revision)`${5}"
100+
$content = [regex]::Replace($content, $target.Pattern, $replacement)
101+
$updates += "$($target.Name) $latest"
102+
} else {
103+
Write-Host " Up to date"
104+
}
105+
}
106+
107+
if ($updates.Count -gt 0) {
108+
[System.IO.File]::WriteAllText($issPath, $content)
109+
$summary = $updates -join ", "
110+
"updates_found=true" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
111+
"summary=$summary" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
112+
Write-Host "`nUpdates found: $summary"
113+
} else {
114+
"updates_found=false" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
115+
Write-Host "`nNo updates found"
116+
}
117+
env:
118+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
119+
120+
- name: Create Pull Request
121+
id: create-pr
122+
if: steps.check-updates.outputs.updates_found == 'true'
123+
uses: peter-evans/create-pull-request@v7
124+
with:
125+
token: ${{ secrets.GITHUB_TOKEN }}
126+
commit-message: "Update ${{ steps.check-updates.outputs.summary }}"
127+
title: "Update ${{ steps.check-updates.outputs.summary }}"
128+
body: |
129+
Automated update based on the latest [microsoft/winget-pkgs](https://github.com/microsoft/winget-pkgs) manifests:
130+
${{ steps.check-updates.outputs.summary }}
131+
branch: update-winget-dependencies
132+
delete-branch: true
133+
labels: dependencies, automated
134+
135+
- name: Enable auto-merge
136+
if: steps.create-pr.outputs.pull-request-number
137+
env:
138+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
139+
run: gh pr merge --auto --squash ${{ steps.create-pr.outputs.pull-request-number }} --repo ${{ github.repository }}

0 commit comments

Comments
 (0)