Skip to content

Commit

Permalink
Added DevOpsMetrics. Updated FileSystem NuGet to stable release.
Browse files Browse the repository at this point in the history
  • Loading branch information
janstaelensskyline committed Dec 19, 2023
1 parent dcab45a commit d0f6124
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Skyline.DataMiner.CICD.FileSystem" Version="1.0.2-ReadAllBytes1" />
<PackageReference Include="Skyline.DataMiner.CICD.FileSystem" Version="1.0.2" />
<PackageReference Include="Skyline.DataMiner.CICD.Tools.WinEncryptedKeys.Lib" Version="1.0.2" />
</ItemGroup>

Expand Down
3 changes: 2 additions & 1 deletion CICD.Tools.CatalogUpload/CICD.Tools.CatalogUpload.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
<PackageReference Include="Skyline.DataMiner.CICD.FileSystem" Version="1.0.2-ReadAllBytes1" />
<PackageReference Include="Skyline.DataMiner.CICD.FileSystem" Version="1.0.2" />
<PackageReference Include="Skyline.DataMiner.CICD.Tools.Reporter" Version="1.0.1" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
</ItemGroup>
<ItemGroup>
Expand Down
108 changes: 73 additions & 35 deletions CICD.Tools.CatalogUpload/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Skyline.DataMiner.CICD.Tools.CatalogUpload
{
using System;
using System.CommandLine;
using System.Threading.Tasks;

Expand All @@ -8,6 +9,7 @@
using Serilog;

using Skyline.DataMiner.CICD.Tools.CatalogUpload.Lib;
using Skyline.DataMiner.CICD.Tools.Reporter;

/// <summary>
/// Uploads artifacts to the Skyline DataMiner catalog (https://catalog.dataminer.services).
Expand Down Expand Up @@ -106,47 +108,83 @@ private static async Task<int> Process(string pathToArtifact, string dmCatalogTo

private static async Task<int> ProcessWithRegistrationAsync(string pathToArtifact, string dmCatalogToken, bool isDebug, string registrationIdentifier, string overrideVersion, string branch, string committerMail, string releaseUri)
{
LoggerConfiguration logConfig = new LoggerConfiguration().WriteTo.Console();
if (!isDebug)
{
logConfig.MinimumLevel.Information();
}
else
{

logConfig.MinimumLevel.Debug();
}

var seriLog = logConfig.CreateLogger();
// Skyline.DataMiner.CICD.Tools.CatalogUpload|with-registration:https://github.com/SomeRepo|Status:OK"
// Skyline.DataMiner.CICD.Tools.CatalogUpload|with-registration:https://github.com/SomeRepo|Status:Fail-blabla"
// Skyline.DataMiner.CICD.Tools.CatalogUpload|volatile|Status:OK"
// Skyline.DataMiner.CICD.Tools.CatalogUpload|volatile|Status:Fail-blabla"
string devopsMetricsMessage = "Skyline.DataMiner.CICD.Tools.CatalogUpload";

LoggerFactory loggerFactory = new LoggerFactory();
loggerFactory.AddSerilog(seriLog);

var logger = loggerFactory.CreateLogger("Skyline.DataMiner.CICD.Tools.CatalogUpload");

CatalogMetaData metaData = CatalogMetaData.FromArtifact(pathToArtifact);

if (registrationIdentifier != null)
try
{
// Registration as a whole is optional. If there is no Identifier provided there will be no registration.
metaData.Identifier = registrationIdentifier; // Need from user <- optional unique identifier. Usually the path to the sourcecode on github/gitlab/git.

// These are optional. Only override if not null.
if (overrideVersion != null) metaData.Version = overrideVersion;
if (branch != null) metaData.Branch = branch;
if (committerMail != null) metaData.CommitterMail = committerMail;
if (releaseUri != null) metaData.ReleaseUri = releaseUri;
LoggerConfiguration logConfig = new LoggerConfiguration().WriteTo.Console();
if (!isDebug)
{
logConfig.MinimumLevel.Information();
}
else
{

logConfig.MinimumLevel.Debug();
}

var seriLog = logConfig.CreateLogger();

LoggerFactory loggerFactory = new LoggerFactory();
loggerFactory.AddSerilog(seriLog);

var logger = loggerFactory.CreateLogger("Skyline.DataMiner.CICD.Tools.CatalogUpload");

CatalogMetaData metaData = CatalogMetaData.FromArtifact(pathToArtifact);

if (registrationIdentifier != null)
{
devopsMetricsMessage += "|with-registration:" + registrationIdentifier;
// Registration as a whole is optional. If there is no Identifier provided there will be no registration.
metaData.Identifier = registrationIdentifier; // Need from user <- optional unique identifier. Usually the path to the sourcecode on github/gitlab/git.

// These are optional. Only override if not null.
if (overrideVersion != null) metaData.Version = overrideVersion;
if (branch != null) metaData.Branch = branch;
if (committerMail != null) metaData.CommitterMail = committerMail;
if (releaseUri != null) metaData.ReleaseUri = releaseUri;
}
else
{
devopsMetricsMessage += "|volatile";
}

CatalogArtifact artifact = new CatalogArtifact(pathToArtifact, logger, metaData);

if (string.IsNullOrWhiteSpace(dmCatalogToken))
{
await artifact.UploadAsync();
}
else
{
await artifact.UploadAsync(dmCatalogToken);
}

devopsMetricsMessage += "|Status:OK";
}

CatalogArtifact artifact = new CatalogArtifact(pathToArtifact, logger, metaData);

if (string.IsNullOrWhiteSpace(dmCatalogToken))
catch (Exception e)
{
await artifact.UploadAsync();
devopsMetricsMessage += "|" + "Status:Fail-" + e.Message;
throw;
}
else
finally
{
await artifact.UploadAsync(dmCatalogToken);
if (!string.IsNullOrWhiteSpace(devopsMetricsMessage))
{
try
{
DevOpsMetrics devOpsMetrics = new DevOpsMetrics();
await devOpsMetrics.ReportAsync(devopsMetricsMessage);
}
catch
{
// Fire and forget.
}
}
}

return 0;
Expand Down

0 comments on commit d0f6124

Please sign in to comment.