Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/auto_bump_test_package_versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ jobs:
- name: "Regenerating package versions"
run: .\tracer\build.ps1 GeneratePackageVersions --PackageVersionCooldownDays 2

- name: Read cooldown report
id: cooldown
- name: Read bump report
id: bump
if: always()
shell: pwsh
run: |
$report = ""
$reportPath = ".nuke/temp/cooldown_report.md"
$reportPath = ".nuke/temp/bump_report.md"
if (Test-Path $reportPath) {
$report = Get-Content $reportPath -Raw
}
Expand All @@ -63,9 +63,9 @@ jobs:
milestone: "${{steps.rename.outputs.milestone}}"
labels: "area:dependabot,area:test-apps,dependencies"
body: |
Updates the package versions for integration tests.
Updates the package versions for integration tests. See below for a summary of the changes.

${{ steps.cooldown.outputs.report }}
${{ steps.bump.outputs.report }}

- name: Send Slack notification about generating failure
if: failure()
Expand Down
31 changes: 19 additions & 12 deletions tracer/build/_build/Build.Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,22 +291,26 @@ static Func<string, CooldownMode> BuildCooldownModeSelector(string[] includePack
if (previousMax is null || tested.MaxVersion > previousMax)
{
bumped++;
var publishedDate = "(unknown)";
DateTimeOffset? publishedDate = null;
if (queriedVersions.TryGetValue(packageName, out var versionsForPackage))
{
var match = versionsForPackage.FirstOrDefault(v => v.Version == tested.MaxVersion.ToString());
if (match?.Published is not null)
{
publishedDate = match.Published.Value.UtcDateTime.ToString("yyyy-MM-dd");
}
publishedDate = match?.Published;
}

versionGenerator.BumpReport.AddBump(new PackageBumpReport.BumpEntry(
packageName,
tested.IntegrationName,
previousMax,
tested.MaxVersion,
Comment thread
andrewlock marked this conversation as resolved.
Outdated
publishedDate));

Logger.Information(
" {Package} {Previous} -> {Current} (published {Date}, https://www.nuget.org/packages/{Package}/{Current})",
packageName,
previousMax?.ToString() ?? "(new)",
tested.MaxVersion,
publishedDate,
publishedDate?.UtcDateTime.ToString("yyyy-MM-dd") ?? "(unknown)",
packageName,
tested.MaxVersion);
}
Expand All @@ -318,25 +322,28 @@ static Func<string, CooldownMode> BuildCooldownModeSelector(string[] includePack

Logger.Information("{Bumped} package(s) bumped, {Unchanged} unchanged", bumped, unchanged);

if (versionGenerator.CooldownReport.HasEntries)
if (versionGenerator.BumpReport.CooldownEntries.Count > 0)
{
Logger.Warning(
"{Count} package version(s) were excluded due to the {Days}-day cooldown period",
versionGenerator.CooldownReport.Entries.Count,
versionGenerator.BumpReport.CooldownEntries.Count,
effectiveCooldownDays);

foreach (var entry in versionGenerator.CooldownReport.Entries)
foreach (var entry in versionGenerator.BumpReport.CooldownEntries)
{
Logger.Warning(
" {Package} {Version} overridden (published {Date})",
entry.PackageName,
entry.OverriddenVersion,
entry.PublishedDate?.UtcDateTime.ToString("yyyy-MM-dd") ?? "unknown");
}
}

var reportPath = TemporaryDirectory / "cooldown_report.md";
await versionGenerator.CooldownReport.SaveToFile(reportPath);
Logger.Information("Cooldown report saved to {Path}", reportPath);
if (versionGenerator.BumpReport.HasEntries)
{
var reportPath = TemporaryDirectory / "bump_report.md";
await versionGenerator.BumpReport.SaveToFile(reportPath);
Logger.Information("Bump report saved to {Path}", reportPath);
}

var assemblies = MonitoringHomeDirectory
Expand Down
81 changes: 0 additions & 81 deletions tracer/build/_build/GeneratePackageVersions/CooldownReport.cs

This file was deleted.

125 changes: 125 additions & 0 deletions tracer/build/_build/GeneratePackageVersions/PackageBumpReport.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
// <copyright file="PackageBumpReport.cs" company="Datadog">
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
// </copyright>

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;

namespace GeneratePackageVersions;

/// <summary>
/// Collects the outcome of a package version regeneration run (packages that were
/// bumped and packages that were skipped by the cooldown filter) and renders them
/// as a markdown report for inclusion in the PR body.
/// </summary>
public class PackageBumpReport
{
private readonly int _cooldownDays;
private readonly List<BumpEntry> _bumpedEntries = new();
private readonly List<CooldownEntry> _cooldownEntries = new();

public PackageBumpReport(int cooldownDays)
{
_cooldownDays = cooldownDays;
}

public bool HasEntries => _bumpedEntries.Count > 0 || _cooldownEntries.Count > 0;

public IReadOnlyList<BumpEntry> BumpedEntries => _bumpedEntries;

public IReadOnlyList<CooldownEntry> CooldownEntries => _cooldownEntries;

public void AddBump(BumpEntry entry)
{
_bumpedEntries.Add(entry);
}

public void AddCooldown(CooldownEntry entry)
{
_cooldownEntries.Add(entry);
}

public string ToMarkdown()
{
if (!HasEntries)
{
return string.Empty;
}

var sb = new StringBuilder();

if (_bumpedEntries.Count > 0)
{
sb.AppendLine("## Package Version Updates");
sb.AppendLine();
sb.AppendLine("Bold entries indicate **major**-version bumps. `(new)` means no previous version existed.");
sb.AppendLine();
sb.AppendLine("| Package | Integration | Previous | New | Published |");
sb.AppendLine("|---------|-------------|----------|-----|-----------|");

foreach (var entry in _bumpedEntries)
{
var previous = entry.PreviousVersion?.ToString() ?? "(new)";
var newVersion = entry.IsMajorBump ? $"**{entry.NewVersion}**" : entry.NewVersion.ToString();
var published = entry.PublishedDate?.UtcDateTime.ToString("yyyy-MM-dd") ?? "unknown";

sb.AppendLine($"| {entry.PackageName} | {entry.IntegrationName} | {previous} | {newVersion} | {published} |");
}

sb.AppendLine();
}

if (_cooldownEntries.Count > 0)
{
sb.AppendLine("## Package Version Cooldown Report");
sb.AppendLine();
sb.AppendLine($"The following versions were published less than **{_cooldownDays} days** ago and have been overridden.");
sb.AppendLine("These require manual review before inclusion.");
sb.AppendLine();
sb.AppendLine("| Package | Integration | Overridden Version | Published | Age (days) |");
sb.AppendLine("|---------|-------------|--------------------|-----------|------------|");

foreach (var entry in _cooldownEntries)
{
var published = entry.PublishedDate?.UtcDateTime.ToString("yyyy-MM-dd") ?? "unknown";
var age = entry.PublishedDate.HasValue
? ((int)(DateTimeOffset.UtcNow - entry.PublishedDate.Value).TotalDays).ToString()
: "?";

sb.AppendLine($"| {entry.PackageName} | {entry.IntegrationName} | {entry.OverriddenVersion} | {published} | {age} |");
}
}

return sb.ToString();
}

public async Task SaveToFile(string path)
{
var markdown = ToMarkdown();
if (!string.IsNullOrEmpty(markdown))
{
// necessary to save to a file so that we can then output it in the PR description
await File.WriteAllTextAsync(path, markdown);
}
}

public record BumpEntry(
string PackageName,
string IntegrationName,
Version PreviousVersion,
Version NewVersion,
DateTimeOffset? PublishedDate)
{
public bool IsMajorBump => PreviousVersion is null || NewVersion.Major > PreviousVersion.Major;
}

public record CooldownEntry(
string PackageName,
string IntegrationName,
string OverriddenVersion,
DateTimeOffset? PublishedDate);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public class PackageVersionGenerator
public Dictionary<string, List<VersionWithDate>> QueriedVersions { get; } = new();

/// <summary>
/// Report of package versions that were excluded by the cooldown filter.
/// Report of package versions bumped in this run and versions skipped by the cooldown filter.
/// </summary>
public CooldownReport CooldownReport { get; }
public PackageBumpReport BumpReport { get; }


public PackageVersionGenerator(
Expand All @@ -46,7 +46,7 @@ public PackageVersionGenerator(
{
_getCooldownMode = getCooldownMode;
_cutoffDate = DateTimeOffset.UtcNow.AddDays(-cooldownDays);
CooldownReport = new CooldownReport(cooldownDays);
BumpReport = new PackageBumpReport(cooldownDays);
var propsDirectory = tracerDirectory / "build";
_definitionsFilePath = tracerDirectory / "build" / "PackageVersionsGeneratorDefinitions.json";
_latestMinors = new PackageGroup(propsDirectory, testProjectDirectory, "LatestMinors");
Expand Down Expand Up @@ -200,7 +200,7 @@ private List<VersionWithDate> ApplyCooldown(PackageVersionEntry entry, List<Vers

if (publishedTooRecently && !atOrBelowPreviousMax)
{
CooldownReport.Add(new CooldownReport.CooldownEntry(
BumpReport.AddCooldown(new PackageBumpReport.CooldownEntry(
entry.NugetPackageSearchName,
entry.IntegrationName,
v.Version,
Expand Down
Loading