Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .github/linters/.linkspector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dirs:
- .
- .github
excludedDirs:
- eng/announcement-templates
- eng/readme-templates
ignorePatterns:
- pattern: "^https://github.com/microsoft/mcr.*$"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint-code-base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ jobs:
uses: github/super-linter@v6 # https://github.com/github/super-linter
env:
DEFAULT_BRANCH: main
FILTER_REGEX_EXCLUDE: eng/docker-tools/.*|eng/readme-templates/.*|.portal-docs/.*
FILTER_REGEX_EXCLUDE: eng/announcement-templates/.*|eng/docker-tools/.*|eng/readme-templates/.*|.portal-docs/.*
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VALIDATE_MARKDOWN: true
218 changes: 218 additions & 0 deletions eng/announcement-templates/Render.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
#!/usr/bin/env dotnet
#:package [email protected]
#:package [email protected]
#:package [email protected]

using System.CommandLine;
using Fluid;
using Spectre.Console;

var renderCommand = new RenderTemplateCommand(templateFileInfo =>
{
if (!templateFileInfo.Exists)
{
Console.Error.WriteLine($"Template file not found: {templateFileInfo.FullName}");
return 1;
}

if (!TemplateDefinitions.TemplateIsSupported(templateFileInfo))
{
Console.Error.WriteLine($"Unsupported template file: {templateFileInfo.Name}");
return 1;
}

// Parse the template first, so any errors are caught before prompting for input
var template = TemplateDefinitions.ParseTemplate(templateFileInfo, out var parseError);
if (template is null)
{
Console.Error.WriteLine($"Failed to parse template: {parseError}");
return 1;
}

// Display some helpful reference information right before prompting the user for input.
DisplayPatchTuesdayReferenceText();

// This will prompt the user for the template parameters.
TemplateContext context = TemplateDefinitions.GetTemplateContext(templateFileInfo);

// Finally, render the template with the provided parameters.
var result = template.Render(context);

AnsiConsole.WriteLine();
AnsiConsole.Write(new Rule("[green]Generated Announcement[/]"));
AnsiConsole.WriteLine();
Console.WriteLine(result);

return 0;
});

var parseResult = renderCommand.Parse(args);
return parseResult.Invoke();


static void DisplayPatchTuesdayReferenceText()
{
AnsiConsole.WriteLine();
AnsiConsole.MarkupLine("[grey]Patch Tuesdays Reference:[/]");
for (int i = -4; i <= 4; i++)
{
var pt = DateOnly.GetPatchTuesday(i);
var label = i == 0 ? "this month" : i.ToString("+0;-0");
AnsiConsole.MarkupLine($"[grey] {label,11}: {pt:yyyy-MM-dd}[/]");
}

AnsiConsole.WriteLine();
}

static class TemplateDefinitions
{
// All supported templates and their associated context factories.
private static readonly Dictionary<string, Func<TemplateContext>> s_templateContexts = new()
{
["alpine-floating-tag-update.md"] = AlpineFloatingTagTemplateParameters.ContextFactory,
};

public static TemplateContext GetTemplateContext(FileInfo templateFileInfo)
{
var contextFactory = s_templateContexts[templateFileInfo.Name];
var templateContext = contextFactory();
return templateContext;
}

public static IFluidTemplate? ParseTemplate(FileInfo templateFile, out string? error)
{
var parser = new FluidParser();
var templateText = File.ReadAllText(templateFile.FullName);

if (!parser.TryParse(templateText, out var template, out string? internalError))
{
error = internalError;
return null;
}

error = null;
return template;
}

public static bool TemplateIsSupported(FileInfo templateFile) =>
s_templateContexts.ContainsKey(templateFile.Name);
}

sealed class RenderTemplateCommand : RootCommand
{
public RenderTemplateCommand(Func<FileInfo, int> handler) : base("Render announcement template")
{
var templateFileArgument = new Argument<FileInfo>("templateFile")
{
Description = "The template file to read and display on the console",
};
Arguments.Add(templateFileArgument);

SetAction(parseResult =>
{
var templateFileResult = parseResult.GetValue(templateFileArgument);
if (parseResult.Errors.Count == 0 && templateFileResult is FileInfo validTemplateFile)
{
return handler(validTemplateFile);
}

if (parseResult.Errors.Count > 0)
{
foreach (var error in parseResult.Errors)
Console.Error.WriteLine(error.Message);

return 1;
}

// Show help text
Parse("-h").Invoke();

return 0;
});
}
}

sealed record AlpineFloatingTagTemplateParameters(
string NewVersion,
string OldVersion,
DateTime PublishDate,
DateTime ReleaseDate,
DateTime EolDate,
string PublishDiscussionUrl,
string DotnetExampleVersion)
{
public static Func<TemplateContext> ContextFactory { get; } = () =>
{
var model = PromptForInput();
return new TemplateContext(model);
};

public static AlpineFloatingTagTemplateParameters PromptForInput()
{
var newVersion = AnsiConsole.Prompt(
new TextPrompt<string>("New Alpine version:")
.DefaultValue("3.XX"));

var oldVersion = AnsiConsole.Prompt(
new TextPrompt<string>("Previous Alpine version:")
.DefaultValue("3.XX"));

var publishDate = AnsiConsole.Prompt(
new TextPrompt<DateOnly>($"When was Alpine {newVersion} published?")
.DefaultValue(DateOnly.GetPatchTuesday(-1)));

const string DiscussionQueryLink = "https://github.com/dotnet/dotnet-docker/discussions/categories/announcements?discussions_q=is%3Aopen+category%3AAnnouncements+alpine";
var publishDiscussionUrl = AnsiConsole.Prompt(
new TextPrompt<string>($"Link to announcement for publishing Alpine {newVersion} images (see {DiscussionQueryLink}):"));

var releaseDate = AnsiConsole.Prompt(
new TextPrompt<DateOnly>($"When were floating tags moved from Alpine {oldVersion} to {newVersion}?")
.DefaultValue(DateOnly.GetPatchTuesday(0)));

var eolDate = AnsiConsole.Prompt(
new TextPrompt<DateOnly>($"When will we stop publishing Alpine {oldVersion} images?")
.DefaultValue(DateOnly.GetPatchTuesday(3)));

var dotnetExampleVersion = AnsiConsole.Prompt(
new TextPrompt<string>(".NET example version for tags:")
.DefaultValue("10.0"));

return new AlpineFloatingTagTemplateParameters(
newVersion,
oldVersion,
publishDate.ToDateTime(TimeOnly.MinValue),
releaseDate.ToDateTime(TimeOnly.MinValue),
eolDate.ToDateTime(TimeOnly.MinValue),
publishDiscussionUrl,
dotnetExampleVersion);
}
}

internal static class DateOnlyExtensions
{
extension(DateOnly date)
{
/// <summary>
/// Gets the Patch Tuesday (second Tuesday of the month) for a month
/// relative to the current month.
/// </summary>
/// <param name="offset">
/// The number of months from the current month.
/// 0 = this month, 1 = next month, -3 = three months ago.
/// </param>
/// <returns>The date of Patch Tuesday for the target month.</returns>
public static DateOnly GetPatchTuesday(int offset = 0)
{
var today = DateOnly.FromDateTime(DateTime.Today);
var targetMonth = today.AddMonths(offset);
var firstOfMonth = new DateOnly(targetMonth.Year, targetMonth.Month, 1);

// Find the first Tuesday
var daysUntilTuesday = ((int)DayOfWeek.Tuesday - (int)firstOfMonth.DayOfWeek + 7) % 7;
var firstTuesday = firstOfMonth.AddDays(daysUntilTuesday);

// Second Tuesday is 7 days later
return firstTuesday.AddDays(7);
}
}
}
23 changes: 23 additions & 0 deletions eng/announcement-templates/alpine-floating-tag-update.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Alpine Floating Tags Updated to Alpine {{ NewVersion }}

In {{ PublishDate | date: "%B %Y" }}, [Alpine {{ NewVersion }} container images were published]({{ PublishDiscussionUrl }}). For today's {{ ReleaseDate | date: "%B %Y" }} .NET release, all Alpine floating tags now point to Alpine {{ NewVersion }} instead of Alpine {{ OldVersion }} according to our [tagging policy](https://github.com/dotnet/dotnet-docker/blob/main/documentation/supported-tags.md).

Per the [.NET Docker platform support policy](https://github.com/dotnet/dotnet-docker/blob/main/documentation/supported-platforms.md#linux), Alpine {{ OldVersion }} images will no longer be maintained starting on {{ EolDate | date: "%B %-d, %Y" }} (3 months after Alpine {{ NewVersion }} images were released).

## Details

Please review the [Alpine {{ NewVersion }} changelog](https://alpinelinux.org/posts/Alpine-{{ NewVersion }}.0-released.html) for more details on changes that were made in this version of Alpine.

The affected floating tags use this naming pattern:

* `<version>-alpine` (e.g. `{{ DotnetExampleVersion }}-alpine`)
* `<version>-alpine-<variant>` (e.g. `{{ DotnetExampleVersion }}-alpine-extra`)
* `<version>-alpine-<arch>` (e.g. `{{ DotnetExampleVersion }}-alpine-amd64`)
* `<version>-alpine-<variant>-<arch>` (e.g. `{{ DotnetExampleVersion }}-alpine-extra-amd64`)

The following image repos have been updated:

* dotnet/sdk - [Microsoft Artifact Registry](https://mcr.microsoft.com/product/dotnet/sdk/about)
* dotnet/aspnet - [Microsoft Artifact Registry](https://mcr.microsoft.com/product/dotnet/aspnet/about)
* dotnet/runtime - [Microsoft Artifact Registry](https://mcr.microsoft.com/product/dotnet/runtime/about)
* dotnet/runtime-deps - [Microsoft Artifact Registry](https://mcr.microsoft.com/product/dotnet/runtime-deps/about)
Loading