Skip to content

Commit 66f3a27

Browse files
authored
feat: skip recompilation on cached test apps + bundle in CI release (#70)
SimulationService Step 3: three-tier strategy 1. Cache hit: if Client.exe/Upgrade.exe already exist in AppDirectory → skip 2. Release bundle: if test_app_exe/ exists next to tools → copy pre-built 3. Dev compile: if source (csproj) exists → dotnet publish CI (publish.yml): compile test apps during build and package into publish/{rid}/test_app_exe/. Released packages work without SDK or source code.
1 parent b8554c8 commit 66f3a27

2 files changed

Lines changed: 62 additions & 30 deletions

File tree

.github/workflows/publish.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ jobs:
1414
with:
1515
dotnet-version: 10.0.x
1616

17+
- name: Build test apps (Client + Upgrade)
18+
run: |
19+
dotnet publish test_app/Client/ClientSample.csproj -c Release -r win-x64 -p:PublishSingleFile=true --self-contained -o prebuilt
20+
dotnet publish test_app/Upgrade/UpgradeSample.csproj -c Release -r win-x64 -p:PublishSingleFile=true --self-contained -o prebuilt
21+
1722
- name: Publish Tools
1823
run: >
1924
dotnet publish src/GeneralUpdate.Tools.csproj
@@ -23,6 +28,9 @@ jobs:
2328
-p:IncludeAllContentForSelfExtract=true
2429
-o publish/win-x64
2530
31+
- name: Copy test apps into publish output
32+
run: xcopy prebuilt\* publish\win-x64\test_app_exe\ /Y /I
33+
2634
- name: Upload
2735
uses: actions/upload-artifact@v4
2836
with:
@@ -39,6 +47,11 @@ jobs:
3947
with:
4048
dotnet-version: 10.0.x
4149

50+
- name: Build test apps (Client + Upgrade)
51+
run: |
52+
dotnet publish test_app/Client/ClientSample.csproj -c Release -r linux-x64 -p:PublishSingleFile=true --self-contained -o prebuilt
53+
dotnet publish test_app/Upgrade/UpgradeSample.csproj -c Release -r linux-x64 -p:PublishSingleFile=true --self-contained -o prebuilt
54+
4255
- name: Publish Tools
4356
run: >
4457
dotnet publish src/GeneralUpdate.Tools.csproj
@@ -48,6 +61,9 @@ jobs:
4861
-p:IncludeAllContentForSelfExtract=true
4962
-o publish/linux-x64
5063
64+
- name: Copy test apps into publish output
65+
run: mkdir -p publish/linux-x64/test_app_exe && cp prebuilt/* publish/linux-x64/test_app_exe/
66+
5167
- name: Upload
5268
uses: actions/upload-artifact@v4
5369
with:

src/Services/SimulationService.cs

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

37-
// 3. Compile test apps to .exe
38-
Log("STEP 3: Compiling test apps", progress);
37+
// 3. Ensure test apps are available
38+
Log("STEP 3: Preparing test apps", progress);
3939
var toolsDir = AppDomain.CurrentDomain.BaseDirectory;
40-
var clientProj = Path.Combine(toolsDir, "..", "..", "..", "..", "test_app", "Client", "ClientSample.csproj");
41-
var upgradeProj = Path.Combine(toolsDir, "..", "..", "..", "..", "test_app", "Upgrade", "UpgradeSample.csproj");
42-
43-
// Normalize paths
44-
clientProj = Path.GetFullPath(clientProj);
45-
upgradeProj = Path.GetFullPath(upgradeProj);
46-
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 compiled apps into app directory (where the update will run)
6440
var clientDest = Path.Combine(config.AppDirectory, "Client.exe");
65-
File.Copy(Path.Combine(exeDir, "ClientSample.exe"), clientDest, true);
41+
var upgradeDest = Path.Combine(config.AppDirectory, "Upgrade.exe");
6642

67-
var upgradeExe = Path.Combine(exeDir, "UpgradeSample.exe");
68-
File.Copy(upgradeExe, Path.Combine(config.AppDirectory, "Upgrade.exe"), true);
69-
Log($" Upgrade.exe → {config.AppDirectory}", progress);
43+
if (File.Exists(clientDest) && File.Exists(upgradeDest))
44+
{
45+
Log(" Test apps already cached, skipping", progress);
46+
}
47+
else
48+
{
49+
// Strategy 1: bundled exes (release package)
50+
var bundledDir = Path.Combine(toolsDir, "test_app_exe");
51+
if (Directory.Exists(bundledDir) &&
52+
File.Exists(Path.Combine(bundledDir, "ClientSample.exe")) &&
53+
File.Exists(Path.Combine(bundledDir, "UpgradeSample.exe")))
54+
{
55+
Log(" Copying bundled test apps...", progress);
56+
File.Copy(Path.Combine(bundledDir, "ClientSample.exe"), clientDest, true);
57+
File.Copy(Path.Combine(bundledDir, "UpgradeSample.exe"), upgradeDest, true);
58+
Log($" Client.exe → {config.AppDirectory}", progress);
59+
Log($" Upgrade.exe → {config.AppDirectory}", progress);
60+
}
61+
else
62+
{
63+
// Strategy 2: compile from source (dev environment)
64+
var clientProj = Path.GetFullPath(Path.Combine(toolsDir, "..", "..", "..", "..", "test_app", "Client", "ClientSample.csproj"));
65+
var upgradeProj = Path.GetFullPath(Path.Combine(toolsDir, "..", "..", "..", "..", "test_app", "Upgrade", "UpgradeSample.csproj"));
66+
67+
if (!File.Exists(clientProj) || !File.Exists(upgradeProj))
68+
throw new FileNotFoundException("Test apps not found. Run in dev environment or use a release build that includes test_app_exe.");
69+
70+
var exeDir = Path.Combine(toolsDir, "test_app");
71+
Directory.CreateDirectory(exeDir);
72+
73+
Log(" Compiling Client.exe...", progress);
74+
await DotNetPublishAsync(clientProj, exeDir);
75+
Log($" Client.exe → {exeDir}", progress);
76+
77+
Log(" Compiling Upgrade.exe...", progress);
78+
await DotNetPublishAsync(upgradeProj, exeDir);
79+
Log($" Upgrade.exe → {exeDir}", progress);
80+
81+
File.Copy(Path.Combine(exeDir, "ClientSample.exe"), clientDest, true);
82+
File.Copy(Path.Combine(exeDir, "UpgradeSample.exe"), upgradeDest, true);
83+
Log($" Copied to {config.AppDirectory}", progress);
84+
}
85+
}
7086

7187
// 4. Start server
7288
Log("STEP 4: Starting local server", progress);

0 commit comments

Comments
 (0)