Skip to content

Commit

Permalink
add diffs
Browse files Browse the repository at this point in the history
  • Loading branch information
goaaats committed Jul 30, 2022
1 parent 224cbd4 commit 00add1b
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 7 deletions.
73 changes: 71 additions & 2 deletions Plogon/BuildProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Json;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Docker.DotNet;
Expand Down Expand Up @@ -152,7 +155,67 @@ async Task GetDep(string name, NugetLockfile.Dependency dependency)
});
}

public async Task<bool> ProcessTask(BuildTask task, bool commit)
private class HasteResponse
{
[JsonPropertyName("key")]
public string Key { get; set; }
};

private async Task<string> GetDiffUrl(DirectoryInfo workDir, string haveCommit, string wantCommit)
{
if (string.IsNullOrEmpty(haveCommit))
{
var revListPsi = new ProcessStartInfo("git", "rev-list --max-parents=0 HEAD")
{
RedirectStandardOutput = true,
WorkingDirectory = workDir.FullName,
};

var revListProcess = Process.Start(revListPsi);
if (revListProcess == null)
throw new Exception("Could not start rev-list");

haveCommit = Regex.Replace(revListProcess.StandardOutput.ReadToEnd(), @"\t|\n|\r", "");

if (revListProcess.ExitCode != 0)
throw new Exception("Rev-list did not succeed");

Log.Information("Using {NewRev} as have", haveCommit);
}

var diffPsi = new ProcessStartInfo("git",
$"diff --submodule=diff {haveCommit}..{wantCommit}")
{
RedirectStandardOutput = true,
WorkingDirectory = workDir.FullName,
};

var process = Process.Start(diffPsi);
if (process == null)
throw new Exception("Diff process was null.");

var output = await process.StandardOutput.ReadToEndAsync();

if (process.ExitCode != 0)
throw new Exception($"Git could not diff: {process.ExitCode} -- {diffPsi.Arguments}");

using var client = new HttpClient();
var res = await client.PostAsync("https://haste.soulja-boy-told.me/documents", new StringContent(output));
res.EnsureSuccessStatusCode();

var json = await res.Content.ReadFromJsonAsync<HasteResponse>();

return $"https://haste.soulja-boy-told.me/{json!.Key}.diff";
}

public class BuildResult
{
public bool Success { get; set; }

public string DiffUrl { get; set; }
}

public async Task<BuildResult> ProcessTask(BuildTask task, bool commit)
{
var folderName = $"{task.InternalName}-{task.Manifest.Plugin.Commit}";
var work = this.workFolder.CreateSubdirectory($"{folderName}-work");
Expand Down Expand Up @@ -201,6 +264,8 @@ public async Task<bool> ProcessTask(BuildTask task, bool commit)
}
});
}

var diffUrl = await GetDiffUrl(work, task.HaveCommit!, task.Manifest.Plugin.Commit);

var dalamudAssemblyDir = await this.dalamudReleases.GetDalamudAssemblyDirAsync(task.Channel);

Expand Down Expand Up @@ -314,7 +379,11 @@ await this.dockerClient.Containers.RemoveContainerAsync(containerCreateResponse.
}
}

return exitCode == 0;
return new BuildResult
{
DiffUrl = diffUrl,
Success = exitCode == 0,
};
}

public class PluginCommitException : Exception
Expand Down
12 changes: 7 additions & 5 deletions Plogon/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,18 @@ static async Task Main(DirectoryInfo outputFolder, DirectoryInfo manifestFolder,
task.HaveCommit ?? "nothing");
var status = await buildProcessor.ProcessTask(task, commit);

if (!status)
if (status.Success)
{
Log.Error("Could not build: {Name} - {Sha}", task.InternalName,
task.Manifest.Plugin.Commit);
Log.Information("Built: {Name} - {Sha} - {DiffUrl}", task.InternalName,
task.Manifest.Plugin.Commit, status.DiffUrl);

buildsMd.AddRow("✔️", task.InternalName, task.Manifest.Plugin.Commit, string.Empty);
buildsMd.AddRow("✔️", task.InternalName, task.Manifest.Plugin.Commit, $"[Diff]({status.DiffUrl})");
}
else
{
buildsMd.AddRow("", task.InternalName, task.Manifest.Plugin.Commit, "Build failed");
Log.Error("Could not build: {Name} - {Sha}", task.InternalName,
task.Manifest.Plugin.Commit);
buildsMd.AddRow("", task.InternalName, task.Manifest.Plugin.Commit, $"Build failed ([Diff]({status.DiffUrl}))");
}
}
catch (BuildProcessor.PluginCommitException ex)
Expand Down

0 comments on commit 00add1b

Please sign in to comment.