Skip to content

Commit

Permalink
publish catool logs and bom to pipeline artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
Viji committed Jul 26, 2024
1 parent ba05e2a commit 64678c1
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 13 deletions.
34 changes: 31 additions & 3 deletions src/ArtifactoryUploader/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@ static async Task Main(string[] args)

ISettingsManager settingsManager = new SettingsManager();
CommonAppSettings appSettings = settingsManager.ReadConfiguration<CommonAppSettings>(args, FileConstant.appSettingFileName);
CatoolInfo caToolInformation = GetCatoolVersionFromProjectfile();

Log4Net.CatoolCurrentDirectory = Directory.GetParent(caToolInformation.CatoolRunningLocation).FullName;

string FolderPath = InitiateLogger(appSettings);

settingsManager.CheckRequiredArgsToRun(appSettings, "Uploader");
CatoolInfo caToolVersion = GetCatoolVersionFromProjectfile();

Logger.Logger.Log(null, Level.Notice, $"\n====================<<<<< Artifactory Uploader >>>>>====================", null);
Logger.Logger.Log(null, Level.Notice, $"\nStart of Artifactory Uploader execution: {DateTime.Now}", null);
Expand All @@ -57,8 +60,8 @@ static async Task Main(string[] args)

Logger.Logger.Log(null, Level.Info, $"Input Parameters used in Artifactory Uploader:\n\t", null);
Logger.Logger.Log(null, Level.Notice, $"\tBomFilePath:\t\t {appSettings.BomFilePath}\n\t" +
$"CaToolVersion\t\t --> {caToolVersion.CatoolVersion}\n\t" +
$"CaToolRunningPath\t --> {caToolVersion.CatoolRunningLocation}\n\t" +
$"CaToolVersion\t\t --> {caToolInformation.CatoolVersion}\n\t" +
$"CaToolRunningPath\t --> {caToolInformation.CatoolRunningLocation}\n\t" +
$"JFrogUrl:\t\t {appSettings.JFrogApi}\n\t" +
$"Release:\t\t {appSettings.Release}\n\t" +
$"LogFolderPath:\t\t {Path.GetFullPath(FolderPath)}\n", null);
Expand All @@ -79,6 +82,31 @@ static async Task Main(string[] args)


Logger.Logger.Log(null, Level.Notice, $"End of Artifactory Uploader execution : {DateTime.Now}\n", null);
// publish logs and bom file to pipeline artifact
PublishFilesToArtifact();

}

public static void PublishFilesToArtifact()
{
try
{

// Define Azure DevOps/VSTS artifact upload parameters
string containerFolder = "Container"; // Replace with your desired container folder
string artifactName = "catoolArtifactoryUploader"; // Replace with your artifact name
//string logFilePath = Path.GetFullPath(Log4Net.CatoolLogPath);

// Output the artifact upload command
Console.WriteLine($"##vso[artifact.upload containerfolder={containerFolder};artifactname={artifactName}]{Log4Net.CatoolLogPath}");
Console.WriteLine($"##vso[artifact.upload containerfolder={containerFolder};artifactname={artifactName}]{FileOperations.CatoolBomFilePath}");


}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}

private static CatoolInfo GetCatoolVersionFromProjectfile()
Expand Down
6 changes: 3 additions & 3 deletions src/LCT.Common/Constants/FileConstant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public static class FileConstant
public const string PackageLockFileName = "package-lock.json";
public const string PackageConfigFileName = "packages.config";
public const string PackageLockJonFileName = "packages.lock.json";
public const string LogFolder = "..\\Logs";
public const string ComponentCreatorLog = "PacakgeCreator.log";
public const string BomCreatorLog = "PacakgeIdentifier.log";
public const string LogFolder = "Logs";
public const string ComponentCreatorLog = "PackageCreator.log";
public const string BomCreatorLog = "PackageIdentifier.log";
public const string FossologyUploaderLog = "FossologyUploader.log";
public const string ArtifactoryUploaderLog = "ArtifactoryUploader.log";
public const string XzFileExtension = ".tar.xz";
Expand Down
3 changes: 2 additions & 1 deletion src/LCT.Common/FileOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace LCT.Common
public class FileOperations : IFileOperations
{
static readonly ILog Logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public static string CatoolBomFilePath { get; set; }

public void ValidateFilePath(string filePath)
{
Expand Down Expand Up @@ -90,7 +91,7 @@ public string WriteContentToOutputBomFile<T>(T dataToWrite, string folderPath, s

string fileName = $"{projectName}_{fileNameWithExtension}";

string filePath = Path.Combine(folderPath, fileName);
string filePath = CatoolBomFilePath = Path.Combine(folderPath, fileName);
Logger.Debug($"filePath-{filePath}");

BackupTheGivenFile(folderPath, fileName);
Expand Down
9 changes: 7 additions & 2 deletions src/LCT.Common/Logging/Log4net.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using log4net.Core;
using log4net.Appender;
using System;
using LCT.Common.Constants;

namespace LCT.Common
{
Expand All @@ -23,12 +24,16 @@ namespace LCT.Common
public static class Log4Net
{
public static ILoggerRepository LoggerRepository { get; set; }

public static string CatoolLogPath { get; set; }
public static string CatoolCurrentDirectory { get; set; }

public static void Init(string logFileName, string logFolder, bool verbose)
{
LoggerRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
XmlConfigurator.Configure(LoggerRepository, new FileInfo(GetDefaultLogConfigFile()));

string logPath = Path.Combine(logFolder, logFileName);
string outPath = Directory.GetParent(Directory.GetCurrentDirectory()).FullName;
string logPath = CatoolLogPath = Path.Combine(CatoolCurrentDirectory, logFolder, logFileName);

if (LoggerRepository is Hierarchy rootRepo)
{
Expand Down
32 changes: 30 additions & 2 deletions src/LCT.PackageIdentifier/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace LCT.PackageIdentifier
public class Program
{
private static bool m_Verbose = false;

public static Stopwatch BomStopWatch { get; set; }
private static readonly ILog Logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

Expand All @@ -51,9 +52,10 @@ static async Task Main(string[] args)
ISettingsManager settingsManager = new SettingsManager();
CommonAppSettings appSettings = settingsManager.ReadConfiguration<CommonAppSettings>(args, FileConstant.appSettingFileName);
ProjectReleases projectReleases = new ProjectReleases();
CatoolInfo caToolInformation = GetCatoolVersionFromProjectfile();
Log4Net.CatoolCurrentDirectory = Directory.GetParent(caToolInformation.CatoolRunningLocation).FullName;
string FolderPath = LogFolderInitialisation(appSettings);

CatoolInfo caToolInformation = GetCatoolVersionFromProjectfile();
settingsManager.CheckRequiredArgsToRun(appSettings, "Identifer");

Logger.Logger.Log(null, Level.Notice, $"\n====================<<<<< Package Identifier >>>>>====================", null);
Expand Down Expand Up @@ -89,7 +91,7 @@ static async Task Main(string[] args)
$"SW360ProjectName\t --> {appSettings.SW360ProjectName}\n\t" +
$"SW360ProjectID\t\t --> {appSettings.SW360ProjectID}\n\t" +
$"ProjectType\t\t --> {appSettings.ProjectType}\n\t" +
$"LogFolderPath\t\t --> {Path.GetFullPath(FolderPath)}\n\t" +
$"LogFolderPath\t\t --> {Log4Net.CatoolLogPath}\n\t" +
$"InternalRepoList\t --> {listOfInternalRepoList}\n\t" +
$"Include\t\t\t --> {listOfInlude}\n\t" +
$"Exclude\t\t\t --> {listOfExclude}\n\t" +
Expand All @@ -111,6 +113,32 @@ static async Task Main(string[] args)
caToolInformation);
}
Logger.Logger.Log(null, Level.Notice, $"End of Package Identifier execution : {DateTime.Now}\n", null);

// publish logs and bom file to pipeline artifact
PublishFilesToArtifact();

}

public static void PublishFilesToArtifact()
{
try
{

// Define Azure DevOps/VSTS artifact upload parameters
string containerFolder = "Container"; // Replace with your desired container folder
string artifactName = "catoolPackageIdentifier"; // Replace with your artifact name
//string logFilePath = Path.GetFullPath(Log4Net.CatoolLogPath);

// Output the artifact upload command
Console.WriteLine($"##vso[artifact.upload containerfolder={containerFolder};artifactname={artifactName}]{Log4Net.CatoolLogPath}");
Console.WriteLine($"##vso[artifact.upload containerfolder={containerFolder};artifactname={artifactName}]{FileOperations.CatoolBomFilePath}");


}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}

private static CatoolInfo GetCatoolVersionFromProjectfile()
Expand Down
32 changes: 30 additions & 2 deletions src/LCT.SW360PackageCreator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,14 @@ static async Task Main(string[] args)
ISW360ApicommunicationFacade sW360ApicommunicationFacade;
ISw360ProjectService sw360ProjectService= Getsw360ProjectServiceObject(appSettings, out sW360ApicommunicationFacade);
ProjectReleases projectReleases = new ProjectReleases();

CatoolInfo caToolInformation = GetCatoolVersionFromProjectfile();

Log4Net.CatoolCurrentDirectory = Directory.GetParent(caToolInformation.CatoolRunningLocation).FullName;


string FolderPath = InitiateLogger(appSettings);
settingsManager.CheckRequiredArgsToRun(appSettings, "Creator");
await CreatorValidator.ValidateAppSettings(appSettings, sw360ProjectService, projectReleases);
CatoolInfo caToolInformation = GetCatoolVersionFromProjectfile();

Logger.Logger.Log(null, Level.Notice, $"\n====================<<<<< Package creator >>>>>====================", null);
Logger.Logger.Log(null, Level.Notice, $"\nStart of Package creator execution : {DateTime.Now}", null);
Expand All @@ -80,6 +83,31 @@ static async Task Main(string[] args)
await InitiatePackageCreatorProcess(appSettings, sw360ProjectService, sW360ApicommunicationFacade);

Logger.Logger.Log(null, Level.Notice, $"End of Package Creator execution: {DateTime.Now}\n", null);
// publish logs and bom file to pipeline artifact
PublishFilesToArtifact();

}

public static void PublishFilesToArtifact()
{
try
{

// Define Azure DevOps/VSTS artifact upload parameters
string containerFolder = "Container"; // Replace with your desired container folder
string artifactName = "catoolPacakgeCreator"; // Replace with your artifact name
//string logFilePath = Path.GetFullPath(Log4Net.CatoolLogPath);

// Output the artifact upload command
Console.WriteLine($"##vso[artifact.upload containerfolder={containerFolder};artifactname={artifactName}]{Log4Net.CatoolLogPath}");
Console.WriteLine($"##vso[artifact.upload containerfolder={containerFolder};artifactname={artifactName}]{FileOperations.CatoolBomFilePath}");


}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}

private static CatoolInfo GetCatoolVersionFromProjectfile()
Expand Down

0 comments on commit 64678c1

Please sign in to comment.