From 25773649e1d6211b7ebb1ae11653f82fcc528cf5 Mon Sep 17 00:00:00 2001 From: Kyle Burrows Date: Sat, 15 Mar 2025 17:27:36 -0400 Subject: [PATCH 1/3] pair the command output with the commands that caused the output --- README.md | 40 +++++-- src/ShellRunner/CommandBuilder.cs | 93 +++++++++-------- src/ShellRunner/CommandBuilderOptions.cs | 1 + src/ShellRunner/CommandOutput.cs | 3 - src/ShellRunner/CommandRunner.cs | 76 +------------- src/ShellRunner/CompletionToken.cs | 82 +++++++++++++++ src/ShellRunner/GetOutputCommand.cs | 50 --------- src/ShellRunner/IProcessedCommand.cs | 25 +++++ src/ShellRunner/Output.cs | 6 ++ src/ShellRunner/ProcessCommand.cs | 126 +++++++++++++++++++++-- src/ShellRunner/ShellRunner.csproj | 29 +++--- src/ShellRunner/TypicalCommand.cs | 14 --- src/TestApp/Program.cs | 108 ++++++++++--------- src/TestApp/TestApp.csproj | 2 +- 14 files changed, 393 insertions(+), 262 deletions(-) delete mode 100644 src/ShellRunner/CommandOutput.cs create mode 100644 src/ShellRunner/CompletionToken.cs delete mode 100644 src/ShellRunner/GetOutputCommand.cs create mode 100644 src/ShellRunner/IProcessedCommand.cs create mode 100644 src/ShellRunner/Output.cs delete mode 100644 src/ShellRunner/TypicalCommand.cs diff --git a/README.md b/README.md index 6982569..34cf31c 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,47 @@ # ShellRunner -Run command line tools inside CSharp. +Run command line tools using CSharp. + +Supports Windows and Linux (Powershell, bash, and cmd). Example running some dotnet CLI commands: ```csharp using ShellRunner; -CommandRunner +CommandBuilder cb = await CommandRunner .UsePowershell() .StartProcess() // print the dotnet info command .AddCommand("dotnet --info") // build a csharp project - .AddCommand("cd C:\\source\\repos\\MyProject") - .AddCommand("dotnet build MyProject.sln -c Release") - // Print the output - .AddCommand("cd bin\\Release") - .AddCommand("Get-ChildItem -r") - .Run(); + .AddCommand(@"cd C:\source\repos\MyProject") + .AddCommand("dotnet build MyProject.sln -c Release", key: "build-output") + // Print the file list + .AddCommand(@"cd bin\Release\net8.0") + .AddCommand("Get-ChildItem -r", key: "files") + .RunAsync(); ``` Shell Runner is really useful to create a wrapper for several other -commands and to work with data before or after you run the commands. \ No newline at end of file +commands and to work with data before or after you run the commands. + +After running the commands you can optionally access the output of each command +separately so you know the result of each command specifically. + +```csharp +Console.WriteLine("Outputs:"); + +// the outputs are organized by command +foreach (var cmd in cb.Commands) + foreach(var output in cmd.Output) + Console.WriteLine(" " + output.Data); + +// OR use keys declared above +var buildCmd = cb.GetCommand("build-output").Output; + +Console.ForegroundColor = ConsoleColor.Blue; + +foreach(var output in buildCmd) + Console.WriteLine(" " + output.Data); +``` \ No newline at end of file diff --git a/src/ShellRunner/CommandBuilder.cs b/src/ShellRunner/CommandBuilder.cs index c399d73..8ac8867 100644 --- a/src/ShellRunner/CommandBuilder.cs +++ b/src/ShellRunner/CommandBuilder.cs @@ -1,78 +1,89 @@ -using System; -using System.Diagnostics; +using System.Diagnostics; namespace ShellRunner; + public class CommandBuilder { - CommandBuilderOptions _options; + CommandBuilderOptions options; + List commands; + Dictionary commandMap; public ProcessStartInfo StartInfo { get; set; } public Process Process { get; set; } + public IReadOnlyList Commands => commands.AsReadOnly(); internal CommandBuilder(CommandBuilderOptions options, Process process) { Process = process; - Commands = new List(); - - _options = options; + commands = new List(); + this.commandMap = new Dictionary(); + + this.options = options; StartInfo = new ProcessStartInfo { - FileName = options.File, - Arguments = options.Args, + FileName = this.options.File, + Arguments = this.options.Args, CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden, UseShellExecute = false, - RedirectStandardOutput = options.RedirectStandardOutput, - RedirectStandardError = options.RedirectStandardError, - RedirectStandardInput = options.RedirectStandardInput + RedirectStandardOutput = this.options.RedirectStandardOutput, + RedirectStandardError = this.options.RedirectStandardError, + RedirectStandardInput = this.options.RedirectStandardInput }; } - public List Commands { get; private set; } - - public CommandBuilder AddWorkingDirectory(string workingDirectory) + /// + /// Add a command to the command list. + /// + /// + /// When a duplicate key is added. + public void AddCommand(ProcessCommand command) { - StartInfo.WorkingDirectory = workingDirectory; - return this; + this.commands.Add(command); + + if(this.commandMap.ContainsKey(command.Key)) + throw new ArgumentException($"Command with key \"{command.Key}\" already exists."); + + this.commandMap.Add(command.Key, command); } - private void Proc_ErrorDataReceived(object sender, DataReceivedEventArgs e) + /// + /// Get a specific command by key. + /// + /// The key for the command ran earlier. + /// + /// When a key isn't present in the dictionary. + public IProcessedCommand GetCommand(string key) { try { - if (e.Data is null) - return; - - var fg = Console.ForegroundColor; - Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine($"Error: {e.Data}"); - Console.ForegroundColor = fg; + return this.commandMap[key]; } - catch(Exception ex) + catch (KeyNotFoundException) { - var fg = Console.ForegroundColor; - Console.ForegroundColor = ConsoleColor.Red; - Console.WriteLine("Error while processing error data."); - Console.WriteLine(ex); - Console.ForegroundColor = fg; + throw new KeyNotFoundException($"Command with key \"{key}\" not found."); } } - private void Proc_OutputDataReceived(object sender, DataReceivedEventArgs e) + public CommandBuilder AddWorkingDirectory(string workingDirectory) { - try - { - Console.WriteLine(e.Data); - } - catch (Exception ex) + StartInfo.WorkingDirectory = workingDirectory; + return this; + } + + public async Task RunAsync(CancellationToken cancellationToken = default) + { + foreach(var command in commands) { - var fg = Console.ForegroundColor; - Console.ForegroundColor = ConsoleColor.Red; - Console.WriteLine("Error while processing output data."); - Console.WriteLine(ex); - Console.ForegroundColor = fg; + if (cancellationToken.IsCancellationRequested) + break; + + await command.RunCommandAsync(this.Process, cancellationToken); } + + return this; } + } diff --git a/src/ShellRunner/CommandBuilderOptions.cs b/src/ShellRunner/CommandBuilderOptions.cs index db610e3..af9d7b4 100644 --- a/src/ShellRunner/CommandBuilderOptions.cs +++ b/src/ShellRunner/CommandBuilderOptions.cs @@ -2,6 +2,7 @@ namespace ShellRunner; +[DebuggerDisplay("{Shell} {File} {Args}")] public record CommandBuilderOptions { public CommandBuilderOptions(ShellType shellType, string file, string args) diff --git a/src/ShellRunner/CommandOutput.cs b/src/ShellRunner/CommandOutput.cs deleted file mode 100644 index 01b8ad0..0000000 --- a/src/ShellRunner/CommandOutput.cs +++ /dev/null @@ -1,3 +0,0 @@ -namespace ShellRunner; - -public record CommandOutput(string Command, string? Output); \ No newline at end of file diff --git a/src/ShellRunner/CommandRunner.cs b/src/ShellRunner/CommandRunner.cs index f1f5447..bbfad1d 100644 --- a/src/ShellRunner/CommandRunner.cs +++ b/src/ShellRunner/CommandRunner.cs @@ -71,34 +71,6 @@ public static CommandBuilder StartProcess(this CommandBuilderOptions options) proc.Start(); - proc.OutputDataReceived += (o,e) => { - try - { - if(e.Data is not null) - PrintOutputData(e.Data); - } - catch (Exception ex) - { - PrintErrorData("Error while processing error data."); - PrintErrorData(ex.ToString()); - } - }; - proc.ErrorDataReceived += (o,e) => { - try - { - if (e.Data is not null) - PrintErrorData(e.Data); - } - catch (Exception ex) - { - PrintErrorData("Error while processing error data."); - PrintErrorData(ex.ToString()); - } - }; - - proc.BeginOutputReadLine(); - proc.BeginErrorReadLine(); - var builder = new CommandBuilder(options, proc); return builder; @@ -106,54 +78,12 @@ public static CommandBuilder StartProcess(this CommandBuilderOptions options) public static CommandBuilder AddCommand(this CommandBuilder builder, string command) { - builder.Commands.Add(new TypicalCommand(command)); + builder.AddCommand(new ProcessCommand(command, key:Guid.NewGuid().ToString())); return builder; } - public static CommandBuilder AddCommandWithOutput(this CommandBuilder builder, string command) + public static CommandBuilder AddCommand(this CommandBuilder builder, string command, string key) { - builder.Commands.Add(new GetOutputCommand(command)); + builder.AddCommand(new ProcessCommand(command, key: key)); return builder; } - - public static List Run(this CommandBuilder builder) - { - foreach(var cmd in builder.Commands) - { - cmd.RunCommand(builder.Process); - builder.Process.Refresh(); - } - - builder.Process.Refresh(); - - builder.Process.StandardInput.WriteLine("exit"); - - builder.Process.WaitForExit(); - - builder.Process.Close(); - - var outputs = new List(); - - foreach(var cmd in builder.Commands) - { - if(cmd is GetOutputCommand) - { - var output = (GetOutputCommand)cmd; - outputs.Add(new CommandOutput(output.Command, output.Output)); - } - } - - return outputs; - } - - private static void PrintErrorData(string data) - { - var fg = Console.ForegroundColor; - Console.ForegroundColor = ConsoleColor.Red; - Console.WriteLine(data); - Console.ForegroundColor = fg; - } - private static void PrintOutputData(string data) - { - Console.WriteLine(data); - } } \ No newline at end of file diff --git a/src/ShellRunner/CompletionToken.cs b/src/ShellRunner/CompletionToken.cs new file mode 100644 index 0000000..10925d4 --- /dev/null +++ b/src/ShellRunner/CompletionToken.cs @@ -0,0 +1,82 @@ +using System.Diagnostics; + +namespace ShellRunner; + +/// +/// Represents a signal that is sent to the STD_IN stream after a command +/// is ran that when detected in the STD_OUT stream notifies the system +/// when the command has finished running. +/// +struct CompletionToken +{ + public CompletionToken() + { + this.Value = Guid.NewGuid().ToString(); + } + + public string Value { get; } + + public static bool operator ==(CompletionToken a, CompletionToken b) => + a.Value == b.Value; + public static bool operator !=(CompletionToken a, CompletionToken b) => + a.Value != b.Value; + + public static bool operator ==(CompletionToken a, object b) + { + if (b is CompletionToken ct) + return a.Value == ct.Value; + + if(b is string str) + return a.Value == str; + + return false; + } + public static bool operator !=(CompletionToken a, object b) + { + if (b is CompletionToken ct) + return a.Value != ct.Value; + + if (b is string str) + return a.Value != str; + + return true; + } + public static bool operator ==(object b, CompletionToken a) + { + if (b is CompletionToken ct) + return a.Value == ct.Value; + + if (b is string str) + return a.Value == str; + + return false; + } + public static bool operator !=(object b, CompletionToken a) + { + if (b is CompletionToken ct) + return a.Value != ct.Value; + + if (b is string str) + return a.Value != str; + + return true; + } + public override bool Equals(object? obj) + { + if (obj is null) + return false; + + if (obj is CompletionToken ct) + return ct.Value == this.Value; + + return false; + } + public override int GetHashCode() => + Value.GetHashCode(); + + public void SendCompletionSignal(Process process) + { + process.StandardInput.WriteLine($"echo {Value}"); + process.StandardInput.Flush(); + } +} diff --git a/src/ShellRunner/GetOutputCommand.cs b/src/ShellRunner/GetOutputCommand.cs deleted file mode 100644 index ac94132..0000000 --- a/src/ShellRunner/GetOutputCommand.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System.Diagnostics; - -namespace ShellRunner; - -public class GetOutputCommand : ProcessCommand -{ - Process? _process; - - public GetOutputCommand(string command) - : base(command) { } - - public string? Output { get; private set; } - - protected override void Run(Process process) - { - _process = process; - _process.OutputDataReceived += Process_OutputDataReceived; - - process.StandardInput.WriteLine(Command); - } - - bool _outputIncoming = false; - private void Process_OutputDataReceived(object sender, DataReceivedEventArgs e) - { - try - { - if(e.Data is not null) - { - if(_outputIncoming) - { - Output = e.Data; - _outputIncoming = false; - _process!.OutputDataReceived -= Process_OutputDataReceived; - } - - if (e.Data.EndsWith(Command)) - { - _outputIncoming = true; - } - } - } - catch(Exception ex) - { - var fg = Console.ForegroundColor; - Console.ForegroundColor = ConsoleColor.Red; - Console.WriteLine(ex); - Console.ForegroundColor = fg; - } - } -} diff --git a/src/ShellRunner/IProcessedCommand.cs b/src/ShellRunner/IProcessedCommand.cs new file mode 100644 index 0000000..cfe8bfc --- /dev/null +++ b/src/ShellRunner/IProcessedCommand.cs @@ -0,0 +1,25 @@ +namespace ShellRunner; + +/// +/// An interface for the parts of a command that are needed after the command has been run. +/// +public interface IProcessedCommand +{ + /// + /// The original command that was ran. + /// + string Command { get; } + /// + /// The key that the command was stored under. This key is typically automatically generated but you can + /// provide a custom key using AddCommand(command: "echo bar", key: "foo"). + /// + string Key { get; } + /// + /// List of the outputs of the command. + /// + IReadOnlyList Output { get; } + /// + /// True if the command has an error. + /// + bool IsError { get; } +} diff --git a/src/ShellRunner/Output.cs b/src/ShellRunner/Output.cs new file mode 100644 index 0000000..9f81244 --- /dev/null +++ b/src/ShellRunner/Output.cs @@ -0,0 +1,6 @@ +using System.Diagnostics; + +namespace ShellRunner; + +[DebuggerDisplay("{IsError ? \"Error: \" : \"\"}{Data}")] +public record struct Output(bool IsError, string Data); diff --git a/src/ShellRunner/ProcessCommand.cs b/src/ShellRunner/ProcessCommand.cs index e802c63..b9764dc 100644 --- a/src/ShellRunner/ProcessCommand.cs +++ b/src/ShellRunner/ProcessCommand.cs @@ -1,24 +1,59 @@ using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; namespace ShellRunner; -public abstract class ProcessCommand +/// +/// A Process Command. +/// +public class ProcessCommand : IProcessedCommand { + readonly CompletionToken completionToken; + readonly TaskCompletionSource outputCompletion; + readonly List output; - string _command; - public ProcessCommand(string command) + public ProcessCommand(string command, string key) { - _command = command; + this.Command = command; + this.completionToken = new CompletionToken(); + this.outputCompletion = new TaskCompletionSource(); + this.output = new List(); + this.Key = key; } - public string Command - => _command; + public string Command { get; } + public string Key { get; } + public IReadOnlyList Output => output.AsReadOnly(); + public bool IsError { get; private set; } - public void RunCommand(Process process) + /// + /// Run this command. + /// + /// The process to run the command on + /// + /// + public async Task RunCommandAsync(Process process, CancellationToken cancellationToken) { try { - Run(process); + process.OutputDataReceived += Process_OutputDataReceived; + process.ErrorDataReceived += Process_ErrorDataReceived; + + process.BeginOutputReadLine(); + process.BeginErrorReadLine(); + + await RunAsync(process, cancellationToken); + + // send a signal to look for in the output so you know the command is finished + this.completionToken.SendCompletionSignal(process); + + await Task.WhenAny( + this.outputCompletion.Task, + OrCancelWhen(cancellationToken) + ); + + process.CancelOutputRead(); + process.CancelErrorRead(); } catch(Exception ex) { @@ -28,7 +63,80 @@ public void RunCommand(Process process) Console.WriteLine(ex); Console.ForegroundColor = fg; } + finally + { + // cleanup events + process.OutputDataReceived -= Process_OutputDataReceived; + process.ErrorDataReceived -= Process_ErrorDataReceived; + } + } + + // this event is ran when this command receives output data from STD_OUT + private void Process_OutputDataReceived(object sender, DataReceivedEventArgs e) + { + if(isValidData(e.Data)) + { + output.Add(new Output(IsError: false, e.Data)); + } } - protected abstract void Run(Process process); + // this event is ran when this command receives output data from STD_ERROR + private void Process_ErrorDataReceived(object sender, DataReceivedEventArgs e) + { + if (isValidData(e.Data)) + { + output.Add(new Output(IsError: true, e.Data)); + } + IsError = true; + } + + + bool isValidData([NotNullWhen(true)] string? output) + { + if(output is null) + { + return false; + } + + if (output == this.completionToken) + { + // this is the completion signal so stop waiting for output + outputCompletion.TrySetResult(); + return false; + } + + if (output.EndsWith(this.completionToken.Value)) + { + // return false so we don't save the output for the completion token + return false; + } + + // valid data so return true + return true; + } + + /// + /// Run this task. + /// + /// + /// + /// + protected virtual Task RunAsync(Process process, CancellationToken cancellationToken) + { + cancellationToken.ThrowIfCancellationRequested(); + + process.StandardInput.WriteLine(Command); + + return Task.CompletedTask; + } + + /// + /// Creates a task that watches the cancellation token for cancellation. + /// + static Task OrCancelWhen(CancellationToken cancellationToken) + { + var tcs = new TaskCompletionSource(); + cancellationToken.Register(() => tcs.TrySetResult()); + return tcs.Task; + } } diff --git a/src/ShellRunner/ShellRunner.csproj b/src/ShellRunner/ShellRunner.csproj index 30123f6..36b208f 100644 --- a/src/ShellRunner/ShellRunner.csproj +++ b/src/ShellRunner/ShellRunner.csproj @@ -1,20 +1,19 @@  - - netstandard2.0 - latest - enable - enable - embedded - true - true - true + + net8.0 + latest + enable + enable + embedded + true + true + true + - - - - - - + + + + diff --git a/src/ShellRunner/TypicalCommand.cs b/src/ShellRunner/TypicalCommand.cs deleted file mode 100644 index cadac1e..0000000 --- a/src/ShellRunner/TypicalCommand.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Diagnostics; - -namespace ShellRunner; - -public class TypicalCommand : ProcessCommand -{ - public TypicalCommand(string command) - : base(command) { } - - protected override void Run(Process process) - { - process.StandardInput.WriteLine(Command); - } -} diff --git a/src/TestApp/Program.cs b/src/TestApp/Program.cs index 026c513..56cd05e 100644 --- a/src/TestApp/Program.cs +++ b/src/TestApp/Program.cs @@ -3,11 +3,6 @@ try { - var fg = Console.ForegroundColor; - Console.ForegroundColor = ConsoleColor.Green; - Console.WriteLine("v10"); - Console.ForegroundColor = fg; - var execAssemblyLocation = Assembly.GetExecutingAssembly().Location; var directory = Path.GetDirectoryName(execAssemblyLocation); @@ -21,40 +16,25 @@ return; } - List? firstOutput = null; + CommandBuilder cb; + if (args[0] == "bash") { - firstOutput = CommandRunner + cb = CommandRunner .UseBash() - .StartProcess() - .AddCommand("dotnet --info") - .AddCommand("echo test") - .AddCommandWithOutput("echo foo") - .AddCommandWithOutput("echo bar") - .Run(); + .StartProcess(); } else if (args[0] == "powershell") { - firstOutput = CommandRunner + cb = CommandRunner .UsePowershell() - .StartProcess() - .AddCommand("dotnet --info") - .AddCommand("echo PowerShell") - .AddCommandWithOutput("echo foo") - .AddCommandWithOutput("echo bar") - .Run(); + .StartProcess(); } else if (args[0] == "cmd") { - firstOutput = CommandRunner + cb = CommandRunner .UseWindowsCommandShell() - .StartProcess() - .AddCommand("echo off") - .AddCommand("dotnet --info") - .AddCommand("echo CMD") - .AddCommandWithOutput("echo foo") - .AddCommandWithOutput("echo bar") - .Run(); + .StartProcess(); } else { @@ -62,48 +42,82 @@ return; } - if (firstOutput is null) - return; + await cb.AddCommand("echo off") + .AddCommand("dotnet --info") + .AddCommand("echo foo") + .AddCommand("echo bar") + .RunAsync(); Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine("Outputs:"); - foreach (var o in firstOutput) - Console.WriteLine(" " + o.Output); + foreach (var cmd in cb.Commands) + foreach(var output in cmd.Output) + Console.WriteLine(" " + output.Data); + + Console.ResetColor(); - Console.ForegroundColor = ConsoleColor.Gray; if(args[0] == "powershell") { - var secondOutput = CommandRunner - .UsePowershell() + var cb2 = await CommandRunner + .UsePowershell() .StartProcess() - .AddCommand("dotnet --info") .AddWorkingDirectory(directory) - .AddCommand("$myVar = 'foo'") - .AddCommand("echo $myVar") // show what version of dotnet is loaded .AddCommand("dotnet --info") // cd into the lbirary directory .AddCommand("cd ../../../../MyFakeLibrary") // build - .AddCommand("dotnet build MyFakeLibrary.csproj -c Release") + .AddCommand("dotnet build MyFakeLibrary.csproj -c Release", key: "build-output") .AddCommand("cd bin/Release/netstandard2.0") //.AddCommand("echo $myVar") // print artifacts - .AddCommandWithOutput("Get-Childitem") + .AddCommand("Get-Childitem", key: "get-child-item") // load built project into process and run one of the methods .AddCommand("Add-Type -Path .\\MyFakeLibrary.dll") .AddCommand("$obj = new-object MyFakeLibrary.TestClass") - .AddCommand("$obj.TestLibrary('test test')") - .Run(); + .AddCommand("$obj.TestLibrary('test test')", key: "test-library-output") + .RunAsync(); + + Console.ForegroundColor = ConsoleColor.DarkGray; + Console.WriteLine("Outputs:"); + Console.ResetColor(); + + var buildCmd = cb2.GetCommand("build-output"); + foreach(Output output in buildCmd.Output) + { + Console.ForegroundColor = ConsoleColor.Blue; + if (output.IsError) + Console.ForegroundColor = ConsoleColor.Red; + + Console.WriteLine(" " + output.Data); + } + Console.ResetColor(); + + + var listBuildFilesCmd = cb2.GetCommand("get-child-item"); + foreach (Output output in listBuildFilesCmd.Output) + { + Console.ForegroundColor = ConsoleColor.Green; + if (output.IsError) + Console.ForegroundColor = ConsoleColor.Red; + + Console.WriteLine(" " + output.Data); + } + Console.ResetColor(); + + var testLibraryOutputCmd = cb2.GetCommand("test-library-output"); + foreach (Output output in testLibraryOutputCmd.Output) + { + Console.ForegroundColor = ConsoleColor.Magenta; + if (output.IsError) + Console.ForegroundColor = ConsoleColor.Red; - Console.ForegroundColor = ConsoleColor.Blue; - Console.WriteLine("Outputs (2):"); - foreach (var o in secondOutput) - Console.WriteLine(" " + o.Output); + Console.WriteLine(" " + output.Data); + } + Console.ResetColor(); - Console.ForegroundColor = ConsoleColor.Gray; } } diff --git a/src/TestApp/TestApp.csproj b/src/TestApp/TestApp.csproj index 32daaf3..9a3e660 100644 --- a/src/TestApp/TestApp.csproj +++ b/src/TestApp/TestApp.csproj @@ -2,7 +2,7 @@ Exe - net6.0 + net8.0 enable enable From 938895e96abd262b86acedf72245855634810034 Mon Sep 17 00:00:00 2001 From: Kyle Burrows Date: Sat, 15 Mar 2025 17:35:34 -0400 Subject: [PATCH 2/3] update build --- .github/workflows/build-gate.yml | 14 +++++++------- .github/workflows/build.yml | 18 +++++++++--------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/.github/workflows/build-gate.yml b/.github/workflows/build-gate.yml index fd7a653..61b5b66 100644 --- a/.github/workflows/build-gate.yml +++ b/.github/workflows/build-gate.yml @@ -5,20 +5,20 @@ on: branches: [ '*' ] env: - BUILD_VERSION: 0.1.${{github.run_number}} + BUILD_VERSION: 0.2.${{github.run_number}} SLN_PATH: src/ShellRunner.sln - TEST_PATH: src/TestApp/bin/Release/net6.0/TestApp.dll + TEST_PATH: src/TestApp/bin/Release/net8.0/TestApp.dll jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Setup .NET - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v4 with: - dotnet-version: 6.0.x + dotnet-version: 8.0.x - name: Restore dependencies run: dotnet restore $SLN_PATH @@ -30,7 +30,7 @@ jobs: -p:Version=$BUILD_VERSION - name: Upload ShellRunner Build Artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4.6.1 with: name: BuildArtifacts path: ./**/bin/Release/**/* @@ -42,7 +42,7 @@ jobs: steps: - name: Download artifacts - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v4.1.9 with: name: BuildArtifacts diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 474fefc..e1e45b9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,9 +5,9 @@ on: branches: [ "stable" ] env: - BUILD_VERSION: 0.1.${{github.run_number}} + BUILD_VERSION: 0.2.${{github.run_number}} SLN_PATH: src/ShellRunner.sln - TEST_PATH: src/TestApp/bin/Release/net6.0/TestApp.dll + TEST_PATH: src/TestApp/bin/Release/net8.0/TestApp.dll PROJECT_PATH: src/ShellRunner/ShellRunner.csproj PRE_RELEASE_ARTIFACTS: ./**/ShellRunner.$BUILD_VERSION-alpha.nupkg RELEASE_ARTIFACTS: ./**/ShellRunner.$BUILD_VERSION.nupkg @@ -17,11 +17,11 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup .NET - uses: actions/setup-dotnet@v2 + uses: actions/setup-dotnet@v4 with: - dotnet-version: 6.0.x + dotnet-version: 8.0.x - name: Restore dependencies run: dotnet restore $SLN_PATH @@ -50,13 +50,13 @@ jobs: -p:PackageVersion=$BUILD_VERSION - name: Upload ShellRunner PreRelease Artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4.6.1 with: name: PreReleaseArtifacts path: $PRE_RELEASE_ARTIFACTS - name: Upload ShellRunner Release Artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4.6.1 with: name: ReleaseArtifacts path: $RELEASE_ARTIFACTS @@ -70,7 +70,7 @@ jobs: steps: - name: Download artifacts - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v4.1.9 with: name: PreReleaseArtifacts @@ -87,7 +87,7 @@ jobs: steps: - name: Download artifacts - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v4.1.9 with: name: ReleaseArtifacts From 8373b7156625b9bd304b61fcc4c3695c7405d21a Mon Sep 17 00:00:00 2001 From: Kyle Burrows Date: Sat, 15 Mar 2025 17:40:00 -0400 Subject: [PATCH 3/3] test dll doesn't run correctly, missing an argument --- .github/workflows/build-gate.yml | 2 +- .github/workflows/build.yml | 2 +- src/TestApp/Program.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-gate.yml b/.github/workflows/build-gate.yml index 61b5b66..00d7754 100644 --- a/.github/workflows/build-gate.yml +++ b/.github/workflows/build-gate.yml @@ -47,5 +47,5 @@ jobs: name: BuildArtifacts - name: Test - run: dotnet $TEST_PATH + run: dotnet $TEST_PATH bash \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e1e45b9..80b11a5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -33,7 +33,7 @@ jobs: -p:Version=$BUILD_VERSION - name: Test - run: dotnet $TEST_PATH + run: dotnet $TEST_PATH bash - name: Pack-Alpha run: dotnet pack $PROJECT_PATH diff --git a/src/TestApp/Program.cs b/src/TestApp/Program.cs index 56cd05e..bd9ff83 100644 --- a/src/TestApp/Program.cs +++ b/src/TestApp/Program.cs @@ -12,7 +12,7 @@ if(args.Length == 0) { - Console.WriteLine("Provide an argument: 'bash', 'powershell', or 'cmd'"); + Console.Error.WriteLine("Provide an argument: 'bash', 'powershell', or 'cmd'"); return; }