Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
leandromonaco committed Jan 22, 2025
2 parents d7c969c + b01c687 commit 3d56170
Show file tree
Hide file tree
Showing 12 changed files with 282 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ jobs:
run: dir ${{ github.workspace }}\dx-cli\nupkgs

- name: Publish to GitHub Packages
run: dotnet nuget push ${{ github.workspace }}\dx-cli\nupkgs\*.nupkg --source "github" --api-key ${{ secrets.GITHUB_TOKEN }}
run: dotnet nuget push ${{ github.workspace }}\dx-cli\nupkgs\*.nupkg --source "github" --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ jobs:
run: dir ${{ github.workspace }}\dx-cli\nupkgs

- name: Publish to NuGet.org
run: dotnet nuget push ${{ github.workspace }}\dx-cli\nupkgs\*.nupkg --source "https://api.nuget.org/v3/index.json" --api-key ${{ secrets.NUGET_API_KEY }}
run: dotnet nuget push ${{ github.workspace }}\dx-cli\nupkgs\*.nupkg --source "https://api.nuget.org/v3/index.json" --api-key ${{ secrets.NUGET_API_KEY }} --skip-duplicate
47 changes: 47 additions & 0 deletions .github/workflows/sonarqube.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: SonarQube
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
jobs:
build:
name: Build and analyze
runs-on: windows-latest
steps:
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'zulu' # Alternative distribution options are available.
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Cache SonarQube Cloud packages
uses: actions/cache@v4
with:
path: ~\sonar\cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache SonarQube Cloud scanner
id: cache-sonar-scanner
uses: actions/cache@v4
with:
path: .\.sonar\scanner
key: ${{ runner.os }}-sonar-scanner
restore-keys: ${{ runner.os }}-sonar-scanner
- name: Install SonarQube Cloud scanner
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
shell: powershell
run: |
New-Item -Path .\.sonar\scanner -ItemType Directory
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner
- name: Build and analyze
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
shell: powershell
run: |
.\.sonar\scanner\dotnet-sonarscanner begin /k:"devexlead_devex-cli" /o:"devexlead" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io"
dotnet build
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
17 changes: 16 additions & 1 deletion devex-cli.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
.github\workflows\release.yml = .github\workflows\release.yml
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dxc", "src\DevEx.Console\dxc.csproj", "{630B8EA8-DE56-43E9-8621-1DF5CAE4BBFC}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DevEx.Console", "src\DevEx.Console\DevEx.Console.csproj", "{630B8EA8-DE56-43E9-8621-1DF5CAE4BBFC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DevEx.Plugins.Vault", "src\DevEx.Plugins\DevEx.Plugins.Vault\DevEx.Plugins.Vault.csproj", "{0681C47A-A740-4C94-BBAE-F6D4D09BF3F4}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Plugins", "Plugins", "{1C0CF661-9E4C-4306-84A0-CCCC9F67B518}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DevEx.Core", "src\DevEx.Core\DevEx.Core.csproj", "{186999ED-CCC0-42D0-A5D9-F5828B2E941A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -23,11 +29,20 @@ Global
{630B8EA8-DE56-43E9-8621-1DF5CAE4BBFC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{630B8EA8-DE56-43E9-8621-1DF5CAE4BBFC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{630B8EA8-DE56-43E9-8621-1DF5CAE4BBFC}.Release|Any CPU.Build.0 = Release|Any CPU
{0681C47A-A740-4C94-BBAE-F6D4D09BF3F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0681C47A-A740-4C94-BBAE-F6D4D09BF3F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0681C47A-A740-4C94-BBAE-F6D4D09BF3F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0681C47A-A740-4C94-BBAE-F6D4D09BF3F4}.Release|Any CPU.Build.0 = Release|Any CPU
{186999ED-CCC0-42D0-A5D9-F5828B2E941A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{186999ED-CCC0-42D0-A5D9-F5828B2E941A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{186999ED-CCC0-42D0-A5D9-F5828B2E941A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{186999ED-CCC0-42D0-A5D9-F5828B2E941A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{8E024A71-387E-4CEE-9C96-78E933D26CA7} = {639ED8D3-7ABB-4090-99DB-1507FCD572CD}
{0681C47A-A740-4C94-BBAE-F6D4D09BF3F4} = {1C0CF661-9E4C-4306-84A0-CCCC9F67B518}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<PackageId>dxc</PackageId>
<PackAsTool>true</PackAsTool> <!-- This makes it a .NET tool -->
<ToolCommandName>dxc</ToolCommandName> <!-- The command users will run -->
<!-- This makes it a .NET tool -->
<PackAsTool>true</PackAsTool>
<!-- The command users will run -->
<ToolCommandName>dxc</ToolCommandName>
</PropertyGroup>

<ItemGroup>
Expand All @@ -17,6 +19,11 @@
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\DevEx.Core\DevEx.Core.csproj"/>
<ProjectReference Include="..\DevEx.Plugins\DevEx.Plugins.Vault\DevEx.Plugins.Vault.csproj"/>
</ItemGroup>

<ItemGroup>
<None Update="version.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
Expand Down
13 changes: 12 additions & 1 deletion src/DevEx.Console/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
using System.CommandLine;
using System.CommandLine.Builder;
using System.CommandLine.Parsing;
using DevEx.Core;

var rootCommand = new RootCommand();
return await rootCommand.InvokeAsync(args);

PluginService.LoadPlugins(rootCommand);

var builder = new CommandLineBuilder(rootCommand)
.UseDefaults()
.UseSuggestDirective();

var parser = builder.Build();
return await parser.InvokeAsync(args);
4 changes: 2 additions & 2 deletions src/DevEx.Console/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"profiles": {
"dx": {
"DevEx.Console": {
"commandName": "Project",
"commandLineArgs": "dx --version"
"commandLineArgs": "--version"
}
}
}
14 changes: 14 additions & 0 deletions src/DevEx.Core/DevEx.Core.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
</ItemGroup>

</Project>
12 changes: 12 additions & 0 deletions src/DevEx.Core/IPlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.CommandLine;

namespace DevEx.Core
{
public interface IPlugin
{
string Name { get; }
string Description { get; }
Command GetCommand();
}

}
39 changes: 39 additions & 0 deletions src/DevEx.Core/PluginService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System.CommandLine;

namespace DevEx.Core
{
public class PluginService
{
public static void LoadPlugins(RootCommand rootCommand)
{
var pluginAssemblies = Directory.GetFiles(AppContext.BaseDirectory, "DevEx.Plugins.*.dll");
foreach (var assemblyPath in pluginAssemblies)
{
try
{
var assembly = System.Runtime.Loader.AssemblyLoadContext.Default.LoadFromAssemblyPath(assemblyPath);

var pluginTypes = assembly.GetTypes()
.Where(type => typeof(IPlugin)
.IsAssignableFrom(type) && !type.IsInterface);

foreach (var type in pluginTypes)
{
if (Activator.CreateInstance(type) is IPlugin plugin)
{
#if DEBUG
Console.WriteLine($"Loading plugin: {plugin.Name} - {plugin.Description}");
#endif
var command = plugin.GetCommand();
rootCommand.AddCommand(command);
}
}
}
catch (Exception ex)
{
Console.WriteLine($"Failed to load plugins from {assemblyPath}: {ex.Message}");
}
}
}
}
}
111 changes: 111 additions & 0 deletions src/DevEx.Plugins/DevEx.Plugins.Vault/Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
using System.CommandLine;
using DevEx.Core;

namespace DevEx.Plugins.Vault
{
public class SamplePlugin : IPlugin
{
public string Name => "vault";
public string Description => "Manage items in the vault";

public Command GetCommand()
{
var vaultCommand = new Command(Name, Description);

// Create subcommands for actions
Command createCommand = BuildCreateCommand();
Command deleteCommand = BuildDeleteCommand();
Command modifyCommand = BuildModifyCommand();
Command readCommand = BuildReadCommand();

// Add subcommands to the main vault command
vaultCommand.AddCommand(createCommand);
vaultCommand.AddCommand(deleteCommand);
vaultCommand.AddCommand(modifyCommand);
vaultCommand.AddCommand(readCommand);

return vaultCommand;
}

private static Command BuildReadCommand()
{
var readCommand = new Command("read", "Fetch an item from the vault")
{
new Option<string>("--key", "The key of the item to fetch")
};
readCommand.SetHandler((string key) =>
{
if (string.IsNullOrWhiteSpace(key))
{
Console.WriteLine("--key is required for read.");
return;
}
Console.WriteLine($"Fetched item with Key={key}");
},
readCommand.Options[0] as Option<string>);

Check warning on line 45 in src/DevEx.Plugins/DevEx.Plugins.Vault/Class1.cs

View workflow job for this annotation

GitHub Actions / build-test-publish-to-nuget

Possible null reference argument for parameter 'symbol' in 'void Handler.SetHandler<string>(Command command, Action<string> handle, IValueDescriptor<string> symbol)'.

Check warning on line 45 in src/DevEx.Plugins/DevEx.Plugins.Vault/Class1.cs

View workflow job for this annotation

GitHub Actions / build-test-publish-to-nuget

Possible null reference argument for parameter 'symbol' in 'void Handler.SetHandler<string>(Command command, Action<string> handle, IValueDescriptor<string> symbol)'.
return readCommand;
}

private static Command BuildModifyCommand()
{
var modifyCommand = new Command("modify", "Modify an item in the vault")
{
new Option<string>("--key", "The key of the item to modify"),
new Option<string>("--value", "The new value of the item")
};
modifyCommand.SetHandler((string key, string value) =>
{
if (string.IsNullOrWhiteSpace(key) || string.IsNullOrWhiteSpace(value))
{
Console.WriteLine("Both --key and --value are required for modify.");
return;
}
Console.WriteLine($"Modified item: Key={key}, New Value={value}");
},
modifyCommand.Options[0] as Option<string>,

Check warning on line 65 in src/DevEx.Plugins/DevEx.Plugins.Vault/Class1.cs

View workflow job for this annotation

GitHub Actions / build-test-publish-to-nuget

Possible null reference argument for parameter 'symbol1' in 'void Handler.SetHandler<string, string>(Command command, Action<string, string> handle, IValueDescriptor<string> symbol1, IValueDescriptor<string> symbol2)'.

Check warning on line 65 in src/DevEx.Plugins/DevEx.Plugins.Vault/Class1.cs

View workflow job for this annotation

GitHub Actions / build-test-publish-to-nuget

Possible null reference argument for parameter 'symbol1' in 'void Handler.SetHandler<string, string>(Command command, Action<string, string> handle, IValueDescriptor<string> symbol1, IValueDescriptor<string> symbol2)'.
modifyCommand.Options[1] as Option<string>);

Check warning on line 66 in src/DevEx.Plugins/DevEx.Plugins.Vault/Class1.cs

View workflow job for this annotation

GitHub Actions / build-test-publish-to-nuget

Possible null reference argument for parameter 'symbol2' in 'void Handler.SetHandler<string, string>(Command command, Action<string, string> handle, IValueDescriptor<string> symbol1, IValueDescriptor<string> symbol2)'.

Check warning on line 66 in src/DevEx.Plugins/DevEx.Plugins.Vault/Class1.cs

View workflow job for this annotation

GitHub Actions / build-test-publish-to-nuget

Possible null reference argument for parameter 'symbol2' in 'void Handler.SetHandler<string, string>(Command command, Action<string, string> handle, IValueDescriptor<string> symbol1, IValueDescriptor<string> symbol2)'.
return modifyCommand;
}

private static Command BuildDeleteCommand()
{
var deleteCommand = new Command("delete", "Remove an item from the vault")
{
new Option<string>("--key", "The key of the item to remove")
};
deleteCommand.SetHandler((string key) =>
{
if (string.IsNullOrWhiteSpace(key))
{
Console.WriteLine("--key is required for delete.");
return;
}
Console.WriteLine($"Deleted item with Key={key}");
},
deleteCommand.Options[0] as Option<string>);

Check warning on line 85 in src/DevEx.Plugins/DevEx.Plugins.Vault/Class1.cs

View workflow job for this annotation

GitHub Actions / build-test-publish-to-nuget

Possible null reference argument for parameter 'symbol' in 'void Handler.SetHandler<string>(Command command, Action<string> handle, IValueDescriptor<string> symbol)'.

Check warning on line 85 in src/DevEx.Plugins/DevEx.Plugins.Vault/Class1.cs

View workflow job for this annotation

GitHub Actions / build-test-publish-to-nuget

Possible null reference argument for parameter 'symbol' in 'void Handler.SetHandler<string>(Command command, Action<string> handle, IValueDescriptor<string> symbol)'.
return deleteCommand;
}

private static Command BuildCreateCommand()
{
var createCommand = new Command("create", "Add an item to the vault")
{
new Option<string>("--key", "The key of the item to add"),
new Option<string>("--value", "The value of the item to add")
};
createCommand.SetHandler((string key, string value) =>
{
if (string.IsNullOrWhiteSpace(key) || string.IsNullOrWhiteSpace(value))
{
Console.WriteLine("Both --key and --value are required for create.");
return;
}
Console.WriteLine($"Created item: Key={key}, Value={value}");
},
createCommand.Options[0] as Option<string>,

Check warning on line 105 in src/DevEx.Plugins/DevEx.Plugins.Vault/Class1.cs

View workflow job for this annotation

GitHub Actions / build-test-publish-to-nuget

Possible null reference argument for parameter 'symbol1' in 'void Handler.SetHandler<string, string>(Command command, Action<string, string> handle, IValueDescriptor<string> symbol1, IValueDescriptor<string> symbol2)'.
createCommand.Options[1] as Option<string>);

Check warning on line 106 in src/DevEx.Plugins/DevEx.Plugins.Vault/Class1.cs

View workflow job for this annotation

GitHub Actions / build-test-publish-to-nuget

Possible null reference argument for parameter 'symbol2' in 'void Handler.SetHandler<string, string>(Command command, Action<string, string> handle, IValueDescriptor<string> symbol1, IValueDescriptor<string> symbol2)'.
return createCommand;
}
}

}
18 changes: 18 additions & 0 deletions src/DevEx.Plugins/DevEx.Plugins.Vault/DevEx.Plugins.Vault.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\DevEx.Core\DevEx.Core.csproj" />
</ItemGroup>

</Project>

0 comments on commit 3d56170

Please sign in to comment.