refactor!: rename Titano to Chronos and move CI and releases to Gitea (#6)
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
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
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>
This commit was merged in pull request #6.
This commit is contained in:
1 parent
c99842cc86
commit
f2b58522b9
1801 files changed
+11804
-10676
No files matched your search
@@ -0,0 +1,226 @@
|
||||
using System.IO;
|
||||
using Chronos.App.Editor;
|
||||
using Chronos.App.Infrastructure;
|
||||
using Chronos.Core.Diagnostics;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Data;
|
||||
using Chronos.Data.Jobs;
|
||||
using Chronos.Data.Sync;
|
||||
using Chronos.Protocol.Client;
|
||||
|
||||
namespace Chronos.App.Server;
|
||||
|
||||
/// <summary>Makes the sync connection of a signed-in session.</summary>
|
||||
public delegate ISyncRemote SyncRemoteFactory(Uri address, string token, IReadOnlyCollection<string> trustedFingerprints);
|
||||
|
||||
/// <summary>
|
||||
/// This PC's sync with the signed-in server (BRIEF §4.4, §14.5): the <see cref="SyncService"/> of the index, the
|
||||
/// connection of upload and download jobs (<see cref="ISyncConnector"/>), a <see cref="SyncAgent"/> that keeps the
|
||||
/// table current while a session is open, started and stopped in order as the session changes, the
|
||||
/// <see cref="UploadHold"/> for metered connections, the connections of editors of server sequences
|
||||
/// (<see cref="ConnectEditor"/>) and the Export "Sync" of finished renders (<see cref="ExportSync"/>). Options come from
|
||||
/// <see cref="AppSettings.SyncSettingsAutomatically"/>, <see cref="AppSettings.KeepProxiesOffline"/> and
|
||||
/// <see cref="AppSettings.PauseUploadsOnMetered"/>.
|
||||
/// </summary>
|
||||
public sealed class SyncHost(AppServices services) : ISyncConnector, IAsyncDisposable
|
||||
{
|
||||
/// <summary>How long a job resumed at start waits for the saved session to be restored.</summary>
|
||||
private static readonly TimeSpan RestoreWait = TimeSpan.FromSeconds(30);
|
||||
|
||||
private Task _switch = Task.CompletedTask;
|
||||
private Credentials? _credentials;
|
||||
private Running? _running;
|
||||
private JobEngine? _renders;
|
||||
|
||||
/// <summary>Connections over <see cref="ChronosClient"/>; screenshots substitute a fake server.</summary>
|
||||
public SyncRemoteFactory RemoteFactory { get; set; } = (address, token, trusted) =>
|
||||
new ChronosSyncRemote(new ChronosClient(address, new CertificatePinning(trusted), $"Chronos ({Environment.MachineName})") { Token = token }, ownsClient: true);
|
||||
|
||||
/// <summary>Connections of editors of server sequences over <see cref="ChronosClient"/>; screenshots substitute a fake server.</summary>
|
||||
public RemoteSequenceApiFactory EditorFactory { get; set; } = (address, token, trusted) =>
|
||||
new ChronosRemoteSequenceApi(new ChronosClient(address, new CertificatePinning(trusted), $"Chronos ({Environment.MachineName})") { Token = token });
|
||||
|
||||
/// <summary>The engine; null until the index is open.</summary>
|
||||
public SyncService? Service { get; private set; }
|
||||
|
||||
/// <summary>The background comparison of the signed-in server; null while signed out.</summary>
|
||||
public SyncAgent? Agent => Volatile.Read(ref _running)?.Agent;
|
||||
|
||||
/// <summary>The agent's connection, for the table's own calls (conflict resolution); null while signed out.</summary>
|
||||
public ISyncRemote? Remote => Volatile.Read(ref _running)?.Remote;
|
||||
|
||||
/// <summary>Key of the signed-in server (<see cref="SyncService.ServerKey"/>); null while signed out.</summary>
|
||||
public string? Server => Volatile.Read(ref _credentials) is { } c ? SyncService.ServerKey(c.Address) : null;
|
||||
|
||||
/// <summary>The options, and whether the account may change server sequences (without it this PC's edits are not sent).</summary>
|
||||
public SyncPolicy Policy => new(services.Settings.SyncSettingsAutomatically, services.Settings.KeepProxiesOffline, Allows(Permissions.Edit));
|
||||
|
||||
/// <summary>The signed-in account may send files (originals, renders) to the server.</summary>
|
||||
public bool CanUpload => Allows(Permissions.Upload);
|
||||
|
||||
/// <summary>The signed-in account may queue renders on the server.</summary>
|
||||
public bool CanRender => Allows(Permissions.Render);
|
||||
|
||||
/// <summary>Pauses uploads while the connection is metered and the option is on.</summary>
|
||||
public UploadHold Uploads { get; } = new(services);
|
||||
|
||||
/// <summary>The agent started, stopped or compared, or the table of the signed-in server changed (any thread).</summary>
|
||||
public event Action? Changed;
|
||||
|
||||
/// <summary>Creates the engine over the open index; the proxy cache lives in the client's cache folder.</summary>
|
||||
public SyncService Open(ChronosDatabase database, Chronos.Data.Archiving.ArchiveService archives, Chronos.Data.Archiving.ArchiveServiceOptions options)
|
||||
{
|
||||
var cache = CacheStore.Folder(services.Environment, services.Settings);
|
||||
Service = new SyncService(database, archives, new SyncOptions { Archive = options, ProxyCacheDirectory = Path.Combine(cache, "proxies") });
|
||||
Service.Changed += server =>
|
||||
{
|
||||
if (server == Server) Changed?.Invoke();
|
||||
};
|
||||
return Service;
|
||||
}
|
||||
|
||||
/// <summary>Follows the server session (UI thread): starts the agent for a new sign-in, stops it on sign-out.</summary>
|
||||
public void Update()
|
||||
{
|
||||
var session = services.Server;
|
||||
Credentials? wanted = session.IsConnected && session.Flow is { Address: { } address, Token: { } token }
|
||||
? new Credentials(address, token, session.Fingerprints)
|
||||
: null;
|
||||
Volatile.Write(ref _credentials, wanted);
|
||||
_switch = SwitchAsync(_switch, wanted);
|
||||
if (services.Engine is not { } engine) return;
|
||||
Uploads.Attach(engine);
|
||||
if (ReferenceEquals(_renders, engine)) return;
|
||||
if (_renders is not null) _renders.JobChanged -= OnJobChanged;
|
||||
_renders = engine;
|
||||
engine.JobChanged += OnJobChanged;
|
||||
}
|
||||
|
||||
/// <summary>A connection for the editor of a sequence of the signed-in server; null while signed out.</summary>
|
||||
public IRemoteSequenceApi? ConnectEditor() =>
|
||||
Volatile.Read(ref _credentials) is { } c ? EditorFactory(c.Address, c.Token, c.Fingerprints) : null;
|
||||
|
||||
/// <summary>Compares now, once the session switch in progress settled; null while signed out.</summary>
|
||||
public async Task<SyncSnapshot?> RefreshAsync(CancellationToken ct = default)
|
||||
{
|
||||
await _switch.ConfigureAwait(false);
|
||||
return Agent is { } agent ? await agent.RefreshAsync(ct).ConfigureAwait(false) : null;
|
||||
}
|
||||
|
||||
/// <summary>Compares again soon (an option changed, an edit on this PC).</summary>
|
||||
public void RequestRefresh() => Agent?.RequestRefresh();
|
||||
|
||||
/// <summary>The archive downloaded originals go to when a sequence has no local copy: the one this PC works with.</summary>
|
||||
public async Task<Archive?> CurrentArchiveAsync(CancellationToken ct = default)
|
||||
{
|
||||
if (services.Database is not { } db) return null;
|
||||
var archives = await db.Archives.ListAsync(ct);
|
||||
if (services.Settings.LastArchivePath is { Length: > 0 } root)
|
||||
{
|
||||
var full = Path.GetFullPath(root).TrimEnd(Path.DirectorySeparatorChar);
|
||||
if (archives.FirstOrDefault(a => string.Equals(Path.GetFullPath(a.RootPath).TrimEnd(Path.DirectorySeparatorChar), full, StringComparison.OrdinalIgnoreCase))
|
||||
is { } current) return current;
|
||||
}
|
||||
return archives.Count == 1 ? archives[0] : null;
|
||||
}
|
||||
|
||||
public async ValueTask<ISyncRemote?> ConnectAsync(string server, CancellationToken cancellationToken)
|
||||
{
|
||||
// A job resumed at start runs before the saved session is restored: give the restore a moment.
|
||||
var until = DateTime.UtcNow + RestoreWait;
|
||||
while (Volatile.Read(ref _credentials) is null && services.Settings.ProtectedToken is not null && DateTime.UtcNow < until)
|
||||
await Task.Delay(500, cancellationToken);
|
||||
if (Volatile.Read(ref _credentials) is not { } c || SyncService.ServerKey(c.Address) != server) return null;
|
||||
CacheStore.Prepare(CacheStore.Folder(services.Environment, services.Settings));
|
||||
return RemoteFactory(c.Address, c.Token, c.Fingerprints);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops the agent once the session switch in progress settled. The app's exit waits for this on the UI thread, so
|
||||
/// nothing here, in the switch or in the stop continues on it.
|
||||
/// </summary>
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
Volatile.Write(ref _credentials, null);
|
||||
Uploads.Dispose();
|
||||
if (_renders is not null) _renders.JobChanged -= OnJobChanged;
|
||||
await _switch.ConfigureAwait(false);
|
||||
await StopAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private bool Allows(Permissions permission) => services.Server.User is { } user && (user.Permissions & (long)permission) != 0;
|
||||
|
||||
/// <summary>
|
||||
/// Export "Sync": a render of this PC that asked for it is sent to the server once done (<see cref="ExportSync"/>),
|
||||
/// also when it ends while the session is down: the send is queued for the saved session's server and waits for it.
|
||||
/// </summary>
|
||||
private void OnJobChanged(Job job)
|
||||
{
|
||||
if (job is not { Kind: JobKind.Render, State: JobState.Done } || Service is not { } service || services.Database is not { } db || _renders is not { } engine)
|
||||
return;
|
||||
var signedIn = Server;
|
||||
_ = SendRenderAsync(new ExportSync(db, service, engine), job, signedIn ?? SavedServer(), signedIn is null || CanUpload);
|
||||
}
|
||||
|
||||
/// <summary>Key of the server of the saved session (Disconnect keeps it); null without one.</summary>
|
||||
private string? SavedServer() =>
|
||||
services.Server.HasSavedSession && ServerAddress.TryParse(services.Settings.ServerUrl, out var address) ? SyncService.ServerKey(address) : null;
|
||||
|
||||
private static async Task SendRenderAsync(ExportSync exports, Job job, string? server, bool canUpload)
|
||||
{
|
||||
try
|
||||
{
|
||||
switch (await exports.SendAsync(job, server, canUpload))
|
||||
{
|
||||
case { Send: { } send }:
|
||||
Log.Info("sync", $"{job.TargetLabel} will be sent to the server (job {send.Id})");
|
||||
break;
|
||||
case { Gate: var gate }:
|
||||
Log.Warning("sync", $"{job.TargetLabel} asked to be sent to the server but was not ({gate})");
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception ex) when (ex is not OutOfMemoryException)
|
||||
{
|
||||
// Nobody awaits this: the render itself succeeded, and the send can be asked for again on the Server screen.
|
||||
Log.Warning("sync", $"The render {job.TargetLabel} could not be queued for the server", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Switches are chained (each waits for the previous one) and continue on the thread pool: a switch still stopping
|
||||
/// the old agent when the app exits must not need the UI thread its exit blocks.
|
||||
/// </summary>
|
||||
private async Task SwitchAsync(Task previous, Credentials? wanted)
|
||||
{
|
||||
await previous.ConfigureAwait(false);
|
||||
if (Volatile.Read(ref _running) is { } running && wanted is { } same && running.Credentials.Address == same.Address && running.Credentials.Token == same.Token)
|
||||
return;
|
||||
await StopAsync().ConfigureAwait(false);
|
||||
if (wanted is not { } start || Service is not { } service)
|
||||
{
|
||||
Changed?.Invoke();
|
||||
return;
|
||||
}
|
||||
var remote = RemoteFactory(start.Address, start.Token, start.Fingerprints);
|
||||
var agent = new SyncAgent(service, remote, () => Policy, services.Engine);
|
||||
agent.Changed += () => Changed?.Invoke();
|
||||
agent.Start();
|
||||
Volatile.Write(ref _running, new Running(agent, remote, start));
|
||||
Log.Info("sync", $"Comparing with {remote.Server}");
|
||||
Changed?.Invoke();
|
||||
}
|
||||
|
||||
private async Task StopAsync()
|
||||
{
|
||||
if (Interlocked.Exchange(ref _running, null) is not { } running) return;
|
||||
await running.Agent.DisposeAsync().ConfigureAwait(false);
|
||||
running.Remote.Dispose();
|
||||
Changed?.Invoke();
|
||||
}
|
||||
|
||||
private sealed record Credentials(Uri Address, string Token, IReadOnlyCollection<string> Fingerprints);
|
||||
|
||||
/// <summary>The agent of the signed-in session: one reference, so the UI thread never reads half of a switch.</summary>
|
||||
private sealed record Running(SyncAgent Agent, ISyncRemote Remote, Credentials Credentials);
|
||||
}
|
||||
Reference in new issue
Block a user