fix(app): make --capture failures visible in CI
Mirror the log to stderr in capture mode, report how many screenshots were written, exit non-zero when none were, and print the capture log in the CI step with a warning annotation when no images are produced. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
4 files changed
+48
-9
No files matched your search
@@ -89,9 +89,14 @@ jobs:
|
|||||||
- name: Screenshots
|
- name: Screenshots
|
||||||
if: runner.os == 'Windows'
|
if: runner.os == 'Windows'
|
||||||
run: |
|
run: |
|
||||||
src/Titano.App/bin/Release/net10.0-windows/Titano.exe --capture out/screenshots &
|
set +e
|
||||||
|
src/Titano.App/bin/Release/net10.0-windows/Titano.exe --capture out/screenshots 2> out/capture.log &
|
||||||
wait $!
|
wait $!
|
||||||
ls -la out/screenshots
|
code=$?
|
||||||
|
cat out/capture.log
|
||||||
|
count=$(ls out/screenshots/*.png 2>/dev/null | wc -l)
|
||||||
|
echo "capture exit code $code, $count screenshot(s)"
|
||||||
|
if [ "$count" -eq 0 ]; then echo "::warning title=Screenshots::Titano --capture produced no images (exit $code)"; fi
|
||||||
|
|
||||||
- name: Publish desktop programs (win-x64, self-contained single file)
|
- name: Publish desktop programs (win-x64, self-contained single file)
|
||||||
if: runner.os == 'Windows'
|
if: runner.os == 'Windows'
|
||||||
|
|||||||
@@ -24,7 +24,9 @@ public partial class App : Application
|
|||||||
base.OnStartup(e);
|
base.OnStartup(e);
|
||||||
Environment = AppEnvironment.Detect();
|
Environment = AppEnvironment.Detect();
|
||||||
_log = new FileLogSink(Environment.LogDirectory, "titano");
|
_log = new FileLogSink(Environment.LogDirectory, "titano");
|
||||||
Log.SetSink(_log);
|
var capture = Array.IndexOf(e.Args, "--capture") >= 0;
|
||||||
|
// Capture runs in CI: mirror the log to stderr so failures are visible in the job output.
|
||||||
|
Log.SetSink(capture ? new TeeLogSink(_log, new StderrLogSink()) : _log);
|
||||||
Log.Info("app", $"Titano {typeof(App).Assembly.GetName().Version} starting; data at {Environment.DataDirectory}");
|
Log.Info("app", $"Titano {typeof(App).Assembly.GetName().Version} starting; data at {Environment.DataDirectory}");
|
||||||
|
|
||||||
Settings = AppSettings.Load(Environment.SettingsPath);
|
Settings = AppSettings.Load(Environment.SettingsPath);
|
||||||
@@ -45,7 +47,7 @@ public partial class App : Application
|
|||||||
MainWindow = window;
|
MainWindow = window;
|
||||||
|
|
||||||
var captureIndex = Array.IndexOf(e.Args, "--capture");
|
var captureIndex = Array.IndexOf(e.Args, "--capture");
|
||||||
if (captureIndex >= 0)
|
if (capture)
|
||||||
{
|
{
|
||||||
var dir = captureIndex + 1 < e.Args.Length ? e.Args[captureIndex + 1] : "screenshots";
|
var dir = captureIndex + 1 < e.Args.Length ? e.Args[captureIndex + 1] : "screenshots";
|
||||||
ScreenCapture.Run(window, shell, dir);
|
ScreenCapture.Run(window, shell, dir);
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ public static class ScreenCapture
|
|||||||
|
|
||||||
window.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, () =>
|
window.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, () =>
|
||||||
{
|
{
|
||||||
|
var written = 0;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
foreach (var theme in new[] { AppTheme.Dark, AppTheme.Light })
|
foreach (var theme in new[] { AppTheme.Dark, AppTheme.Light })
|
||||||
@@ -37,10 +38,11 @@ public static class ScreenCapture
|
|||||||
{
|
{
|
||||||
shell.Navigate(section.Key);
|
shell.Navigate(section.Key);
|
||||||
Settle(window);
|
Settle(window);
|
||||||
Save(window, Path.Combine(directory, $"{section.Key}-{theme.ToString().ToLowerInvariant()}.png"));
|
if (Save(window, Path.Combine(directory, $"{section.Key}-{theme.ToString().ToLowerInvariant()}.png"))) written++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log.Info("capture", $"Screenshots written to {Path.GetFullPath(directory)}");
|
Log.Info("capture", $"{written} screenshot(s) written to {Path.GetFullPath(directory)}");
|
||||||
|
if (written == 0) Environment.ExitCode = 1;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -62,19 +64,29 @@ public static class ScreenCapture
|
|||||||
window.UpdateLayout();
|
window.UpdateLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Save(Window window, string path)
|
private static bool Save(Window window, string path)
|
||||||
{
|
{
|
||||||
if (VisualTreeHelper.GetChildrenCount(window) == 0) return;
|
if (VisualTreeHelper.GetChildrenCount(window) == 0) window.ApplyTemplate();
|
||||||
|
if (VisualTreeHelper.GetChildrenCount(window) == 0)
|
||||||
|
{
|
||||||
|
Log.Warning("capture", "Window has no visual tree; nothing to render");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
var root = (FrameworkElement)VisualTreeHelper.GetChild(window, 0);
|
var root = (FrameworkElement)VisualTreeHelper.GetChild(window, 0);
|
||||||
var dpi = VisualTreeHelper.GetDpi(window);
|
var dpi = VisualTreeHelper.GetDpi(window);
|
||||||
var width = (int)Math.Ceiling(root.ActualWidth * dpi.DpiScaleX);
|
var width = (int)Math.Ceiling(root.ActualWidth * dpi.DpiScaleX);
|
||||||
var height = (int)Math.Ceiling(root.ActualHeight * dpi.DpiScaleY);
|
var height = (int)Math.Ceiling(root.ActualHeight * dpi.DpiScaleY);
|
||||||
if (width <= 0 || height <= 0) return;
|
if (width <= 0 || height <= 0)
|
||||||
|
{
|
||||||
|
Log.Warning("capture", $"Root element has no size ({root.ActualWidth}×{root.ActualHeight}); skipped {Path.GetFileName(path)}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
var bitmap = new RenderTargetBitmap(width, height, dpi.PixelsPerInchX, dpi.PixelsPerInchY, PixelFormats.Pbgra32);
|
var bitmap = new RenderTargetBitmap(width, height, dpi.PixelsPerInchX, dpi.PixelsPerInchY, PixelFormats.Pbgra32);
|
||||||
bitmap.Render(root);
|
bitmap.Render(root);
|
||||||
var encoder = new PngBitmapEncoder();
|
var encoder = new PngBitmapEncoder();
|
||||||
encoder.Frames.Add(BitmapFrame.Create(bitmap));
|
encoder.Frames.Add(BitmapFrame.Create(bitmap));
|
||||||
using var stream = File.Create(path);
|
using var stream = File.Create(path);
|
||||||
encoder.Save(stream);
|
encoder.Save(stream);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -114,3 +114,23 @@ public sealed class FileLogSink : ILogSink, IDisposable
|
|||||||
lock (_gate) _writer?.Dispose();
|
lock (_gate) _writer?.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Writes every event to several sinks.</summary>
|
||||||
|
public sealed class TeeLogSink(params ILogSink[] sinks) : ILogSink
|
||||||
|
{
|
||||||
|
public void Write(LogLevel level, string category, string message, Exception? exception)
|
||||||
|
{
|
||||||
|
foreach (var sink in sinks) sink.Write(level, category, message, exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Writes events to standard error (CI and command-line diagnostics).</summary>
|
||||||
|
public sealed class StderrLogSink : ILogSink
|
||||||
|
{
|
||||||
|
public void Write(LogLevel level, string category, string message, Exception? exception)
|
||||||
|
{
|
||||||
|
var line = string.Create(CultureInfo.InvariantCulture, $"{DateTime.UtcNow:O} {level,-7} {category}: {message}");
|
||||||
|
if (exception is not null) line += Environment.NewLine + exception;
|
||||||
|
Console.Error.WriteLine(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user