Skip to content

Commit 62085c0

Browse files
CopilotShyam-Gupta
andauthored
Add scheduled workflow to auto-fix NuGet.config packageSource key mismatch in release/10.0 PRs (#14480)
Add scheduled workflow to fix NuGet.config packageSource key mismatch in release/10.0 PRs Agent-Logs-Url: https://github.com/dotnet/winforms/sessions/9e5969ab-bccd-4a40-ba19-f10228d76d67 Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Shyam-Gupta <24871676+Shyam-Gupta@users.noreply.github.com>
1 parent 8164882 commit 62085c0

1 file changed

Lines changed: 102 additions & 0 deletions

File tree

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
name: Fix NuGet.config packageSource key in release/10.0 PRs
2+
3+
on:
4+
schedule:
5+
# Run daily at 18:00 UTC (10:00 AM PST / 11:00 AM PDT)
6+
- cron: '0 18 * * *'
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: write
11+
pull-requests: read
12+
13+
jobs:
14+
fix-nuget-config:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Find and fix NuGet.config packageSource key mismatches
18+
uses: actions/github-script@v7
19+
with:
20+
github-token: ${{ secrets.GITHUB_TOKEN }}
21+
script: |
22+
const { data: pullRequests } = await github.rest.pulls.list({
23+
owner: context.repo.owner,
24+
repo: context.repo.repo,
25+
state: 'open',
26+
base: 'release/10.0',
27+
// Pagination is not implemented; 100 is sufficient since release branches
28+
// rarely have more than a handful of open PRs at any given time.
29+
per_page: 100
30+
});
31+
32+
console.log(`Found ${pullRequests.length} open PR(s) targeting release/10.0`);
33+
34+
for (const pr of pullRequests) {
35+
console.log(`\nChecking PR #${pr.number}: ${pr.title}`);
36+
37+
// Skip PRs from forks — we cannot push to them
38+
if (!pr.head.repo || pr.head.repo.full_name !== `${context.repo.owner}/${context.repo.repo}`) {
39+
console.log(' Skipping — PR branch is in a fork');
40+
continue;
41+
}
42+
43+
// Read NuGet.config from the PR branch
44+
let fileData;
45+
try {
46+
const response = await github.rest.repos.getContent({
47+
owner: context.repo.owner,
48+
repo: context.repo.repo,
49+
path: 'NuGet.config',
50+
ref: pr.head.sha
51+
});
52+
fileData = response.data;
53+
} catch (e) {
54+
console.log(` Could not read NuGet.config: ${e.message}`);
55+
continue;
56+
}
57+
58+
const nugetContent = Buffer.from(fileData.content, 'base64').toString('utf8');
59+
60+
// Extract the darc-pub-dotnet-dotnet-* key from <packageSources>
61+
const sourcesMatch = nugetContent.match(/<add key="(darc-pub-dotnet-dotnet-[a-fA-F0-9]+)"/);
62+
if (!sourcesMatch) {
63+
console.log(' No darc-pub-dotnet-dotnet-* key found in packageSources, skipping');
64+
continue;
65+
}
66+
const sourcesKey = sourcesMatch[1];
67+
68+
// Extract the darc-pub-dotnet-dotnet-* key from <packageSourceMapping>
69+
const mappingMatch = nugetContent.match(/<packageSource key="(darc-pub-dotnet-dotnet-[a-fA-F0-9]+)"/);
70+
if (!mappingMatch) {
71+
console.log(' No darc-pub-dotnet-dotnet-* key found in packageSourceMapping, skipping');
72+
continue;
73+
}
74+
const mappingKey = mappingMatch[1];
75+
76+
if (sourcesKey === mappingKey) {
77+
console.log(` Keys match (${sourcesKey}), no fix needed`);
78+
continue;
79+
}
80+
81+
console.log(` Mismatch detected — packageSources: "${sourcesKey}", packageSourceMapping: "${mappingKey}"`);
82+
83+
// Update the packageSourceMapping key to match packageSources.
84+
// replaceAll handles the unlikely case of the key appearing more than once.
85+
const fixedContent = nugetContent.replaceAll(
86+
`<packageSource key="${mappingKey}">`,
87+
`<packageSource key="${sourcesKey}">`
88+
);
89+
90+
// Commit the fix directly to the PR branch
91+
await github.rest.repos.createOrUpdateFileContents({
92+
owner: context.repo.owner,
93+
repo: context.repo.repo,
94+
path: 'NuGet.config',
95+
message: 'Update packageSource key in NuGet.config',
96+
content: Buffer.from(fixedContent).toString('base64'),
97+
sha: fileData.sha,
98+
branch: pr.head.ref
99+
});
100+
101+
console.log(` Fixed NuGet.config on branch ${pr.head.ref}`);
102+
}

0 commit comments

Comments
 (0)