Files
Anubis/tools/Anubis.Tasks/Program.cs
T
Alby96andClaude Opus 5.5 b4bf864f74
ci / test (postgres) (push) Successful in 1m18s
ci / test (sqlite) (push) Successful in 1m23s
ci / image (push) Successful in 41s
Set up phase 0: .NET 10 solution, toolchain, minimal app, Docker and CI
Empty but complete solution so every later phase starts from a working
toolchain: analyzers as errors, locked restore, format check, policy tests
that keep packages within ADR 0004 and keep live trading switched off,
a /health endpoint served from Docker, and a Gitea workflow with only
run steps. API facts of SPEC section 4 re-checked in docs/API-NOTES.md;
ADR 0006 records what changed (MSTest base packages, Ubuntu images,
OKX WebSocket on 443, Alpaca margin-only accounts).

refs #1 refs #2 refs #3 refs #4 refs #5

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 09:51:41 +01:00

152 lines
4.9 KiB
C#

using System.Diagnostics;
using System.Globalization;
// Project commands (ADR 0003): the same steps on Windows and Linux, without make.
// Run through tasks.ps1 / tasks.sh, which build this tool apart from the solution.
var root = FindRoot();
var command = args.Length > 0 ? args[0].ToLowerInvariant() : "help";
var rest = args.Skip(1).ToArray();
return command switch
{
"check" => Check(),
"test" => Test(Environment.GetEnvironmentVariable("ANUBIS_TEST_DB") ?? "sqlite", rest),
"dev" => Run("dotnet", ["watch", "--project", "src/Anubis.Server", "run", .. rest]),
"build" => BuildImage("dev"),
"ci" => Ci(),
"seed-demo" => NotYet("seed-demo", 1),
"desktop-win" => NotYet("desktop-win", 10),
_ => Help(),
};
// Locked restore, formatting, build with analyzers as errors, tests on the engine in ANUBIS_TEST_DB.
int Check()
{
var engine = Environment.GetEnvironmentVariable("ANUBIS_TEST_DB") ?? "sqlite";
return Step("Ripristino dei pacchetti dai file di blocco", "dotnet", ["restore", "Anubis.slnx", "--locked-mode"])
?? Step("Controllo della formattazione", "dotnet", ["format", "Anubis.slnx", "--verify-no-changes", "--no-restore"])
?? Step("Compilazione con gli analizzatori", "dotnet", ["build", "Anubis.slnx", "--no-restore", "-c", "Release"])
?? Test(engine, ["--no-build", "-c", "Release"]);
}
int Test(string engine, string[] extra)
{
var env = new Dictionary<string, string> { ["ANUBIS_TEST_DB"] = engine, ["TESTINGPLATFORM_TELEMETRY_OPTOUT"] = "1" };
return Step($"Test su {engine}", "dotnet",
["test", "Anubis.slnx", "--filter", "TestCategory!=LiveDemo", "--logger", "console;verbosity=normal", .. extra], env) ?? 0;
}
// What the remote CI does, run locally: check on SQLite, tests on PostgreSQL, image build.
int Ci()
{
var failed = Check();
if (failed != 0)
{
return failed;
}
var ownPostgres = Environment.GetEnvironmentVariable("ANUBIS_TEST_PG_HOST") is null;
if (ownPostgres)
{
failed = Step("Avvio di PostgreSQL per i test", "docker", ["compose", "up", "-d", "--wait", "postgres"]) ?? 0;
if (failed != 0)
{
return failed;
}
}
try
{
failed = Test("postgres", ["--no-build", "-c", "Release"]);
}
finally
{
if (ownPostgres)
{
Step("Arresto di PostgreSQL", "docker", ["compose", "stop", "postgres"]);
}
}
return failed != 0 ? failed : BuildImage("ci");
}
int BuildImage(string tag) =>
Step("Costruzione dell'immagine Docker", "docker",
["build", "-f", "deploy/docker/Dockerfile", "-t", $"gitea.encke-hake.ts.net/balbosoft/anubis:{tag}", "."]) ?? 0;
int NotYet(string name, int phase)
{
Console.Error.WriteLine($"'tasks {name}' arriva nella Fase {phase.ToString(CultureInfo.InvariantCulture)}.");
return 2;
}
int Help()
{
Console.WriteLine("""
Comandi di Anubis (ADR 0003):
tasks check ripristino bloccato, formattazione, compilazione, test
tasks test solo i test (motore da ANUBIS_TEST_DB, predefinito sqlite)
tasks dev avvia il server e lo riavvia a ogni modifica
tasks build costruisce l'immagine Docker
tasks ci come la CI: check, test su PostgreSQL, immagine
tasks seed-demo dati dimostrativi (Fase 1)
tasks desktop-win installatore Windows (Fase 10)
""");
return command == "help" ? 0 : 1;
}
// Runs one step and returns its exit code only when it failed, so steps chain with ??.
int? Step(string title, string file, string[] arguments, Dictionary<string, string>? env = null)
{
Console.WriteLine();
Console.WriteLine($"== {title}");
var code = Run(file, arguments, env);
if (code != 0)
{
Console.Error.WriteLine($"!! {title}: non riuscito (codice {code.ToString(CultureInfo.InvariantCulture)})");
return code;
}
return null;
}
int Run(string file, string[] arguments, Dictionary<string, string>? env = null)
{
var info = new ProcessStartInfo(file) { WorkingDirectory = root, UseShellExecute = false };
foreach (var argument in arguments)
{
info.ArgumentList.Add(argument);
}
foreach (var (key, value) in env ?? [])
{
info.Environment[key] = value;
}
try
{
using var process = Process.Start(info)!;
process.WaitForExit();
return process.ExitCode;
}
catch (System.ComponentModel.Win32Exception ex)
{
Console.Error.WriteLine($"Impossibile avviare '{file}': {ex.Message}");
return 127;
}
}
static string FindRoot()
{
for (var dir = new DirectoryInfo(Environment.CurrentDirectory); dir is not null; dir = dir.Parent)
{
if (File.Exists(Path.Combine(dir.FullName, "Anubis.slnx")))
{
return dir.FullName;
}
}
throw new InvalidOperationException("Anubis.slnx non trovato: lancia i comandi dalla cartella del repository.");
}