-
Notifications
You must be signed in to change notification settings - Fork 3
Key stone #43
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
Closed
Closed
Key stone #43
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
5fc862f
Initial code. Test with RUST exe and NET6 exe.
janstaelensskyline 5aeec26
Integration Tests for several frameworks and languages
janstaelensskyline 2b54bfc
removed test category
janstaelensskyline f2ebe86
Added keystone to packager tool.
janstaelensskyline 2f1b209
Code cleanup
janstaelensskyline cc65d20
wip
janstaelensskyline ac03667
Fixes possible issue when working dir was the input dir
janstaelensskyline 191ebfe
Code cleanup and documentation.
janstaelensskyline 2641da6
removed some debug logs
janstaelensskyline 837bf17
Updated latest beta packagecreator
janstaelensskyline d284563
Cleanup
MichielOda d58aad8
Pre-release nuget (to run tests & SonarCloud)
MichielOda 400e228
SC remarks
MichielOda 56a02ef
Forgotten file
MichielOda 0db5ae0
handle productVersions with
janstaelensskyline b0db9ef
Fixes to allow .nupkg
janstaelensskyline 415754a
Update to include the latest FileSystem NuGet
MichielOda 5dea99a
Sanitization of input values.
janstaelensskyline 414d0a5
WIP
janstaelensskyline 0a3eabe
Update private-dataminer-cicd-nugetsolution.yml
janstaelensskyline dfa3abe
Update private-dataminer-cicd-nugetsolution.yml
janstaelensskyline File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| namespace Skyline.DataMiner.CICD.DMApp.Common | ||
| { | ||
| using System; | ||
| using System.Diagnostics; | ||
| using System.Text; | ||
|
|
||
| internal class Dotnet : IDotnet | ||
| { | ||
| private readonly DataReceivedEventHandler onOutput; | ||
| private readonly DataReceivedEventHandler onError; | ||
|
|
||
| public Dotnet(DataReceivedEventHandler onOutput, DataReceivedEventHandler onError) | ||
| { | ||
| this.onOutput = onOutput; | ||
| this.onError = onError; | ||
| } | ||
|
|
||
| public bool Run(string command, bool ignoreOutput) | ||
| { | ||
| bool success = ignoreOutput | ||
| ? Run(command, null, null) | ||
| : Run(command).succes; | ||
|
|
||
| return success; | ||
| } | ||
|
|
||
| public (bool succes, string output, string errors) Run(string command) | ||
| { | ||
| StringBuilder totalOutput = new StringBuilder(); | ||
| StringBuilder totalErrors = new StringBuilder(); | ||
|
|
||
| bool success = Run(command, OnOutputWrapped, OnErrorWrapped); | ||
|
|
||
| return (success, totalOutput.ToString(), totalErrors.ToString()); | ||
|
|
||
| void OnOutputWrapped(object sender, DataReceivedEventArgs e) | ||
| { | ||
| if (!String.IsNullOrEmpty(e.Data)) | ||
| { | ||
| totalOutput.AppendLine(e.Data); | ||
| onOutput(sender, e); | ||
| } | ||
| } | ||
|
|
||
| void OnErrorWrapped(object sender, DataReceivedEventArgs e) | ||
| { | ||
| if (!String.IsNullOrEmpty(e.Data)) | ||
| { | ||
| totalErrors.AppendLine(e.Data); | ||
| onError(sender, e); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private static bool Run(string command, DataReceivedEventHandler overrideOnOutput, DataReceivedEventHandler overrideOnError) | ||
| { | ||
| bool useOutput = overrideOnOutput != null; | ||
| bool useError = overrideOnError != null; | ||
|
|
||
| const string pathTo = "dotnet"; | ||
| ProcessStartInfo details = new ProcessStartInfo(pathTo, command) | ||
| { | ||
| CreateNoWindow = true, | ||
| UseShellExecute = false, | ||
| RedirectStandardError = useError, | ||
| RedirectStandardOutput = useOutput | ||
| }; | ||
|
|
||
| bool success; | ||
| using (var process = new Process()) | ||
| { | ||
| process.StartInfo = details; | ||
|
|
||
| if (useError) | ||
| { | ||
| process.ErrorDataReceived += overrideOnError; | ||
| } | ||
|
|
||
| if (useOutput) | ||
| { | ||
| process.OutputDataReceived += overrideOnOutput; | ||
| } | ||
|
|
||
| if (process.Start()) | ||
| { | ||
| if (useOutput) | ||
| { | ||
| process.BeginOutputReadLine(); | ||
| } | ||
|
|
||
| if (useError) | ||
| { | ||
| process.BeginErrorReadLine(); | ||
| } | ||
|
|
||
| process.WaitForExit(); | ||
| success = process.ExitCode == 0; | ||
| } | ||
| else | ||
| { | ||
| success = false; | ||
| } | ||
| } | ||
|
|
||
| return success; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| namespace Skyline.DataMiner.CICD.DMApp.Common | ||
| { | ||
| using System.Diagnostics; | ||
|
|
||
| /// <summary> | ||
| /// Creates instances of <see cref="IDotnet"/>. | ||
| /// </summary> | ||
| public static class DotnetFactory | ||
| { | ||
| /// <summary> | ||
| /// Creates a single instance of <see cref="IDotnet"/>. | ||
| /// </summary> | ||
| /// <returns>An instance of <see cref="IDotnet"/>.</returns> | ||
| public static IDotnet Create(DataReceivedEventHandler onOutput, DataReceivedEventHandler onError) | ||
| { | ||
| return new Dotnet(onOutput, onError); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| namespace Skyline.DataMiner.CICD.DMApp.Common | ||
| { | ||
| /// <summary> | ||
| /// Allows running dotnet commands. | ||
| /// </summary> | ||
| public interface IDotnet | ||
| { | ||
| /// <summary> | ||
| /// Run a dotnet command. | ||
| /// </summary> | ||
| /// <param name="command">Command to run.</param> | ||
| /// <param name="ignoreOutput"><c>True</c> to ignore the output.</param> | ||
| /// <returns><c>True</c> when the command was successful.</returns> | ||
| bool Run(string command, bool ignoreOutput); | ||
|
|
||
| /// <summary> | ||
| /// Run a dotnet command. | ||
| /// </summary> | ||
| /// <param name="command">Command to run.</param> | ||
| /// <returns><c>True</c> when the command was successful and the corresponding output and errors.</returns> | ||
| (bool succes, string output, string errors) Run(string command); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| namespace Skyline.DataMiner.CICD.DMApp.Keystone | ||
| { | ||
| using System; | ||
| using System.Diagnostics; | ||
| using System.Threading.Tasks; | ||
|
|
||
| using Skyline.DataMiner.CICD.DMApp.Common; | ||
| using Skyline.DataMiner.CICD.FileSystem; | ||
| using Skyline.DataMiner.CICD.Loggers; | ||
|
|
||
| using static Skyline.AppInstaller.AppPackage; | ||
|
|
||
| /// <summary> | ||
| /// Represents a creator for application packages specifically for Keystone within the DataMiner System. | ||
| /// </summary> | ||
| public class AppPackageCreatorForKeystone : AppPackageCreator | ||
| { | ||
| private readonly ToolMetaData toolMetaData; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="AppPackageCreatorForKeystone"/> class. | ||
| /// </summary> | ||
| /// <param name="toolMetaData">Metadata associated with the tool.</param> | ||
| /// <param name="fileSystem">File system interface to manage file operations.</param> | ||
| /// <param name="logCollector">Log collector to capture logs during operations.</param> | ||
| /// <param name="directoryPath">The directory path where packages are to be created.</param> | ||
| /// <param name="packageName">The name of the package.</param> | ||
| /// <param name="packageVersion">The version of the package.</param> | ||
| public AppPackageCreatorForKeystone(ToolMetaData toolMetaData, IFileSystem fileSystem, ILogCollector logCollector, string directoryPath, string packageName, DMAppVersion packageVersion) : base(fileSystem, logCollector, directoryPath, packageName, packageVersion) | ||
| { | ||
| this.toolMetaData = toolMetaData; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Asynchronously adds items to the application package. | ||
| /// </summary> | ||
| /// <param name="appPackageBuilder">The application package builder to which the items are added.</param> | ||
| /// <returns>A task that represents the asynchronous operation.</returns> | ||
| public override async Task AddItemsAsync(AppPackageBuilder appPackageBuilder) | ||
| { | ||
| if (appPackageBuilder == null) throw new ArgumentNullException(nameof(appPackageBuilder)); | ||
| string pathToCreatedTool; | ||
|
|
||
| if (RepositoryPath.EndsWith(".nupkg")) | ||
| { | ||
| // Already provided a nuget dotnet tool? | ||
| pathToCreatedTool = RepositoryPath; | ||
| } | ||
| else | ||
| { | ||
| // Dotnet tools cannot directly run .exe files. They make their own .exe that runs the Main method from a .dll. So we make our "in-between" tool that then executes the user application. | ||
| IUserExecutable userExecutable = new UserExecutable(); | ||
|
|
||
| static void OnOutput(object sender, DataReceivedEventArgs e) | ||
| { | ||
| if (!String.IsNullOrEmpty(e.Data)) | ||
| { | ||
| Console.WriteLine(e.Data); | ||
| } | ||
| } | ||
|
|
||
| static void OnError(object sender, DataReceivedEventArgs e) | ||
| { | ||
| if (!String.IsNullOrEmpty(e.Data)) | ||
| { | ||
| Console.Error.WriteLine(e.Data); // Write the error data to the console | ||
| } | ||
| } | ||
|
|
||
| var dotnet = DotnetFactory.Create(OnOutput, OnError); | ||
|
|
||
| pathToCreatedTool = userExecutable.WrapIntoDotnetTool(FileSystem, dotnet, RepositoryPath, toolMetaData); | ||
| } | ||
|
|
||
| Console.WriteLine($"Creating dmapp from keystone file {pathToCreatedTool}"); | ||
| appPackageBuilder.WithKeystone(pathToCreatedTool); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Contains methods to facilitate the creation of <see cref="AppPackageCreatorForKeystone"/> instances. | ||
| /// </summary> | ||
| public static class Factory | ||
| { | ||
| /// <summary> | ||
| /// Creates an instance of <see cref="AppPackageCreatorForKeystone"/> from a repository with specified parameters. | ||
| /// </summary> | ||
| /// <param name="metaData">Metadata associated with the tool.</param> | ||
| /// <param name="filesystem">File system interface to manage file operations.</param> | ||
| /// <param name="log">Log collector to capture logs during operations.</param> | ||
| /// <param name="directoryPath">The directory path where packages are to be created.</param> | ||
| /// <param name="packageName">The name of the package.</param> | ||
| /// <param name="packageVersion">The version of the package.</param> | ||
| /// <returns>Returns a new instance of <see cref="AppPackageCreatorForKeystone"/>.</returns> | ||
| public static IAppPackageCreator FromRepository(ToolMetaData metaData, IFileSystem filesystem, ILogCollector log, string directoryPath, string packageName, DMAppVersion packageVersion) | ||
| { | ||
| return new AppPackageCreatorForKeystone(metaData, filesystem, log, directoryPath, packageName, packageVersion); | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net6.0</TargetFramework> | ||
| <AssemblyName>Skyline.DataMiner.CICD.DMApp.Keystone</AssemblyName> | ||
| <RootNamespace>Skyline.DataMiner.CICD.DMApp.Keystone</RootNamespace> | ||
| <GenerateDocumentationFile>True</GenerateDocumentationFile> | ||
| <GeneratePackageOnBuild>True</GeneratePackageOnBuild> | ||
| <Authors>SkylineCommunications</Authors> | ||
| <Company>Skyline Communications</Company> | ||
| <PackageLicenseFile>LICENSE.txt</PackageLicenseFile> | ||
| <PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance> | ||
| <PackageIcon>icon.png</PackageIcon> | ||
| <PackageProjectUrl>https://skyline.be/</PackageProjectUrl> | ||
| <PackageTags>Skyline;DataMiner;CICD</PackageTags> | ||
| <Description> | ||
| Library to convert a directory with an executable into DataMiner Application Packages (.DMApp) file. | ||
| Code Entry Point: var builder = AppPackageCreatorForKeystone.Factory.FromDirectory(logCollector, repositoryPath, packageName, packageVersion); | ||
| </Description> | ||
| <PackageReadmeFile>README.md</PackageReadmeFile> | ||
| <RepositoryUrl>https://github.com/SkylineCommunications/Skyline.DataMiner.CICD.Packages</RepositoryUrl> | ||
| <RepositoryType>git</RepositoryType> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Compile Remove="ExeShimmy\**" /> | ||
| <Content Include="ExeShimmy\**" CopyToOutputDirectory="Always" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <None Include="..\README.md" Pack="true" PackagePath="" /> | ||
| <None Include="..\_NuGetItems\icon.png" Pack="true" PackagePath="" /> | ||
| <None Include="..\_NuGetItems\LICENSE.txt" Pack="true" PackagePath="" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\DMApp.Common\DMApp.Common.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <PackAsTool>true</PackAsTool> | ||
| <ToolCommandName>$ToolCommand$</ToolCommandName> | ||
| <AssemblyName>$ToolName$</AssemblyName> | ||
| <ImplicitUsings>disable</ImplicitUsings> | ||
| <Nullable>disable</Nullable> | ||
| <PackageVersion>$ToolVersion$</PackageVersion> | ||
| <Version>$ToolVersion$</Version> | ||
| <PackageTags>Skyline;DataMiner</PackageTags> | ||
| <PackageProjectUrl>https://skyline.be</PackageProjectUrl> | ||
| <PackageReadmeFile>README.md</PackageReadmeFile> | ||
| <PackageLicenseFile>LICENSE.txt</PackageLicenseFile> | ||
| <PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance> | ||
| <PackageIcon>Icon.png</PackageIcon> | ||
| <GenerateDocumentationFile>True</GenerateDocumentationFile> | ||
| <Authors>$Authors$</Authors> | ||
| <Company>$Company$</Company> | ||
| <Description></Description> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <None Include="$ProgramNameShimmy$\**\*"> | ||
| <CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
| </None> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Content Include="Icon.png"> | ||
| <Pack>True</Pack> | ||
| <PackagePath>\</PackagePath> | ||
| </Content> | ||
| <Content Include="LICENSE.txt"> | ||
| <Pack>True</Pack> | ||
| <PackagePath>\</PackagePath> | ||
| </Content> | ||
| <Content Include="README.md"> | ||
| <Pack>True</Pack> | ||
| <PackagePath>\</PackagePath> | ||
| </Content> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.