Files
Chronos/src/Chronos.Tools/Commands/ChangelogCommand.cs
T
Alby96andClaude Opus 5.5 f2b58522b9
CI / Build and test (push) Successful in 8m14s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 13m19s
CI / PostgreSQL 16 integration (push) Successful in 4m49s
CI / PostgreSQL 17 integration (push) Successful in 5m28s
CI / Docker image (push) Successful in 53s
Release / Server image (push) Failing after 10s
refactor!: rename Titano to Chronos and move CI and releases to Gitea (#6)
The owner renamed the product and moved the repository to the self-hosted
Gitea (https://gitea.encke-hake.ts.net/BalboSoft/Chronos) for more control,
and asked for Actions and a first automatic release with the server package
and the Windows exe (docs/requests/2026-10-23-chronos-gitea.md).

- Chronos everywhere: a byte-exact rename of contents and paths, then a
  per-language review of the forms the old name's ending had dictated.
- Gitea instead of GitHub: the update check, licence, issue and support
  links read ChronosReleasesUrl; the update check takes the highest stable
  version, offers a pre-release build its final release and reports a
  repository it cannot see as a failed check. EULA, security policy and
  Gitea issue forms live at the repository root.
- Gitea Actions for the Linux act_runner (.gitea/workflows): CI, release,
  nightly image and performance gates in the .NET SDK container with git
  checkout and the system SQLite. The release cross-compiles the Windows
  programs, checks their icon, version and DPI manifest, packs installers
  and zips, publishes the Gitea release and pushes the server image
  (REGISTRY_TOKEN). Windows-only tests run in an opt-in job on a Windows
  runner (WINDOWS_RUNNER).
- New Chronos.Tools commands: zip, gitea-release, postgres-ci (replaces the
  docker-exec script, which Gitea's service containers do not allow; the
  throw-away server runs without durability) and pe-check.
- Timed tests take their budget from TestTiming (CHRONOS_TEST_TIME_FACTOR,
  3 on the shared runner; the weekly performance gates keep theirs).

BREAKING CHANGE: programs, settings, data folders, file types, environment
variables and the Docker image use the new name; nothing is migrated from
Titano, which never had a release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
2026-10-23 12:45:18 +02:00

95 lines
3.5 KiB
C#

using System.Text;
using System.Text.RegularExpressions;
namespace Chronos.Tools.Commands;
/// <summary>
/// Builds release notes from Conventional Commits. Reads <c>git log --format=%h%x09%s</c> lines from stdin
/// (or <c>--in file</c>) and writes Markdown grouped by type.
/// </summary>
internal sealed partial class ChangelogCommand : ICommand
{
private static readonly (string Type, string Heading)[] Sections =
[
("feat", "Added"),
("fix", "Fixed"),
("perf", "Performance"),
("security", "Security"),
("i18n", "Localization"),
("docs", "Documentation"),
];
public string Name => "changelog";
public string Summary => "Release notes from Conventional Commits on stdin (--title, --out file)";
public async Task<int> RunAsync(string[] args)
{
var a = new Args(args);
IReadOnlyList<string> input = a.Get("in") is { } file ? await File.ReadAllLinesAsync(file) : ReadStdin();
var markdown = Render(input, a.Get("title"));
if (a.Get("out") is { } outFile)
{
Directory.CreateDirectory(Path.GetDirectoryName(Path.GetFullPath(outFile))!);
await File.WriteAllTextAsync(outFile, markdown, new UTF8Encoding(false));
}
else
{
Console.Write(markdown);
}
return 0;
}
internal static string Render(IEnumerable<string> lines, string? title)
{
var groups = new Dictionary<string, List<string>>(StringComparer.Ordinal);
var breaking = new List<string>();
foreach (var line in lines)
{
var tab = line.IndexOf('\t');
var hash = tab > 0 ? line[..tab] : string.Empty;
var subject = tab > 0 ? line[(tab + 1)..] : line;
var m = Conventional().Match(subject);
if (!m.Success) continue;
var type = m.Groups["type"].Value.ToLowerInvariant();
var scope = m.Groups["scope"].Success ? $"**{m.Groups["scope"].Value}**: " : string.Empty;
var entry = $"- {scope}{m.Groups["desc"].Value.Trim()}{(hash.Length > 0 ? $" ({hash})" : string.Empty)}";
if (m.Groups["bang"].Success) breaking.Add(entry);
if (!groups.TryGetValue(type, out var list)) groups[type] = list = [];
list.Add(entry);
}
var sb = new StringBuilder();
if (title is not null) sb.Append("# ").AppendLine(title).AppendLine();
// The title alone says nothing about the release: the fallback depends on the entries written, not on the text.
var written = false;
if (breaking.Count > 0)
{
sb.AppendLine("### Breaking changes");
foreach (var e in breaking) sb.AppendLine(e);
sb.AppendLine();
written = true;
}
foreach (var (type, heading) in Sections)
{
if (!groups.TryGetValue(type, out var entries)) continue;
sb.Append("### ").AppendLine(heading);
foreach (var e in entries) sb.AppendLine(e);
sb.AppendLine();
written = true;
}
if (!written) sb.AppendLine("Maintenance release.");
return sb.ToString();
}
private static List<string> ReadStdin()
{
var lines = new List<string>();
if (!Console.IsInputRedirected) return lines;
while (Console.In.ReadLine() is { } line) lines.Add(line);
return lines;
}
[GeneratedRegex(@"^(?<type>[a-zA-Z]+)(?:\((?<scope>[^)]+)\))?(?<bang>!)?:\s*(?<desc>.+)$")]
private static partial Regex Conventional();
}