Skip to content

Commit

Permalink
chore: enable verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
guitarrapc committed Dec 17, 2024
1 parent dd91016 commit b07f3f2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
40 changes: 29 additions & 11 deletions src/Actions/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class ActionsBatch
{
#pragma warning disable CA1822 // Mark members as static

private bool _verbose;

/// <summary>Get version string from tag</summary>
/// <param name="tag"></param>
/// <param name="prefix"></param>
Expand All @@ -27,7 +29,7 @@ public void Versioning(string tag, string prefix = "", VersionIncrement versionI
var versioning = command.Versioning(withoutPrefix);

var output = OutputFormat("version", versioning, outputFormat);
Console.WriteLine(output);
WriteLog(output);
}

/// <summary>
Expand All @@ -39,37 +41,40 @@ public void Versioning(string tag, string prefix = "", VersionIncrement versionI
[Command("update-version")]
public void UpdateVersion(string version, string path, bool dryRun)
{
Console.WriteLine($"Update begin, {path} ...");
WriteLog($"Update begin, {path} ...");
if (string.IsNullOrWhiteSpace(path))
{
Console.WriteLine("Empty path detected, skip execution.");
WriteLog("Empty path detected, skip execution.");
return;
}

using (var githubGroup = new GitHubActionsGroupLogger("Before"))
Console.WriteLine(File.ReadAllText(path));
WriteLog(File.ReadAllText(path));

var command = new UpdateVersionCommand(version, path);
var result = command.UpdateVersion(dryRun);

using (var githubGroup = new GitHubActionsGroupLogger("After"))
Console.WriteLine(result.After);
WriteLog(result.After);

Console.WriteLine($"Completed ...");
WriteLog($"Completed ...");
}

/// <summary>
/// Validate specified path contains file
/// </summary>
/// <param name="pathPattern"></param>
/// <param name="verbose"></param>
[Command("validate-file-exists")]
public void ValidateFileExists(string pathPattern)
public void ValidateFileExists(string pathPattern, bool verbose)
{
Console.WriteLine($"Validating path, {pathPattern}");
_verbose = verbose;
WriteLog($"Validating path, {pathPattern} ...");
WriteVerbose($"UTF8: {DebugTools.ToUtf8Base64String(pathPattern)}");
var command = new FileExsistsCommand(pathPattern);
command.Validate();

Console.WriteLine($"Completed ...");
WriteLog($"Completed ...");
}

/// <summary>
Expand All @@ -79,12 +84,12 @@ public void ValidateFileExists(string pathPattern)
[Command("create-dummy")]
public void CreateDummy(string basePath)
{
Console.WriteLine($"Creating dummy files, under {basePath} ...");
WriteLog($"Creating dummy files, under {basePath} ...");

var command = new CreateDummyCommand();
command.CreateDummy(basePath);

Console.WriteLine($"Completed ...");
WriteLog($"Completed ...");
}

#pragma warning restore CA1822 // Mark members as static
Expand All @@ -95,6 +100,19 @@ public void CreateDummy(string basePath)
OutputFormatType.GitHubActions => $"{key}={value}",
_ => throw new NotImplementedException(nameof(format)),
};

void WriteLog(string value)
{
Console.WriteLine($"[{DateTime.Now:s}] {value}");
}

void WriteVerbose(string value)
{
if (_verbose)
{
Console.WriteLine($"[{DateTime.Now:s}] {value}");
}
}
}

public class ActionCommandException(string message, Exception? innterException = null) : Exception(message, innterException)
Expand Down
8 changes: 8 additions & 0 deletions src/Actions/Utils/DebugTools.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System.Text;

namespace Actions.Utils;

public static class DebugTools
{
public static string ToUtf8Base64String(string input) => string.Join(" ", Encoding.UTF8.GetBytes(input).Select(b => b.ToString("X2")));
}

0 comments on commit b07f3f2

Please sign in to comment.