Skip to content

Commit

Permalink
feat: fully implement version-specific branching and directory structure
Browse files Browse the repository at this point in the history
  • Loading branch information
ChecksumDev committed Jul 16, 2024
1 parent 51a418c commit 53a3c49
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions MBSS/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ namespace MBSS
{
internal class BeatSaberVersion
{
[JsonProperty("version")]
[JsonProperty("version")]
public string Version { get; set; } = string.Empty;

[JsonProperty("manifest")]
[JsonProperty("manifest")]
public string Manifest { get; set; } = string.Empty;
}

Expand Down Expand Up @@ -50,18 +50,20 @@ public static async Task Main(string[] args)
foreach (var version in versions)

Check warning on line 50 in MBSS/Program.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 50 in MBSS/Program.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
{
var downloadPath = Path.Combine("downloads", version.Version);
var versionPath = Path.Combine(Directory.GetCurrentDirectory(), version.Version);
var versionPath = Path.Combine(Directory.GetCurrentDirectory(), "data");

if (Directory.Exists(versionPath))
var branchName = $"versions/{version.Version}";
if (Directory.Exists(versionPath) &&
File.ReadAllText(Path.Combine(versionPath, "version.txt")).Trim() == version.Version)
{
AnsiConsole.MarkupLine($"[yellow]Version {version.Version} already exists, skipping...[/]");
AnsiConsole.MarkupLine($"[yellow]Version {version.Version} already exists in branch {branchName}, skipping...[/]");
continue;
}

await GetAndStrip(version, downloadPath, versionPath);
AnsiConsole.MarkupLine($"[green]Version {version.Version} stripped![/]");

await CommitAndPushVersion(version);
await CommitAndPushVersion(version, branchName, versionPath);
}
}

Expand Down Expand Up @@ -176,6 +178,8 @@ private static async Task GetAndStrip(BeatSaberVersion version, string downloadP
await RunProcess(GenericStripperExe, $"strip -m beatsaber -p \"{downloadPath}\" -o \"{versionPath}\"");

if (Directory.Exists(downloadPath)) Directory.Delete(downloadPath, true);

await File.WriteAllTextAsync(Path.Combine(versionPath, "version.txt"), version.Version);
}

private static async Task RunProcess(string fileName, string arguments)
Expand All @@ -197,19 +201,18 @@ private static async Task RunProcess(string fileName, string arguments)
await process.WaitForExitAsync();
}

private static async Task CommitAndPushVersion(BeatSaberVersion version)
private static async Task CommitAndPushVersion(BeatSaberVersion version, string branchName, string versionPath)

Check warning on line 204 in MBSS/Program.cs

View workflow job for this annotation

GitHub Actions / build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 204 in MBSS/Program.cs

View workflow job for this annotation

GitHub Actions / build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
using var repo = new Repository(Directory.GetCurrentDirectory());
var author = new Signature(Environment.GetEnvironmentVariable("GIT_AUTHOR_NAME"), Environment.GetEnvironmentVariable("GIT_AUTHOR_EMAIL"), DateTimeOffset.Now);

var branchName = $"version/{version.Version}";
var branch = repo.Branches[branchName] ?? repo.CreateBranch(branchName);
Commands.Checkout(repo, branch);

var status = repo.RetrieveStatus();
if (!status.IsDirty) return; // No changes, skip
if (!status.IsDirty) return;

Commands.Stage(repo, Path.Combine(Directory.GetCurrentDirectory(), version.Version));
Commands.Stage(repo, "*");
repo.Commit($"chore: v{version.Version}", author, author);

var remote = repo.Network.Remotes["origin"];
Expand All @@ -236,4 +239,4 @@ private static async Task SetupDotEnv()
}
}
}
}
}

0 comments on commit 53a3c49

Please sign in to comment.