Skip to content

Commit c71f249

Browse files
committed
Address PR comments
1 parent a976fcc commit c71f249

5 files changed

Lines changed: 51 additions & 107 deletions

File tree

.github/workflows/auto_bump_test_package_versions.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
shell: pwsh
4747
run: |
4848
$report = ""
49-
$reportPath = "tracer/build/cooldown_report.md"
49+
$reportPath = ".nuke/temp/cooldown_report.md"
5050
if (Test-Path $reportPath) {
5151
$report = Get-Content $reportPath -Raw
5252
}

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,3 @@ tools/dumps/
405405

406406
# test optimization temp/run folder
407407
.dd/
408-
409-
# Generated by GeneratePackageVersions target (consumed by CI workflow, not committed)
410-
tracer/build/cooldown_report.md

tracer/build/_build/Build.Utilities.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ partial class Build
5959
[Parameter("Only update package versions for packages with the following names")]
6060
readonly string[] IncludePackages;
6161

62-
[Parameter("Minimum age in days a NuGet package version must have been published before auto-including (default: 0, no filtering)")]
63-
readonly int PackageVersionCooldownDays;
62+
[Parameter("Minimum age in days a NuGet package version must have been published before auto-including (default: 2)")]
63+
readonly int PackageVersionCooldownDays = 2;
6464

6565
[LazyLocalExecutable(@"C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\gacutil.exe")]
6666
readonly Lazy<Tool> GacUtil;
@@ -323,7 +323,7 @@ partial class Build
323323
resolvedText);
324324
}
325325

326-
var reportPath = BuildDirectory / "cooldown_report.md";
326+
var reportPath = TemporaryDirectory / "cooldown_report.md";
327327
await versionGenerator.CooldownReport.SaveToFile(reportPath);
328328
Logger.Information("Cooldown report saved to {Path}", reportPath);
329329
}

tracer/build/_build/GeneratePackageVersions/NuGetVersionCache.cs

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public static class NuGetVersionCache
2525

2626
/// <summary>
2727
/// Load the version cache from disk. Returns an empty dictionary if the file doesn't exist.
28-
/// Handles both the old format (plain version strings) and the new format (version + publish date).
2928
/// </summary>
3029
public static async Task<Dictionary<string, List<VersionWithDate>>> Load(string path)
3130
{
@@ -36,30 +35,10 @@ public static async Task<Dictionary<string, List<VersionWithDate>>> Load(string
3635

3736
await using var openStream = File.OpenRead(path);
3837

39-
// Try new format first: List<KeyValuePair<string, List<VersionWithDate>>>
40-
try
41-
{
42-
var result = await JsonSerializer.DeserializeAsync<List<KeyValuePair<string, List<VersionWithDate>>>>(openStream, JsonOptions);
43-
if (result is not null)
44-
{
45-
return new Dictionary<string, List<VersionWithDate>>(result);
46-
}
47-
}
48-
catch (JsonException)
49-
{
50-
// Fall through to old format
51-
}
52-
53-
// Reset stream position for retry with old format
54-
openStream.Position = 0;
55-
56-
// Old format: List<KeyValuePair<string, List<string>>>
57-
var legacy = await JsonSerializer.DeserializeAsync<List<KeyValuePair<string, List<string>>>>(openStream, JsonOptions)
58-
?? new List<KeyValuePair<string, List<string>>>();
38+
var result = await JsonSerializer.DeserializeAsync<List<KeyValuePair<string, List<VersionWithDate>>>>(openStream, JsonOptions)
39+
?? new List<KeyValuePair<string, List<VersionWithDate>>>();
5940

60-
return legacy.ToDictionary(
61-
kvp => kvp.Key,
62-
kvp => kvp.Value.Select(v => new VersionWithDate(v, null)).ToList());
41+
return new Dictionary<string, List<VersionWithDate>>(result);
6342
}
6443

6544
/// <summary>
@@ -74,8 +53,7 @@ public static async Task Save(string path, Dictionary<string, List<VersionWithDa
7453
x.Key,
7554
x.Value
7655
.Select(v => v with { Version = Version.Parse(v.Version).ToString() })
77-
.OrderBy(v => Version.Parse(v.Version))
78-
.ToList()));
56+
.OrderBy(v => Version.Parse(v.Version))));
7957
await using var createStream = File.Create(path);
8058
await JsonSerializer.SerializeAsync(createStream, ordered, JsonOptions);
8159
}

tracer/build/_build/GeneratePackageVersions/PackageVersionGenerator.cs

Lines changed: 43 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,18 @@ where IsSupported(entry, version.ToString(), framework)
122122
select (version, framework))
123123
.ToList();
124124

125+
// Apply cooldown once on the full version list before selection.
126+
// This removes versions within the cooldown period (unless already at/below baseline)
127+
// so that SelectMax/SelectPackagesFromGlobs never see them.
128+
orderedWithFramework = ApplyCooldown(entry, orderedWithFramework, publishDateLookup);
129+
125130
// Add the last for every minor
126131
var latestMajors = SelectMax(orderedWithFramework, v => v.Major).ToList();
127132
var latestMinors = SelectMax(orderedWithFramework, v => $"{v.Major}.{v.Minor}").ToList();
128133
var latestSpecific = entry.SpecificVersions.Length == 0
129134
? latestMajors
130135
: SelectPackagesFromGlobs(orderedWithFramework, entry.SpecificVersions).ToList();
131136

132-
// Apply cooldown: override versions that are too new with older resolved versions
133-
latestMajors = ApplyCooldown(entry, latestMajors, orderedWithFramework, publishDateLookup, v => v.Major).ToList();
134-
latestMinors = ApplyCooldown(entry, latestMinors, orderedWithFramework, publishDateLookup, v => $"{v.Major}.{v.Minor}").ToList();
135-
latestSpecific = ApplyCooldown(entry, latestSpecific, orderedWithFramework, publishDateLookup, v => v.Major).ToList();
136-
137137
_latestMinors.Write(entry, latestMinors, requiresDockerDependency);
138138
_latestMajors.Write(entry, latestMajors, requiresDockerDependency);
139139
_latestSpecific.Write(entry, latestSpecific, requiresDockerDependency);
@@ -164,90 +164,59 @@ where IsSupported(entry, version.ToString(), framework)
164164
}
165165

166166
/// <summary>
167-
/// Applies cooldown filtering to selected versions. For each version that was published
167+
/// Applies cooldown filtering to the full ordered version list. For each version published
168168
/// within the cooldown period, checks if it was already accepted (at or below baseline).
169-
/// If already accepted, keeps it. Otherwise, finds the best resolved version that is
170-
/// either outside the cooldown or at the baseline. Overridden versions are added to CooldownReport.
169+
/// If already accepted, keeps it. Otherwise, removes it so that downstream selection
170+
/// (SelectMax/SelectPackagesFromGlobs) naturally picks the next-best version.
171+
/// Removed versions are recorded in CooldownReport.
171172
/// </summary>
172-
private List<(TargetFramework framework, IEnumerable<Version> versions)> ApplyCooldown<T>(
173+
private List<(Version version, TargetFramework framework)> ApplyCooldown(
173174
PackageVersionEntry entry,
174-
List<(TargetFramework framework, IEnumerable<Version> versions)> selectedVersions,
175-
List<(Version version, TargetFramework framework)> allOrderedVersions,
176-
Dictionary<string, DateTimeOffset?> publishDateLookup,
177-
Func<Version, T> groupBy)
175+
List<(Version version, TargetFramework framework)> orderedVersions,
176+
Dictionary<string, DateTimeOffset?> publishDateLookup)
178177
{
179178
_baseline.TryGetValue(entry.NugetPackageSearchName, out var baselineVersion);
180179

181-
var result = new List<(TargetFramework framework, IEnumerable<Version> versions)>();
180+
var result = new List<(Version version, TargetFramework framework)>();
182181

183-
foreach (var (framework, versions) in selectedVersions)
182+
foreach (var (version, framework) in orderedVersions)
184183
{
185-
// All versions available for this framework, grouped the same way as selection
186-
var allForFramework = allOrderedVersions
187-
.Where(x => x.framework == framework)
188-
.Select(x => x.version)
189-
.ToList();
184+
var versionKey = version.ToString();
185+
publishDateLookup.TryGetValue(versionKey, out var publishedDate);
190186

191-
var filteredVersions = new List<Version>();
192-
foreach (var version in versions)
187+
if (!IsWithinCooldown(publishedDate))
193188
{
194-
var versionKey = version.ToString();
195-
publishDateLookup.TryGetValue(versionKey, out var publishedDate);
196-
197-
if (!IsWithinCooldown(publishedDate))
198-
{
199-
// Outside cooldown -- always accept
200-
filteredVersions.Add(version);
201-
continue;
202-
}
189+
// Outside cooldown -- always accept
190+
result.Add((version, framework));
191+
continue;
192+
}
203193

204-
if (baselineVersion is not null && version <= baselineVersion)
205-
{
206-
// Within cooldown but already accepted in a previous run -- keep it
207-
filteredVersions.Add(version);
208-
continue;
209-
}
210-
211-
// Within cooldown and above baseline -- override to the best available:
212-
// the baseline version if it exists in this group, otherwise the latest
213-
// version outside cooldown
214-
var groupKey = groupBy(version);
215-
var versionsInGroup = allForFramework
216-
.Where(v => EqualityComparer<T>.Default.Equals(groupBy(v), groupKey))
217-
.Where(v => v < version)
218-
.OrderByDescending(v => v);
219-
220-
// Prefer baseline version if it's in this group
221-
Version resolved = null;
222-
if (baselineVersion is not null)
223-
{
224-
resolved = versionsInGroup.FirstOrDefault(v => v <= baselineVersion);
225-
}
194+
if (baselineVersion is not null && version <= baselineVersion)
195+
{
196+
// Within cooldown but already accepted in a previous run -- keep it
197+
result.Add((version, framework));
198+
continue;
199+
}
226200

227-
// Fall back to latest outside cooldown
228-
resolved ??= versionsInGroup.FirstOrDefault(v =>
201+
// Within cooldown and above baseline -- remove from the list.
202+
// The best fallback is whatever SelectMax ends up picking from the remaining versions.
203+
// Find what that would be for reporting purposes.
204+
var fallback = orderedVersions
205+
.Where(v => v.framework == framework && v.version < version)
206+
.Select(v => v.version)
207+
.OrderByDescending(v => v)
208+
.FirstOrDefault(v =>
229209
{
230-
publishDateLookup.TryGetValue(v.ToString(), out var rDate);
231-
return !IsWithinCooldown(rDate);
210+
publishDateLookup.TryGetValue(v.ToString(), out var d);
211+
return !IsWithinCooldown(d) || (baselineVersion is not null && v <= baselineVersion);
232212
});
233213

234-
CooldownReport.Add(new CooldownReport.CooldownEntry(
235-
entry.NugetPackageSearchName,
236-
entry.IntegrationName,
237-
versionKey,
238-
publishedDate,
239-
resolved?.ToString()));
240-
241-
if (resolved is not null)
242-
{
243-
filteredVersions.Add(resolved);
244-
}
245-
}
246-
247-
if (filteredVersions.Count > 0)
248-
{
249-
result.Add((framework, filteredVersions.Distinct().OrderBy(v => v).ToList()));
250-
}
214+
CooldownReport.Add(new CooldownReport.CooldownEntry(
215+
entry.NugetPackageSearchName,
216+
entry.IntegrationName,
217+
versionKey,
218+
publishedDate,
219+
fallback?.ToString()));
251220
}
252221

253222
return result;

0 commit comments

Comments
 (0)