Revert CliFx removal; fix macOS CI hang by setting WorkingDirectory on Exec

The macOS CI timeout was caused by `dotnet run` detecting the
`.csproj` file in the working directory and running the GUI project
instead of the `.csx` script. The GUI app would launch, try to
initialize Metal/Skia graphics (no display on CI), and hang until
the 10-minute job timeout.

Fix: Set `WorkingDirectory="$([System.IO.Path]::GetTempPath())"` on
the `<Exec>` element so `dotnet run` runs from a clean directory with
no project file, correctly treating the `.csx` as a file-based app.

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Tyrrrz/DiscordChatExporter/sessions/4e5ffe4c-7b2e-44b9-9477-5ea3d50e0ec0
This commit is contained in:
copilot-swe-agent[bot] 2026-03-23 21:08:41 +00:00
parent d8b46b5610
commit 824e1011ca
2 changed files with 118 additions and 92 deletions

View file

@ -56,7 +56,8 @@
<Target Name="PublishMacOSBundle" AfterTargets="Publish" Condition="$(PublishMacOSBundle)"> <Target Name="PublishMacOSBundle" AfterTargets="Publish" Condition="$(PublishMacOSBundle)">
<Exec <Exec
Command="dotnet run &quot;$(ProjectDir)/Publish-MacOSBundle.csx&quot; -- --publish-dir &quot;$(PublishDir)&quot; --icons-file &quot;$(ProjectDir)/../favicon.icns&quot; --full-version $(Version) --short-version $(AssemblyVersion)" Command="dotnet run &quot;$(ProjectDir)Publish-MacOSBundle.csx&quot; -- --publish-dir &quot;$(PublishDir)&quot; --icons-file &quot;$(ProjectDir)../favicon.icns&quot; --full-version $(Version) --short-version $(AssemblyVersion)"
WorkingDirectory="$([System.IO.Path]::GetTempPath())"
LogStandardErrorAsError="true" LogStandardErrorAsError="true"
/> />
</Target> </Target>

View file

@ -1,42 +1,61 @@
#!/usr/bin/env -S dotnet run -- #!/usr/bin/env -S dotnet run --
#:package CliFx
// Set up arguments using CliFx;
string GetArg(string name) using CliFx.Attributes;
using CliFx.Infrastructure;
return await new CliApplicationBuilder()
.AddCommand<PublishMacOSBundleCommand>()
.Build()
.RunAsync(args);
[Command(Description = "Publishes the GUI app as a macOS .app bundle.")]
public class PublishMacOSBundleCommand : ICommand
{ {
var idx = Array.IndexOf(args, name); private const string BundleName = "DiscordChatExporter.app";
if (idx < 0 || idx + 1 >= args.Length) private const string AppName = "DiscordChatExporter";
throw new InvalidOperationException($"Missing required option: {name}"); private const string AppCopyright = "© Oleksii Holub";
return args[idx + 1]; private const string AppIdentifier = "me.Tyrrrz.DiscordChatExporter";
} private const string AppSpokenName = "Discord Chat Exporter";
private const string AppIconName = "AppIcon";
var publishDirPathArg = GetArg("--publish-dir"); [CommandOption("publish-dir", Description = "Path to the publish output directory.")]
var iconsFilePathArg = GetArg("--icons-file"); public required string PublishDirPath { get; init; }
var fullVersionArg = GetArg("--full-version");
var shortVersionArg = GetArg("--short-version");
const string BundleName = "DiscordChatExporter.app"; [CommandOption("icons-file", Description = "Path to the .icns icons file.")]
const string AppName = "DiscordChatExporter"; public required string IconsFilePath { get; init; }
const string AppCopyright = "© Oleksii Holub";
const string AppIdentifier = "me.Tyrrrz.DiscordChatExporter";
const string AppSpokenName = "Discord Chat Exporter";
const string AppIconName = "AppIcon";
// Set up paths [CommandOption("full-version", Description = "Full version string (e.g. '1.2.3.4').")]
var publishDirPath = Path.GetFullPath(publishDirPathArg); public required string FullVersion { get; init; }
var tempDirPath = Path.GetFullPath(Path.Combine(publishDirPath, "../publish-macos-app-temp"));
// Ensure the temporary directory is clean before use in case a previous run crashed [CommandOption("short-version", Description = "Short version string (e.g. '1.2.3').")]
if (Directory.Exists(tempDirPath)) public required string ShortVersion { get; init; }
public async ValueTask ExecuteAsync(IConsole console)
{
// Set up paths
var publishDirPath = Path.GetFullPath(PublishDirPath);
var tempDirPath = Path.GetFullPath(
Path.Combine(publishDirPath, "../publish-macos-app-temp")
);
// Ensure the temporary directory is clean before use in case a previous run crashed
if (Directory.Exists(tempDirPath))
Directory.Delete(tempDirPath, true); Directory.Delete(tempDirPath, true);
var bundleDirPath = Path.Combine(tempDirPath, BundleName); var bundleDirPath = Path.Combine(tempDirPath, BundleName);
var contentsDirPath = Path.Combine(bundleDirPath, "Contents"); var contentsDirPath = Path.Combine(bundleDirPath, "Contents");
try try
{ {
// Copy icons into the .app's Resources folder // Copy icons into the .app's Resources folder
Directory.CreateDirectory(Path.Combine(contentsDirPath, "Resources")); Directory.CreateDirectory(Path.Combine(contentsDirPath, "Resources"));
File.Copy(iconsFilePathArg, Path.Combine(contentsDirPath, "Resources", "AppIcon.icns"), true); File.Copy(
IconsFilePath,
Path.Combine(contentsDirPath, "Resources", "AppIcon.icns"),
true
);
// Generate the Info.plist metadata file with the app information // Generate the Info.plist metadata file with the app information
// lang=xml // lang=xml
@ -62,9 +81,9 @@ try
<key>CFBundleIconName</key> <key>CFBundleIconName</key>
<string>{AppIconName}</string> <string>{AppIconName}</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>{fullVersionArg}</string> <string>{FullVersion}</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>{shortVersionArg}</string> <string>{ShortVersion}</string>
<key>NSHighResolutionCapable</key> <key>NSHighResolutionCapable</key>
<true /> <true />
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
@ -84,7 +103,11 @@ try
Directory.CreateDirectory(Path.Combine(contentsDirPath, "MacOS")); Directory.CreateDirectory(Path.Combine(contentsDirPath, "MacOS"));
foreach (var entryPath in Directory.GetFileSystemEntries(publishDirPath)) foreach (var entryPath in Directory.GetFileSystemEntries(publishDirPath))
{ {
var destinationPath = Path.Combine(contentsDirPath, "MacOS", Path.GetFileName(entryPath)); var destinationPath = Path.Combine(
contentsDirPath,
"MacOS",
Path.GetFileName(entryPath)
);
if (Directory.Exists(entryPath)) if (Directory.Exists(entryPath))
Directory.Move(entryPath, destinationPath); Directory.Move(entryPath, destinationPath);
@ -94,10 +117,12 @@ try
// Move the final bundle into the publish directory for upload // Move the final bundle into the publish directory for upload
Directory.Move(bundleDirPath, Path.Combine(publishDirPath, BundleName)); Directory.Move(bundleDirPath, Path.Combine(publishDirPath, BundleName));
} }
finally finally
{ {
// Clean up the temporary directory // Clean up the temporary directory
if (Directory.Exists(tempDirPath)) if (Directory.Exists(tempDirPath))
Directory.Delete(tempDirPath, true); Directory.Delete(tempDirPath, true);
}
}
} }