Skip to content

Commit 3289587

Browse files
authored
feat: compile test_app at runtime, delete ClientGeneratorService (#61)
- SimulationService: dotnet publish test_app/Client + Upgrade at runtime - Output .exe to Tools running dir/test_app/ folder - Copy to simulation output dir, run Client.exe with args - Delete ClientGeneratorService.cs and all .csx logic - Remove CI pre-compile steps (runtime build instead)
1 parent 6851d38 commit 3289587

3 files changed

Lines changed: 46 additions & 169 deletions

File tree

.github/workflows/publish.yml

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,6 @@ jobs:
2323
-p:IncludeAllContentForSelfExtract=true
2424
-o publish/win-x64
2525
26-
- name: Publish Client
27-
run: >
28-
dotnet publish test_app/Client/ClientSample.csproj
29-
-c Release -r win-x64
30-
-p:PublishSingleFile=true -p:PublishTrimmed=true --self-contained
31-
-o publish/test_app/Client
32-
33-
- name: Publish Upgrade
34-
run: >
35-
dotnet publish test_app/Upgrade/UpgradeSample.csproj
36-
-c Release -r win-x64
37-
-p:PublishSingleFile=true -p:PublishTrimmed=true --self-contained
38-
-o publish/test_app/Upgrade
39-
40-
- name: Copy test apps to Tools output
41-
run: |
42-
mkdir -p publish/win-x64/test_app
43-
cp publish/test_app/Client/ClientSample.exe publish/win-x64/test_app/Client.exe
44-
cp publish/test_app/Upgrade/UpgradeSample.exe publish/win-x64/test_app/Upgrade.exe
45-
4626
- name: Upload
4727
uses: actions/upload-artifact@v4
4828
with:

src/Services/ClientGeneratorService.cs

Lines changed: 0 additions & 137 deletions
This file was deleted.

src/Services/SimulationService.cs

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,37 @@ public async Task<SimulationResult> RunAsync(
3434
Log($"STEP 2: Preparing {config.OutputDirectory}", progress);
3535
Directory.CreateDirectory(config.OutputDirectory);
3636

37-
// 3. Copy test app executables
38-
Log("STEP 3: Copying test executables", progress);
37+
// 3. Compile test apps to .exe
38+
Log("STEP 3: Compiling test apps", progress);
3939
var toolsDir = AppDomain.CurrentDomain.BaseDirectory;
40-
var clientSrc = Path.Combine(toolsDir, "test_app", "Client.exe");
41-
var upgradeSrc = Path.Combine(toolsDir, "test_app", "Upgrade.exe");
40+
var clientProj = Path.Combine(toolsDir, "..", "..", "..", "..", "test_app", "Client", "ClientSample.csproj");
41+
var upgradeProj = Path.Combine(toolsDir, "..", "..", "..", "..", "test_app", "Upgrade", "UpgradeSample.csproj");
4242

43-
if (!File.Exists(clientSrc))
44-
throw new FileNotFoundException($"Client.exe not found at {clientSrc}. Ensure test_app is deployed.");
45-
if (!File.Exists(upgradeSrc))
46-
throw new FileNotFoundException($"Upgrade.exe not found at {upgradeSrc}. Ensure test_app is deployed.");
43+
// Normalize paths
44+
clientProj = Path.GetFullPath(clientProj);
45+
upgradeProj = Path.GetFullPath(upgradeProj);
4746

47+
if (!File.Exists(clientProj))
48+
throw new FileNotFoundException($"Client project not found at {clientProj}");
49+
if (!File.Exists(upgradeProj))
50+
throw new FileNotFoundException($"Upgrade project not found at {upgradeProj}");
51+
52+
var exeDir = Path.Combine(toolsDir, "test_app");
53+
Directory.CreateDirectory(exeDir);
54+
55+
Log(" Compiling Client.exe...", progress);
56+
await DotNetPublishAsync(clientProj, exeDir);
57+
Log($" Client.exe → {exeDir}", progress);
58+
59+
Log(" Compiling Upgrade.exe...", progress);
60+
await DotNetPublishAsync(upgradeProj, exeDir);
61+
Log($" Upgrade.exe → {exeDir}", progress);
62+
63+
// Copy to simulation output
4864
var clientDest = Path.Combine(config.OutputDirectory, "Client.exe");
4965
var upgradeDest = Path.Combine(config.OutputDirectory, "Upgrade.exe");
50-
File.Copy(clientSrc, clientDest, true);
51-
File.Copy(upgradeSrc, upgradeDest, true);
52-
Log($" Client.exe → {config.OutputDirectory}", progress);
53-
Log($" Upgrade.exe → {config.OutputDirectory}", progress);
66+
File.Copy(Path.Combine(exeDir, "ClientSample.exe"), clientDest, true);
67+
File.Copy(Path.Combine(exeDir, "UpgradeSample.exe"), upgradeDest, true);
5468

5569
// 4. Start server
5670
Log("STEP 4: Starting local server", progress);
@@ -109,6 +123,26 @@ public async Task<SimulationResult> RunAsync(
109123
return result;
110124
}
111125

126+
private static async Task DotNetPublishAsync(string projectPath, string outputDir)
127+
{
128+
var psi = new ProcessStartInfo("dotnet", $"publish \"{projectPath}\" -c Release -r win-x64 -p:PublishSingleFile=true --self-contained -p:PublishTrimmed=true -o \"{outputDir}\"")
129+
{
130+
RedirectStandardOutput = true,
131+
RedirectStandardError = true,
132+
UseShellExecute = false,
133+
CreateNoWindow = true
134+
};
135+
using var p = Process.Start(psi)!;
136+
var outTask = p.StandardOutput.ReadToEndAsync();
137+
var errTask = p.StandardError.ReadToEndAsync();
138+
await p.WaitForExitAsync();
139+
if (p.ExitCode != 0)
140+
{
141+
var err = await errTask;
142+
throw new InvalidOperationException($"dotnet publish failed (exit {p.ExitCode}):\n{err}");
143+
}
144+
}
145+
112146
private void Validate(SimulateConfigModel config)
113147
{
114148
if (!Directory.Exists(config.AppDirectory))

0 commit comments

Comments
 (0)