CI / Build and test (SQLite) (pull_request) Successful in 43s
CI / PostgreSQL 16 integration (pull_request) Skipped
CI / PostgreSQL 17 integration (pull_request) Skipped
CI / YAML check (pull_request) Successful in 15s
CI / Docker image (pull_request) Successful in 59s
Start development with the skeleton every later milestone builds on, so that code, image and release path exist and are verified from day one. - Khaemhat.sln with the ten projects of SPEC section 3 and six MSTest projects; shared build rules with warnings as errors, analyzers and Central Package Management restricted to the allowlist. - Architecture tests and scripts/check-packages.sh fail on any project reference or package that SPEC does not allow. - Khaemhat.Web serves an Italian "under construction" page with the official icons and version, plus /health/live, /health/ready and /health (ADR 0012); honours KHAEMHAT_URLS and KHAEMHAT_LOG_LEVEL. - docker/Dockerfile (non-root app user aligned to PUID/PGID by the entrypoint, pg_dump 17, healthcheck, OCI and Unraid labels) and compose files for PostgreSQL and a standalone SQLite demo. - Gitea Actions: ci.yml (build, tests, image smoke test, PostgreSQL 16/17 on tags, YAML check), release.yml (image and release from a vX.Y.Z tag, skipping versions already published) and wiki.yml. - Development scripts, VS Code launch/tasks for debugging, and ADR 0012-0017 deciding the M0 open points of docs/STATUS.md. Closes #1, #2, #3, #4, #5, #114 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
89 lines
3.8 KiB
C#
89 lines
3.8 KiB
C#
using System.Xml.Linq;
|
|
|
|
namespace Khaemhat.Core.Tests.Architecture;
|
|
|
|
/// <summary>Reads the solution's project files from the repository, without loading the projects.</summary>
|
|
internal static class RepositoryLayout
|
|
{
|
|
private static readonly Lazy<string> RootPath = new(FindRoot);
|
|
|
|
/// <summary>The repository root (the folder holding <c>Khaemhat.sln</c>).</summary>
|
|
public static string Root => RootPath.Value;
|
|
|
|
/// <summary>Every project file under <c>src/</c>, <c>tests/</c> and <c>tools/</c>, by project name.</summary>
|
|
public static IReadOnlyDictionary<string, string> Projects()
|
|
{
|
|
var result = new Dictionary<string, string>(StringComparer.Ordinal);
|
|
foreach (var folder in new[] { "src", "tests", "tools" })
|
|
{
|
|
var path = Path.Combine(Root, folder);
|
|
if (!Directory.Exists(path))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
foreach (var file in Directory.EnumerateFiles(path, "*.csproj", SearchOption.AllDirectories))
|
|
{
|
|
if (!IsBuildOutput(file))
|
|
{
|
|
result[Path.GetFileNameWithoutExtension(file)] = file;
|
|
}
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>Names of the projects referenced by a project file.</summary>
|
|
public static IReadOnlySet<string> ProjectReferences(string projectFile) =>
|
|
Includes(projectFile, "ProjectReference")
|
|
.Select(include => Path.GetFileNameWithoutExtension(include.Replace('\\', '/')))
|
|
.ToHashSet(StringComparer.Ordinal);
|
|
|
|
/// <summary>Package ids referenced by a project or props file.</summary>
|
|
public static IReadOnlySet<string> PackageReferences(string file) =>
|
|
Includes(file, "PackageReference").ToHashSet(StringComparer.OrdinalIgnoreCase);
|
|
|
|
/// <summary>Every MSBuild file (projects, props, targets) of the repository that could declare packages.</summary>
|
|
public static IEnumerable<string> MsBuildFiles() =>
|
|
Directory.EnumerateFiles(Root, "*.*", SearchOption.AllDirectories)
|
|
.Where(f => f.EndsWith(".csproj", StringComparison.OrdinalIgnoreCase)
|
|
|| f.EndsWith(".props", StringComparison.OrdinalIgnoreCase)
|
|
|| f.EndsWith(".targets", StringComparison.OrdinalIgnoreCase))
|
|
.Where(f => !IsBuildOutput(f) && !IsUnderIgnoredFolder(f));
|
|
|
|
/// <summary>The path of a file relative to the repository root, with forward slashes.</summary>
|
|
public static string Relative(string file) => Path.GetRelativePath(Root, file).Replace('\\', '/');
|
|
|
|
private static IEnumerable<string> Includes(string file, string element) =>
|
|
XDocument.Load(file).Descendants()
|
|
.Where(e => e.Name.LocalName == element)
|
|
.Select(e => (string?)e.Attribute("Include") ?? (string?)e.Attribute("Update") ?? string.Empty)
|
|
.Where(s => s.Length > 0);
|
|
|
|
private static bool IsBuildOutput(string path)
|
|
{
|
|
var p = path.Replace('\\', '/');
|
|
return p.Contains("/bin/", StringComparison.Ordinal) || p.Contains("/obj/", StringComparison.Ordinal);
|
|
}
|
|
|
|
private static bool IsUnderIgnoredFolder(string path)
|
|
{
|
|
var relative = Relative(path);
|
|
return relative.StartsWith(".git/", StringComparison.Ordinal)
|
|
|| relative.StartsWith(".claude/", StringComparison.Ordinal)
|
|
|| relative.StartsWith("out/", StringComparison.Ordinal);
|
|
}
|
|
|
|
private static string FindRoot()
|
|
{
|
|
var dir = new DirectoryInfo(AppContext.BaseDirectory);
|
|
while (dir is not null && !File.Exists(Path.Combine(dir.FullName, "Khaemhat.sln")))
|
|
{
|
|
dir = dir.Parent;
|
|
}
|
|
|
|
return dir?.FullName ?? throw new InvalidOperationException("Repository root (Khaemhat.sln) not found.");
|
|
}
|
|
}
|