Skip to content

Commit c45cdf6

Browse files
authored
Support Catalog references (#8)
Support Catalog references
1 parent aeac450 commit c45cdf6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1771
-191
lines changed

.github/workflows/release.yml

+25-10
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,33 @@ on:
1414

1515
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
1616
jobs:
17+
ubuntu-tests:
18+
name: Run all tests on Ubuntu
19+
runs-on: ubuntu-22.04 # Latest misses mono for .NET Framework
20+
env:
21+
DOWNLOAD_KEY: ${{ secrets.DOWNLOAD_KEY }}
22+
23+
steps:
24+
- uses: actions/checkout@v4
25+
26+
- name: Test All
27+
run: dotnet test -c Release
28+
29+
30+
dotnet-test:
31+
name: Run Integration Tests
32+
runs-on: windows-latest
33+
env:
34+
DOWNLOAD_KEY: ${{ secrets.DOWNLOAD_KEY }}
35+
36+
steps:
37+
- uses: actions/checkout@v4
38+
39+
- name: Integration Tests
40+
run: dotnet test -c Release --filter TestCategory=IntegrationTest
1741

18-
# Note: Tagging will push the nupackage to nuget.org using the provided NUGETAPIKEY. You can tag both a prerelease version (a.b.c-xxxx) or a stable release (a.b.c).
1942
CICD:
43+
needs: [ubuntu-tests, dotnet-test]
2044
uses: SkylineCommunications/_ReusableWorkflows/.github/workflows/NuGet Solution Master Workflow.yml@main
2145
with:
2246
referenceName: ${{ github.ref_name }}
@@ -30,12 +54,3 @@ jobs:
3054
pfx: ${{ secrets.PFX }}
3155
pfxPassword: ${{ secrets.PFXPASSWORD }}
3256
nugetApiKey: ${{ secrets.NUGETAPIKEY }}
33-
34-
Tests-Ubuntu:
35-
runs-on: ubuntu-22.04 # Latest misses mono for .NET Framework
36-
37-
steps:
38-
- uses: actions/checkout@v4
39-
40-
- name: Test
41-
run: dotnet test -c Release

Sdk/DataMinerSdkLogger.cs

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
namespace Skyline.DataMiner.Sdk
2+
{
3+
using System;
4+
5+
using Microsoft.Build.Framework;
6+
using Microsoft.Build.Utilities;
7+
8+
using Skyline.DataMiner.CICD.Loggers;
9+
10+
internal class DataMinerSdkLogger : ILogCollector
11+
{
12+
private readonly TaskLoggingHelper logger;
13+
private readonly bool debugMode;
14+
15+
public DataMinerSdkLogger(TaskLoggingHelper logger, string debug)
16+
{
17+
this.logger = logger;
18+
debugMode = String.Equals(debug, "true", StringComparison.OrdinalIgnoreCase);
19+
}
20+
21+
public void ReportError(string error)
22+
{
23+
logger.LogError(error);
24+
}
25+
26+
public void ReportStatus(string status)
27+
{
28+
logger.LogMessage(status);
29+
}
30+
31+
public void ReportWarning(string warning)
32+
{
33+
logger.LogWarning(warning);
34+
}
35+
36+
public void ReportDebug(string debug)
37+
{
38+
if (debugMode)
39+
{
40+
logger.LogMessage(MessageImportance.High, $"DEBUG: {debug}");
41+
}
42+
}
43+
44+
public void ReportLog(string message)
45+
{
46+
logger.LogMessage(message);
47+
}
48+
}
49+
}

Sdk/Helpers/BuildOutputHandler.cs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
namespace Skyline.DataMiner.Sdk.Helpers
2+
{
3+
using Skyline.DataMiner.CICD.FileSystem;
4+
5+
internal static class BuildOutputHandler
6+
{
7+
public const string BuildDirectoryName = "DataMinerBuild";
8+
9+
/// <summary>
10+
/// Gets the output path (directory) where the output artifacts need to be stored. The directory will already be created.
11+
/// </summary>
12+
/// <param name="output">Output straight from the Sdk.targets (OutDir).</param>
13+
/// <param name="projectDirectory">Directory path of the project.</param>
14+
/// <returns>A created directory for storing the build output.</returns>
15+
public static string GetOutputPath(string output, string projectDirectory)
16+
{
17+
string baseLocation = output;
18+
if (!FileSystem.Instance.Path.IsPathRooted(output))
19+
{
20+
// Relative path (starting from project directory)
21+
baseLocation = FileSystem.Instance.Path.GetFullPath(FileSystem.Instance.Path.Combine(projectDirectory, output));
22+
}
23+
24+
string outputPath = FileSystem.Instance.Path.Combine(baseLocation, BuildDirectoryName);
25+
FileSystem.Instance.Directory.CreateDirectory(outputPath);
26+
return outputPath;
27+
}
28+
}
29+
}

Sdk/Helpers/CatalogReferencesHelper.cs

+32-31
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
using System.Collections.Generic;
55
using System.IO;
66
using System.Linq;
7-
using System.Net.Http;
87
using System.Xml;
98
using System.Xml.Linq;
109

10+
using Skyline.ArtifactDownloader.Identifiers;
1111
using Skyline.DataMiner.CICD.FileSystem;
1212
using Skyline.DataMiner.CICD.Parsers.Common.VisualStudio.Projects;
1313

1414
internal static class CatalogReferencesHelper
1515
{
16-
public static bool TryResolveCatalogReferences(Project packageProject, out List<string> includedPackages, out string errorMessage)
16+
public static bool TryResolveCatalogReferences(Project packageProject, out List<(CatalogIdentifier Identifier, string DisplayName)> includedPackages, out string errorMessage)
1717
{
1818
includedPackages = null;
1919
errorMessage = null;
@@ -42,50 +42,51 @@ public static bool TryResolveCatalogReferences(Project packageProject, out List<
4242
return false;
4343
}
4444

45-
private static List<string> ResolveCatalogReferences(string xmlFilePath)
45+
private static List<(CatalogIdentifier, string)> ResolveCatalogReferences(string xmlFilePath)
4646
{
47-
throw new NotSupportedException();
48-
4947
// Load the XML file
5048
var doc = XDocument.Load(xmlFilePath);
5149
XNamespace ns = "http://www.skyline.be/catalogReferences";
5250

5351
var catalogItems = doc.Descendants(ns + "CatalogReference").ToList();
5452

55-
using (HttpClient client = new HttpClient())
53+
List<(CatalogIdentifier, string)> catalogIdentifiers = new List<(CatalogIdentifier, string)>();
54+
foreach (XElement catalogItem in catalogItems)
5655
{
57-
//ICatalogService service = Downloader.FromCatalog(client);
58-
foreach (XElement catalogItem in catalogItems)
56+
if (!Guid.TryParse(catalogItem.Attribute("id")?.Value, out Guid catalogItemGuid))
5957
{
60-
if (!Guid.TryParse(catalogItem.Attribute("id")?.Value, out Guid catalogItemGuid))
61-
{
62-
continue;
63-
}
58+
continue;
59+
}
6460

65-
XElement selection = catalogItem.Element(ns + "Selection");
66-
if (selection == null || !selection.HasElements)
67-
{
68-
continue;
69-
}
61+
// Take name from the Name element, if not available use the Guid as name
62+
string displayName = catalogItem.Element(ns + "Name")?.Value;
63+
if (String.IsNullOrWhiteSpace(displayName))
64+
{
65+
displayName = catalogItemGuid.ToString();
66+
}
7067

71-
string specific = selection.Element(ns + "Specific")?.Value;
72-
if (!String.IsNullOrWhiteSpace(specific))
73-
{
74-
//CatalogIdentifier identifier = CatalogIdentifier.WithVersion(catalogItemGuid, specific);
68+
XElement selection = catalogItem.Element(ns + "Selection");
69+
if (selection == null || !selection.HasElements)
70+
{
71+
continue;
72+
}
7573

76-
// Download specific version (if exists)
77-
continue;
78-
}
74+
string specific = selection.Element(ns + "Specific")?.Value;
75+
if (!String.IsNullOrWhiteSpace(specific))
76+
{
77+
catalogIdentifiers.Add((CatalogIdentifier.WithVersion(catalogItemGuid, specific), displayName));
78+
continue;
79+
}
7980

80-
XElement range = selection.Element(ns + "Range");
81-
if (!String.IsNullOrWhiteSpace(range?.Value))
82-
{
83-
Boolean.TryParse(range.Attribute("allowPrerelease")?.Value, out bool allowPrerelease);
84-
//CatalogIdentifier identifier = CatalogIdentifier.WithRange(catalogItemGuid, range.Value, allowPrerelease);
85-
// Download latest version of range
86-
}
81+
XElement range = selection.Element(ns + "Range");
82+
if (!String.IsNullOrWhiteSpace(range?.Value))
83+
{
84+
Boolean.TryParse(range.Attribute("allowPrerelease")?.Value, out bool allowPrerelease);
85+
catalogIdentifiers.Add((CatalogIdentifier.WithRange(catalogItemGuid, range.Value, allowPrerelease), displayName));
8786
}
8887
}
88+
89+
return catalogIdentifiers;
8990
}
9091
}
9192
}

Sdk/Sdk.csproj

+9-3
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ By integrating this SDK into your build process, you can easily generate install
4343
<PackageReference Include="Nito.AsyncEx.Tasks" Version="5.1.2" />
4444
<PackageReference Include="Skyline.DataMiner.CICD.DMApp.Common" Version="2.0.16" />
4545
<PackageReference Include="Skyline.DataMiner.CICD.Assemblers.Automation" Version="1.1.2" />
46+
<PackageReference Include="Skyline.DataMiner.Core.AppPackageCreator" Version="2.1.0-echo" />
47+
<PackageReference Include="Skyline.DataMiner.Core.ArtifactDownloader" Version="2.1.0-echo" />
4648
<PackageReference Include="Skyline.DataMiner.CICD.FileSystem" Version="1.1.0" />
4749
<PackageReference Include="Skyline.DataMiner.CICD.Parsers.Common" Version="1.1.1" />
48-
<PackageReference Include="Skyline.DataMiner.Core.AppPackageCreator" Version="2.0.5" />
49-
<PackageReference Include="System.Text.Json" Version="9.0.2" />
5050
</ItemGroup>
5151

5252
<ItemGroup>
@@ -55,8 +55,14 @@ By integrating this SDK into your build process, you can easily generate install
5555

5656
<Target Name="CopyProjectReferencesToPackage" DependsOnTargets="ResolveReferences">
5757
<ItemGroup>
58-
<!-- The TargetPath is the path inside the package that the source file will be placed. This is already precomputed in the ReferenceCopyLocalPaths items' DestinationSubPath, so reuse it here. -->
58+
<!-- The dependencies of your MSBuild task must be packaged inside the package, they cannot be expressed as normal PackageReferences -->
5959
<BuildOutputInPackage Include="@(ReferenceCopyLocalPaths)" TargetPath="%(ReferenceCopyLocalPaths.DestinationSubPath)" />
6060
</ItemGroup>
6161
</Target>
62+
63+
<Target Name="LocalTesting" AfterTargets="Pack" Condition="'$(Configuration)' == 'Debug' And $(USERPROFILE.Contains('MichielOD'))">
64+
<RemoveDir Directories="$(USERPROFILE)\.nuget\packages\skyline.dataminer.sdk\$(PackageVersion)" />
65+
<Copy SourceFiles="$(MSBuildProjectDirectory)\$(BaseOutputPath)$(Configuration)\$(AssemblyName).$(PackageVersion).nupkg" DestinationFolder="$(USERPROFILE)\Documents\MyNugets" />
66+
<Message Text="### Finished copying new package. ###" Importance="High" />
67+
</Target>
6268
</Project>

Sdk/Sdk/Sdk.targets

+9-6
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,26 @@
1111
<Target Name="DmappCreation" AfterTargets="Build" Condition="'$(GenerateDataMinerPackage)' == 'true'">
1212
<DmappCreation
1313
ProjectFile="$(MSBuildProjectFile)"
14-
BaseOutputPath="$(BaseOutputPath)"
15-
Configuration="$(Configuration)"
14+
Output="$(OutDir)"
1615

1716
ProjectType="$(DataMinerType)"
1817

1918
PackageId="$(PackageId)"
2019
PackageVersion="$(Version)"
2120
MinimumRequiredDmVersion="$(MinimumRequiredDmVersion)"
21+
22+
UserSecretsId="$(UserSecretsId)"
23+
CatalogPublishKeyName="$(CatalogPublishKeyName)"
24+
CatalogDefaultDownloadKeyName="$(CatalogDefaultDownloadKeyName)"
25+
26+
Debug="$(SkylineDataMinerSdkDebug)"
2227
/>
2328
</Target>
2429

2530
<Target Name="CatalogInformation" AfterTargets="Build" Condition="'$(GenerateDataMinerPackage)' == 'true'">
2631
<CatalogInformation
2732
ProjectDirectory="$(MSBuildProjectDirectory)"
28-
BaseOutputPath="$(BaseOutputPath)"
29-
Configuration="$(Configuration)"
33+
Output="$(OutDir)"
3034
PackageId="$(PackageId)"
3135
PackageVersion="$(Version)"
3236
/>
@@ -37,8 +41,7 @@
3741
<Message Text="Publishing to catalog.dataminer.services...." Importance="high" />
3842
<PublishToCatalog
3943
ProjectDirectory="$(MSBuildProjectDirectory)"
40-
BaseOutputPath="$(BaseOutputPath)"
41-
Configuration="$(Configuration)"
44+
Output="$(OutDir)"
4245
PackageId="$(PackageId)"
4346
PackageVersion="$(Version)"
4447
VersionComment="$(VersionComment)"

0 commit comments

Comments
 (0)