Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix v3.1.2 - Bug fix for getting correct artifactory repo name from Jfrog for NuGet #54

Merged
merged 9 commits into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions .github/workflows/compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ jobs:
semver: ${{ steps.gitversion.outputs.semver }}
LicenseClearingTool: ${{ steps.packageBuildResults.outputs.LicenseClearingTool }}
nupkg-LicenseClearingTool: ${{ steps.createNupkg.outputs.nupkg-LicenseClearingTool }}

docker-LicenseClearingTool: ${{ steps.builddocker.outputs.docker-LicenseClearingTool }}

steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -149,11 +150,12 @@ jobs:
*.nupkg

- name: Build the Docker image
id: builddocker
#if: ${{ false }} # disable for now
run: |
docker build . --file Dockerfile --tag ${{ github.repository }}:continuous-clearing-v3.1.1
docker save ${{ github.repository }}:continuous-clearing-v3.1.1 -o continuous-clearing-v3.1.1.tar

Write-Host "::set-output name=docker-LicenseClearingTool::continuous-clearing-v3.1.1.tar"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MadanReddyK why it is being hardcoded in main branch.


- name: Archive docker image
#if: ${{ false }} # disable for now
Expand All @@ -179,6 +181,11 @@ jobs:
with:
name: nuget-continuous-clearing

- name: Download Docker image
uses: actions/download-artifact@v2
with:
name: docker-continuous-clearing

- name: Debug
run: |
tree
Expand Down Expand Up @@ -216,7 +223,17 @@ jobs:
asset_path: ./${{ needs.build.outputs.nupkg-LicenseClearingTool }}
asset_name: ${{ needs.build.outputs.nupkg-LicenseClearingTool }}
asset_content_type: application/zip


- name: Upload Nupkg
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./${{ needs.build.outputs.docker-LicenseClearingTool }}
asset_name: ${{ needs.build.outputs.docker-LicenseClearingTool }}
asset_content_type: application/zip

- name: Upload ReadmeOSS_nupkg file
uses: actions/upload-release-asset@v1
env:
Expand Down
2 changes: 1 addition & 1 deletion CA.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<package >
<metadata>
<id>continuous-clearing</id>
<version>3.1.1</version>
<version>3.1.2</version>
<authors>Siemens AG</authors>
<owners>continuous-clearing contributors</owners>
<projectUrl>https://github.com/siemens/continuous-clearing</projectUrl>
Expand Down
6 changes: 3 additions & 3 deletions doc/UsageDoc/CA_UsageDocument.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,7 @@ Continuous Clearing Tool reduces the effort in creating components in SW360 and

#### **Method 1 (Recommended)**
Copy the below content and create new `appSettings.json` file in `Continuous Clearing tool Config` directory.



Below is the list of settings can be made in `appSettings.json` file.

_`Sample appSettings.json file`_
Expand Down Expand Up @@ -273,12 +272,13 @@ Description for the settings in `appSettings.json` file
| 19 | --jfrogmavendestreponame | The destination folder name for the Maven package to be copied to | Yes | |
| 20 | --timeout | SW360 response timeout value | No | |


#### **Method 2**

You can also pass the above mentioned arguments in the command line.

`Note: If the second approach is followed then make sure you provide all the settings mentioned in the appsettings.json in the command line`

#### Exclude Component or Folders :
In order to exclude any components ,it can be configured in the "appSettings.json" by providing the package name and version as specified above in the *_ExcludedComponents_* field.

Expand Down
2 changes: 1 addition & 1 deletion src/ArtifactoryUploader/PackageUploadHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ private static async Task PackageUploadToArtifactory(UploaderKpiData uploaderKpi
else
{
uploaderKpiData.PackagesUploadedToJfrog++;
Logger.Warn($"Package {item.Name}-{item.Version} is already uploaded to {item.DestRepoName}");
Logger.Info($"Package {item.Name}-{item.Version} is already uploaded to {item.DestRepoName}");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/LCT.Common/appSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// SPDX-License-Identifier: MIT
// --------------------------------------------------------------------------------------------------------------------
{
"CaVersion": "3.1.1",
"CaVersion": "3.1.2",
"TimeOut": 200,
"ProjectType": "<Insert ProjectType>",
"SW360ProjectName": "<Insert SW360 Project Name>",
Expand Down
170 changes: 164 additions & 6 deletions src/LCT.PackageIdentifier.UTest/NugetParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using LCT.APICommunications.Model.AQL;
using CycloneDX.Models;
using System.Threading.Tasks;
using System.Linq;

namespace PackageIdentifier.UTest
{
Expand Down Expand Up @@ -234,7 +235,7 @@ public async Task IdentificationOfInternalComponents_Nuget_ReturnsComponentData_

AqlResult aqlResult = new()
{
Name = "animations-1.0.0.tgz",
Name = "animations-1.0.0.nupkg",
Path = "@siemens-gds/saap-api-node/-/@siemens-gds",
Repo = "energy-dev-npm-egll"
};
Expand Down Expand Up @@ -271,7 +272,7 @@ public async Task IdentificationOfInternalComponents_Nuget_ReturnsComponentData2

AqlResult aqlResult = new()
{
Name = "animations-common_license-1.0.0.tgz",
Name = "animations-common_license-1.0.0.nupkg",
Path = "@siemens-gds/saap-api-node/-/@siemens-gds",
Repo = "energy-dev-npm-egll"
};
Expand Down Expand Up @@ -309,7 +310,7 @@ public async Task IdentificationOfInternalComponents_ReturnsComponentData3_Succe

AqlResult aqlResult = new()
{
Name = "animations-common-1.0.0.tgz",
Name = "animations-common-1.0.0.nupkg",
Path = "@siemens-gds/saap-api-node/-/@siemens-gds",
Repo = "energy-dev-npm-egll"
};
Expand Down Expand Up @@ -347,7 +348,7 @@ public async Task GetJfrogRepoDetailsOfAComponent_ReturnsWithData_SuccessFully()
appSettings.Nuget = new LCT.Common.Model.Config() { JfrogNugetRepoList = reooListArr };
AqlResult aqlResult = new()
{
Name = "animations-common-1.0.0.tgz",
Name = "animations-common-1.0.0.nupkg",
Path = "@siemens-gds/saap-api-node/-/@siemens-gds",
Repo = "siparty-release-npm-egll"
};
Expand Down Expand Up @@ -383,10 +384,10 @@ public async Task GetJfrogRepoDetailsOfAComponent_Nuget_ReturnsWithData2_Success
var components = new List<Component>() { component1 };
string[] reooListArr = { "siparty-release-npm-egll", "org1-npmjs-npm-remote-cache" };
CommonAppSettings appSettings = new();
appSettings.Nuget = new LCT.Common.Model.Config() { JfrogNugetRepoList = reooListArr };
appSettings.Nuget = new Config() { JfrogNugetRepoList = reooListArr };
AqlResult aqlResult = new()
{
Name = "animations-common-1.0.0.tgz",
Name = "animations-common-1.0.0.nupkg",
Path = "@siemens-gds/saap-api-node/-/@siemens-gds",
Repo = "siparty-release-npm-egll"
};
Expand All @@ -407,5 +408,162 @@ public async Task GetJfrogRepoDetailsOfAComponent_Nuget_ReturnsWithData2_Success
// Assert
Assert.That(actual, Is.Not.Null);
}

[Test]
public async Task GetArtifactoryRepoName_Nuget_ReturnsRepoName_SuccessFully()
{
// Arrange
Component component1 = new()
{
Name = "animations-common",
Group = "",
Description = string.Empty,
Version = "1.0.0"
};
var components = new List<Component>() { component1 };
string[] reooListArr = { "siparty-release-npm-egll", "org1-npmjs-npm-remote-cache" };
CommonAppSettings appSettings = new();
appSettings.Nuget = new Config() { JfrogNugetRepoList = reooListArr };
AqlResult aqlResult = new()
{
Name = "animations-common-1.0.0.nupkg",
Path = "@siemens-gds/saap-api-node/-/@siemens-gds",
Repo = "siparty-release-npm-egll"
};

List<AqlResult> results = new List<AqlResult>() { aqlResult };

Mock<IJFrogService> mockJfrogService = new Mock<IJFrogService>();
Mock<IBomHelper> mockBomHelper = new Mock<IBomHelper>();
mockBomHelper.Setup(m => m.GetListOfComponentsFromRepo(It.IsAny<string[]>(), It.IsAny<IJFrogService>()))
.ReturnsAsync(results);
mockBomHelper.Setup(m => m.GetFullNameOfComponent(It.IsAny<Component>())).Returns("animations");

// Act
NugetProcessor nugetProcessor = new NugetProcessor();
var actual = await nugetProcessor.GetJfrogRepoDetailsOfAComponent(
components, appSettings, mockJfrogService.Object, mockBomHelper.Object);

var reponameActual = actual.First(x => x.Properties[0].Name == "internal:siemens:clearing:repo-url").Properties[0].Value;

Assert.That(reponameActual, Is.EqualTo(aqlResult.Repo));
}
[Test]
public async Task GetArtifactoryRepoName_Nuget_ReturnsRepoName_ReturnsFailure()
{
// Arrange
Component component1 = new()
{
Name = "animations-common",
Group = "",
Description = string.Empty,
Version = "1.0.0"
};
var components = new List<Component>() { component1 };
string[] reooListArr = { "siparty-release-npm-egll", "org1-npmjs-npm-remote-cache" };
CommonAppSettings appSettings = new();
appSettings.Nuget = new Config() { JfrogNugetRepoList = reooListArr };
AqlResult aqlResult = new()
{
Name = "animation-test-1.0.0.nupkg",
Path = "@siemens-gds/saap-api-node/-/@siemens-gds",
Repo = "siparty-release-npm-egll"
};

List<AqlResult> results = new () { aqlResult };

Mock<IJFrogService> mockJfrogService = new Mock<IJFrogService>();
Mock<IBomHelper> mockBomHelper = new Mock<IBomHelper>();
mockBomHelper.Setup(m => m.GetListOfComponentsFromRepo(It.IsAny<string[]>(), It.IsAny<IJFrogService>()))
.ReturnsAsync(results);
mockBomHelper.Setup(m => m.GetFullNameOfComponent(It.IsAny<Component>())).Returns("animations");

// Act
NugetProcessor nugetProcessor = new NugetProcessor();
var actual = await nugetProcessor.GetJfrogRepoDetailsOfAComponent(
components, appSettings, mockJfrogService.Object, mockBomHelper.Object);

var reponameActual = actual.First(x => x.Properties[0].Name == "internal:siemens:clearing:repo-url").Properties[0].Value;

Assert.That("Not Found in JFrogRepo", Is.EqualTo(reponameActual));
}
[Test]
public async Task GetArtifactoryRepoName_Nuget_ReturnsRepoName_ReturnsSuccess()
{
// Arrange
Component component1 = new()
{
Name = "animations-common",
Group = "",
Description = string.Empty,
Version = "1.0.0"
};
var components = new List<Component>() { component1 };
string[] reooListArr = { "siparty-release-npm-egll", "org1-npmjs-npm-remote-cache" };
CommonAppSettings appSettings = new();
appSettings.Nuget = new Config() { JfrogNugetRepoList = reooListArr };
AqlResult aqlResult = new()
{
Name = "animations-common.1.0.0.nupkg",
Path = "@siemens-gds/saap-api-node/-/@siemens-gds",
Repo = "siparty-release-npm-egll"
};

List<AqlResult> results = new() { aqlResult };

Mock<IJFrogService> mockJfrogService = new Mock<IJFrogService>();
Mock<IBomHelper> mockBomHelper = new Mock<IBomHelper>();
mockBomHelper.Setup(m => m.GetListOfComponentsFromRepo(It.IsAny<string[]>(), It.IsAny<IJFrogService>()))
.ReturnsAsync(results);
mockBomHelper.Setup(m => m.GetFullNameOfComponent(It.IsAny<Component>())).Returns("animations");

// Act
NugetProcessor nugetProcessor = new NugetProcessor();
var actual = await nugetProcessor.GetJfrogRepoDetailsOfAComponent(
components, appSettings, mockJfrogService.Object, mockBomHelper.Object);

var reponameActual = actual.First(x => x.Properties[0].Name == "internal:siemens:clearing:repo-url").Properties[0].Value;

Assert.That("siparty-release-npm-egll", Is.EqualTo(reponameActual));
}
[Test]
public async Task GetArtifactoryRepoName_Nuget_ReturnsNotFound_ReturnsFailure()
{
// Arrange
Component component1 = new()
{
Name = "animations-common",
Group = "",
Description = string.Empty,
Version = "1.0.0"
};
var components = new List<Component>() { component1 };
string[] reooListArr = { "siparty-release-npm-egll", "org1-npmjs-npm-remote-cache" };
CommonAppSettings appSettings = new();
appSettings.Nuget = new Config() { JfrogNugetRepoList = reooListArr };
AqlResult aqlResult = new()
{
Name = "animation-common.1.0.0.nupkg",
Path = "@siemens-gds/saap-api-node/-/@siemens-gds",
Repo = "siparty-release-npm-egll"
};

List<AqlResult> results = new() { aqlResult };

Mock<IJFrogService> mockJfrogService = new Mock<IJFrogService>();
Mock<IBomHelper> mockBomHelper = new Mock<IBomHelper>();
mockBomHelper.Setup(m => m.GetListOfComponentsFromRepo(It.IsAny<string[]>(), It.IsAny<IJFrogService>()))
.ReturnsAsync(results);
mockBomHelper.Setup(m => m.GetFullNameOfComponent(It.IsAny<Component>())).Returns("animations");

// Act
NugetProcessor nugetProcessor = new NugetProcessor();
var actual = await nugetProcessor.GetJfrogRepoDetailsOfAComponent(
components, appSettings, mockJfrogService.Object, mockBomHelper.Object);

var reponameActual = actual.First(x => x.Properties[0].Name == "internal:siemens:clearing:repo-url").Properties[0].Value;

Assert.That("Not Found in JFrogRepo", Is.EqualTo(reponameActual));
}
}
}
13 changes: 10 additions & 3 deletions src/LCT.PackageIdentifier/NugetProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -296,20 +296,27 @@ public async Task<List<Component>> GetJfrogRepoDetailsOfAComponent(List<Componen

private static string GetArtifactoryRepoName(List<AqlResult> aqlResultList, Component component, IBomHelper bomHelper)
{
string jfrogcomponentName = $"{component.Name}-{component.Version}.tgz";
string jfrogcomponentName = $"{component.Name}-{component.Version}.nupkg";

string repoName = aqlResultList.Find(x => x.Name.Equals(
jfrogcomponentName, StringComparison.OrdinalIgnoreCase))?.Repo ?? NotFoundInRepo;

string fullName = bomHelper.GetFullNameOfComponent(component);
string fullNameVersion = $"{fullName}-{component.Version}.tgz";
string fullNameVersion = $"{fullName}-{component.Version}.nupkg";

if (!fullNameVersion.Equals(jfrogcomponentName, StringComparison.OrdinalIgnoreCase) &&
repoName.Equals(NotFoundInRepo, StringComparison.OrdinalIgnoreCase))
{
repoName = aqlResultList.Find(x => x.Name.Equals(
fullNameVersion, StringComparison.OrdinalIgnoreCase))?.Repo ?? NotFoundInRepo;
}
if (repoName == NotFoundInRepo)
{
jfrogcomponentName = $"{component.Name}.{component.Version}.nupkg";
repoName = aqlResultList.Find(x => x.Name.Equals(
jfrogcomponentName, StringComparison.OrdinalIgnoreCase))?.Repo ?? NotFoundInRepo;

}

return repoName;
}
Expand Down Expand Up @@ -363,7 +370,7 @@ private static bool IsInternalNugetComponent(List<AqlResult> aqlResultList, Comp

string fullName = bomHelper.GetFullNameOfComponent(component);
string fullNameVersion = $"{fullName}.{component.Version}.nupkg";
if (!fullNameVersion.Equals(jfrogcomponentName, StringComparison.OrdinalIgnoreCase)
if (!fullNameVersion.Equals(jfrogcomponentName, StringComparison.OrdinalIgnoreCase)
&& aqlResultList.Exists(
x => x.Name.Equals(fullNameVersion, StringComparison.OrdinalIgnoreCase)))
{
Expand Down