-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Two features here: - Report summary and details as a comment on the associated PR (if any) - Issue :error: notices with the paths of the failed paths and the error message.
- Loading branch information
Showing
6 changed files
with
272 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
using System.Text; | ||
|
||
namespace Devlooped; | ||
|
||
static class Extensions | ||
{ | ||
public static StringBuilder AppendLineIndented(this StringBuilder builder, string value, string indent) | ||
{ | ||
foreach (var line in value.ReplaceLineEndings().Split(Environment.NewLine)) | ||
builder.Append(indent).AppendLine(line); | ||
|
||
return builder; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System; | ||
using System.Diagnostics; | ||
|
||
namespace Devlooped; | ||
|
||
static class Process | ||
{ | ||
public static bool TryExecute(string program, string arguments, out string? output) | ||
=> TryExecuteCore(program, arguments, null, out output); | ||
|
||
public static bool TryExecute(string program, string arguments, string input, out string? output) | ||
=> TryExecuteCore(program, arguments, input, out output); | ||
|
||
static bool TryExecuteCore(string program, string arguments, string? input, out string? output) | ||
{ | ||
var info = new ProcessStartInfo(program, arguments) | ||
{ | ||
RedirectStandardOutput = true, | ||
RedirectStandardError = true, | ||
RedirectStandardInput = input != null | ||
}; | ||
|
||
try | ||
{ | ||
var proc = System.Diagnostics.Process.Start(info); | ||
if (proc == null) | ||
{ | ||
output = null; | ||
return false; | ||
} | ||
|
||
var gotError = false; | ||
proc.ErrorDataReceived += (_, __) => gotError = true; | ||
|
||
if (input != null) | ||
{ | ||
// Write the input to the standard input stream | ||
proc.StandardInput.WriteLine(input); | ||
proc.StandardInput.Close(); | ||
} | ||
|
||
output = proc.StandardOutput.ReadToEnd(); | ||
if (!proc.WaitForExit(5000)) | ||
{ | ||
proc.Kill(); | ||
output = null; | ||
return false; | ||
} | ||
|
||
var error = proc.StandardError.ReadToEnd(); | ||
gotError |= error.Length > 0; | ||
output = output.Trim(); | ||
if (string.IsNullOrEmpty(output)) | ||
output = null; | ||
|
||
return !gotError && proc.ExitCode == 0; | ||
} | ||
catch (Exception ex) | ||
{ | ||
output = ex.Message; | ||
return false; | ||
} | ||
} | ||
} |
Oops, something went wrong.