Skip to content
Snippets Groups Projects

New: Color console output

Merged Petar Hristov requested to merge test_ci into master
Files
3
@@ -19,6 +19,15 @@ public class Deployer
private readonly GraphDeployerConfiguration _graphDeployerConfiguration;
private readonly AdminApi _adminApi;
// Define ANSI escape codes for colors
private const string _esc = "\u001b"; // ANSI escape character
private const string _r = $"{_esc}[91m";
private const string _gb = $"{_esc}[1;92m";
private const string _y = $"{_esc}[93m";
private const string _bb = $"{_esc}[1;94m";
private const string _c = $"{_esc}[96m";
private const string _0 = $"{_esc}[0m";
public Deployer(ILogger<Deployer> logger, IOptionsMonitor<GraphDeployerConfiguration> graphDeployerConfiguration)
{
_logger = logger;
@@ -35,7 +44,7 @@ public class Deployer
// Check if the graph deployer has to skip SSL checks when connecting to the API
if (_graphDeployerConfiguration.SkipSslCheck)
{
_logger.LogInformation("Skipping SSL certificate validation...");
_logger.LogInformation("{y}Skipping SSL certificate validation...{res}", _y, _0);
// Skip SSL certificate validation
apiClientConfig.RemoteCertificateValidationCallback = (_, _, _, _) => true;
}
@@ -62,9 +71,12 @@ public class Deployer
// Log the current application execution mode
if (opts.DummyMode)
{
_logger.LogInformation("Running in Dummy Mode. No changes will be made.");
_logger.LogInformation("{y}Running in Dummy Mode. No changes will be made.{r}", _y, _0);
}
if (opts.Redeploy)
{
_logger.LogInformation("{y}Redeploying all graphs.{r}", _y, _0);
}
_logger.LogDebug("Redeploy: {redeploy}", opts.Redeploy);
// Override the working folder if specified in the configuration
if (!string.IsNullOrWhiteSpace(_graphDeployerConfiguration.WorkingFolder))
@@ -79,7 +91,7 @@ public class Deployer
// Iterate over the repositories and deploy the graphs
foreach (var graphRepo in _graphDeployerConfiguration.GitLab.Repositories)
{
_logger.LogInformation("Working with {repoName}", graphRepo.Name);
_logger.LogInformation("Working with {bb}{repoName}{res}...", _bb, graphRepo.Name, _0);
// Clone the repository inside the Working Folder
var success = CloneRepo(graphRepo.Url, WorkingFolder, _graphDeployerConfiguration.GitLab.Token, graphRepo.Ref);
@@ -111,10 +123,10 @@ public class Deployer
}
catch (Exception e)
{
_logger.LogError("Failed to load and process Turtle file: \"{file}\". Error: {errorMessage}", file, e.Message);
_logger.LogError("Failed to load and process Turtle file: \"{r}{file}{res}\". Error: {errorMessage}", _r, file, _0, e.Message);
}
});
_logger.LogDebug("Accumulated {count} graphs for possible deployment.", graphAccumulation.Count);
_logger.LogDebug("Accumulated {c}{count}{res} graphs for possible deployment.", _c, graphAccumulation.Count, _0);
// Iterate over the accumulated graphs and deploy them
foreach (var kv in graphAccumulation)
@@ -124,7 +136,7 @@ public class Deployer
var graphId = kv.Key.ToString();
var currentRun = new Dictionary<string, string>();
_logger.LogDebug("Deploying graph: {graphName}", graphId);
_logger.LogDebug("Deploying graph: {c}{graphName}{res}", _c, graphId, _0);
// Get the hash of the currently deployed graph and compare it with the hash of the graph to be deployed
files.ForEach((path) => currentRun.TryAdd(graphId, HashUtil.GetFileHash(path)));
@@ -134,10 +146,10 @@ public class Deployer
if (hasChanged)
{
_logger.LogDebug("The graph has changed");
_logger.LogDebug("The graph has changed.");
} else
{
_logger.LogDebug("The graph has not changed");
_logger.LogDebug("The graph has not changed.");
}
if(deployedGraph is null)
@@ -177,12 +189,12 @@ public class Deployer
});
}
_logger.LogInformation("Deployed {graphName} successfully.", graphId);
_logger.LogInformation("Deployed {c}{graphName}{res} {gb}successfully{res}.", _c, graphId, _0, _gb, _0);
DeployedGraphs.Add(graphId);
}
else
{
_logger.LogDebug("Skipped {graphName} as it has not changed.", graphId);
_logger.LogDebug("Skipped {c}{graphName}{res} as it has not changed.", _c, graphId, _0);
SkippedGraphs.Add(graphId);
continue;
}
@@ -230,7 +242,7 @@ public class Deployer
// Retrieve the reference of the repository, either the branch name or the commit hash
var repoRef = localRepo.Head.IsTracking ? localRepo.Head.FriendlyName : localRepo.Head.Tip.Sha;
_logger.LogInformation("Repository successfully cloned and switched on ref \"{ref}\".", repoRef);
_logger.LogInformation("Repository successfully cloned and switched on ref \"{c}{ref}{res}\".", _c, repoRef, _0);
return true;
}
Loading