Skip to content

Commit c6cb0b8

Browse files
committed
Update Unit Tests, refactor tool, make easier to test locally
1 parent 007fd32 commit c6cb0b8

24 files changed

+20393
-64
lines changed

.github/actions/project-build/run-command-for-every-tests-project.ps1

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,30 @@ $projectPath = $args[0]
1414
$projectName = Split-Path -Path $projectPath -Leaf
1515
$testsFolderPath = Join-Path -Path $projectPath -ChildPath "../tests"
1616
$global:exitCode = 0
17-
1817
$commandToExecute = $args[1]
18+
$allowNoTests = $args.Count -ge 3 -and $args[2] -eq "--allow-no-tests"
19+
20+
$testsFound = @(
21+
Get-ChildItem -Path $testsFolderPath -Directory -Recurse |
22+
Where-Object { $_.Name -match "^$projectName.*Tests$" }
23+
)
24+
25+
if ($testsFound.Count -eq 0) {
26+
if ($allowNoTests) {
27+
Write-Host "No test projects found for project '$projectName', but skipping due to --allow-no-tests flag."
28+
exit 0
29+
}
30+
else {
31+
Write-Host "No test projects found for project '$projectName'."
32+
exit 1
33+
}
34+
}
1935

20-
Get-ChildItem -Path $testsFolderPath -Directory -Recurse `
21-
| Where-Object { $_.Name -match "^$projectName.*Tests$" } `
22-
| ForEach-Object {
23-
$testsProjectName = $_.Name
36+
foreach ($testProject in $testsFound) {
37+
$testsProjectName = $testProject.Name
2438
$testsProjectPath = Join-Path -Path $testsFolderPath -ChildPath $testsProjectName
2539
Write-Host "Tests project found: $testsProjectPath. Executing a command: $commandToExecute"
40+
2641
try {
2742
bash -c "PROJECT_PATH=$testsProjectPath && $commandToExecute"
2843
if ($LASTEXITCODE -ne 0) {
@@ -39,6 +54,7 @@ Get-ChildItem -Path $testsFolderPath -Directory -Recurse `
3954
if ($global:exitCode -ne 0) {
4055
Write-Host "`nOne or more test commands failed."
4156
exit $global:exitCode
42-
} else {
57+
}
58+
else {
4359
Write-Host "`nAll test projects executed successfully."
4460
}

src/UnturnedRedistUpdateTool/GameInfoParser.cs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,32 @@
33

44
namespace UnturnedRedistUpdateTool;
55

6-
public class GameInfoParser
6+
public static class GameInfoParser
77
{
8-
public async Task<(string Version, string BuildId)> ParseAsync(string unturnedPath, string steamappsPath, string appId)
8+
public static string FindAppManifestFile(string unturnedPath, string appId)
99
{
10-
var node = JsonNode.Parse(await File.ReadAllTextAsync(Path.Combine(unturnedPath, "Status.json")))!["Game"]!;
11-
var version = $"3.{node["Major_Version"]}.{node["Minor_Version"]}.{node["Patch_Version"]}";
12-
var appmanifestFileName = $"appmanifest_{appId}.acf";
13-
var appmanifestFilePath = Path.Combine(steamappsPath, appmanifestFileName);
14-
if (!File.Exists(appmanifestFilePath))
10+
string[] possiblePath =
11+
[
12+
Path.Combine(unturnedPath, "steamapps", $"appmanifest_{appId}.acf"), // inside of Unturned folder
13+
Path.GetFullPath(Path.Combine(unturnedPath, "..", "..", $"appmanifest_{appId}.acf")) // outside of unturned folder
14+
];
15+
var appdataPath = possiblePath.FirstOrDefault(File.Exists);
16+
if (appdataPath == null)
17+
{
18+
throw new FileNotFoundException($"Required file is not found. Searched: {unturnedPath}", $"appmanifest_{appId}.acf");
19+
}
20+
return appdataPath;
21+
}
22+
public static async Task<(string Version, string BuildId)> ParseAsync(string unturnedPath, string appManifestPath)
23+
{
24+
var statusFilePath = Path.Combine(unturnedPath, "Status.json");
25+
if (!File.Exists(statusFilePath))
1526
{
16-
throw new FileNotFoundException("Required file is not found", appmanifestFilePath);
27+
throw new FileNotFoundException("Status file is not found", statusFilePath);
1728
}
18-
await using var file = File.OpenRead(appmanifestFilePath);
29+
var node = JsonNode.Parse(await File.ReadAllTextAsync(statusFilePath))!["Game"]!;
30+
var version = $"3.{node["Major_Version"]}.{node["Minor_Version"]}.{node["Patch_Version"]}";
31+
await using var file = File.OpenRead(appManifestPath);
1932
var kv = KVSerializer.Create(KVSerializationFormat.KeyValues1Text);
2033
var obj = kv.Deserialize(file);
2134
var buildId = obj["buildid"].ToString();

src/UnturnedRedistUpdateTool/Program.cs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ private static async Task<int> Main(string[] args)
1111

1212
AssertPlatformSupported();
1313

14+
#if DEBUG
15+
if (args.Length == 0)
16+
{
17+
args = [@"C:\Me\Apps\Steam\steamapps\common\Unturned", Path.Combine(AppContext.BaseDirectory, "TempRedist", "Client"), "304930", "--force"];
18+
}
19+
#endif
20+
1421
if (args.Length < 3)
1522
{
1623
Console.WriteLine("Wrong usage. Correct usage: UnturnedRedistUpdateTool.exe <unturned_path> <redist_path> <app_id> [args]");
@@ -50,26 +57,16 @@ private static async Task<int> Main(string[] args)
5057

5158
Console.WriteLine("Preparing to run tool...");
5259

53-
var steamappsDirectory = Path.Combine(unturnedPath, "steamapps");
54-
if (!Directory.Exists(steamappsDirectory))
55-
{
56-
Console.WriteLine($"steamapps Directory not found: \"{steamappsDirectory}\"");
57-
return 1;
58-
}
60+
var appManifestPath = GameInfoParser.FindAppManifestFile(unturnedPath, appId);
61+
5962
var unturnedDataPath = GetUnturnedDataDirectoryName();
6063
var managedDirectory = Path.Combine(unturnedDataPath, "Managed");
6164
if (!Directory.Exists(managedDirectory))
6265
{
6366
Console.WriteLine($"Unturned Managed Directory not found: \"{managedDirectory}\"");
6467
return 1;
6568
}
66-
const string statusFileName = "Status.json";
67-
var statusFilePath = Path.Combine(unturnedPath, statusFileName);
68-
if (!File.Exists(statusFilePath))
69-
{
70-
throw new FileNotFoundException("Status file is not found", statusFilePath);
71-
}
72-
var (newVersion, buildId) = await new GameInfoParser().ParseAsync(unturnedPath, steamappsDirectory, appId);
69+
var (newVersion, buildId) = await GameInfoParser.ParseAsync(unturnedPath, appManifestPath);
7370
if (string.IsNullOrWhiteSpace(newVersion))
7471
{
7572
Console.WriteLine("New Game Version is not found");
Binary file not shown.

0 commit comments

Comments
 (0)