Skip to content
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
159 changes: 159 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
root = true

[*]
insert_final_newline = false
trim_trailing_whitespace = true

ij_any_if_brace_force = always
ij_any_do_while_brace_force = always
ij_any_for_brace_force = always
ij_any_while_brace_force = always

[*.cs]
ij_any_space_before_colon = false
ij_any_space_after_colon = true

ij_any_space_before_comma = false
ij_any_space_after_comma = true

ij_any_space_before_quest = true
ij_any_space_after_quest = true

ij_any_while_on_new_line = true
ij_any_finally_on_new_line = true
insert_final_newline = true
ij_any_catch_on_new_line = true
ij_any_else_on_new_line = true

ij_any_align_group_field_declarations = true
csharp_using_directive_placement = outside_namespace:error
csharp_prefer_simple_using_statement = true:error
csharp_prefer_braces = true:error
csharp_style_namespace_declarations = file_scoped:error
csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_top_level_statements = true:silent
csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_constructors = false:silent
csharp_style_expression_bodied_operators = false:silent
csharp_style_expression_bodied_properties = true:silent
csharp_style_expression_bodied_indexers = true:silent
csharp_style_expression_bodied_accessors = true:silent
csharp_style_expression_bodied_lambdas = true:silent
csharp_style_expression_bodied_local_functions = false:silent
csharp_indent_labels = one_less_than_current
csharp_space_after_cast = true
csharp_space_around_binary_operators = before_and_after
csharp_style_throw_expression = true:suggestion
csharp_style_prefer_null_check_over_type_check = true:suggestion
csharp_prefer_simple_default_expression = true:suggestion
csharp_style_prefer_local_over_anonymous_function = true:suggestion
csharp_style_prefer_index_operator = true:suggestion
csharp_style_prefer_range_operator = true:suggestion
csharp_style_implicit_object_creation_when_type_is_apparent = true:suggestion
csharp_style_prefer_tuple_swap = true:suggestion
csharp_style_prefer_utf8_string_literals = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion
csharp_style_deconstructed_variable_declaration = true:suggestion
csharp_style_unused_value_assignment_preference = discard_variable:suggestion
csharp_style_unused_value_expression_statement_preference = discard_variable:silent
csharp_prefer_static_local_function = true:suggestion
csharp_style_prefer_readonly_struct = true:suggestion
csharp_style_prefer_readonly_struct_member = true:suggestion
csharp_style_allow_embedded_statements_on_same_line_experimental = true:silent
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true:silent
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true:silent
csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = true:silent
csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = true:silent
csharp_style_conditional_delegate_call = true:suggestion
csharp_style_prefer_switch_expression = true:suggestion
csharp_style_prefer_pattern_matching = true:silent
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
csharp_style_prefer_not_pattern = true:suggestion
csharp_style_prefer_extended_property_pattern = true:suggestion
csharp_style_var_for_built_in_types = true:error
csharp_style_var_when_type_is_apparent = true:error
csharp_style_var_elsewhere = true:error


[*.{cs,vb}]
#### Naming styles ####

# Naming rules

dotnet_naming_rule.interface_should_be_begins_with_i.severity = error
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i

dotnet_naming_rule.types_should_be_pascal_case.severity = error
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case

dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case

# Symbol specifications

dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interface.required_modifiers =

dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.types.required_modifiers =

dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.non_field_members.required_modifiers =

# Naming styles

dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.begins_with_i.capitalization = pascal_case

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case
dotnet_style_operator_placement_when_wrapping = beginning_of_line
tab_width = 4
indent_size = 4
end_of_line = crlf
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
dotnet_style_prefer_auto_properties = true:silent
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
dotnet_style_prefer_conditional_expression_over_return = true:silent
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_compound_assignment = true:suggestion
dotnet_style_prefer_simplified_interpolation = true:suggestion
dotnet_style_namespace_match_folder = true:suggestion
dotnet_style_readonly_field = true:suggestion
dotnet_style_predefined_type_for_locals_parameters_members = true:silent
dotnet_style_predefined_type_for_member_access = true:silent
dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent
dotnet_style_allow_multiple_blank_lines_experimental = true:silent
dotnet_style_allow_statement_immediately_after_block_experimental = true:silent
dotnet_code_quality_unused_parameters = all:suggestion
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:silent
dotnet_style_qualification_for_field = false:error
dotnet_style_qualification_for_property = false:error
dotnet_style_qualification_for_method = false:error
dotnet_style_qualification_for_event = false:error
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ namespace ModularPipelines.Analyzers.Test;

public class Net
{
private static readonly Lazy<ReferenceAssemblies> _lazyNet60 = new(() =>
private static readonly Lazy<ReferenceAssemblies> LazyNet60 = new(() =>
new ReferenceAssemblies(
"net6.0",
new PackageIdentity(
"Microsoft.NETCore.App.Ref",
"6.0.19"),
Path.Combine("ref", "net6.0")));

public static ReferenceAssemblies Net60 => _lazyNet60.Value;
public static ReferenceAssemblies Net60 => LazyNet60.Value;
}
1 change: 0 additions & 1 deletion ModularPipelines.Docker/Options/DockerBuildOptions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using ModularPipelines.Attributes;
using ModularPipelines.FileSystem;
using ModularPipelines.Options;
using File = ModularPipelines.FileSystem.File;

namespace ModularPipelines.Docker.Options;

Expand Down
102 changes: 46 additions & 56 deletions ModularPipelines.DotNet/DotNet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,52 @@
using ModularPipelines.Context;
using ModularPipelines.DotNet.Options;
using ModularPipelines.Extensions;
using ModularPipelines.Options;

namespace ModularPipelines.DotNet;

public class DotNet : IDotNet
{
private readonly IModuleContext _context;
private readonly ICommand _command;
private readonly IFileSystemContext _fileSystemContext;
private readonly ITrxParser _trxParser;

public DotNet(IModuleContext context, ITrxParser trxParser)
public DotNet(ITrxParser trxParser, ICommand command, IFileSystemContext fileSystemContext)
{
_context = context;
_trxParser = trxParser;
_command = command;
_fileSystemContext = fileSystemContext;
}

public Task<CommandResult> Restore(DotNetRestoreOptions options, CancellationToken cancellationToken = default)
{
return RunCommand(ToDotNetCommandOptions("restore", options), options, cancellationToken);
var args = new List<string> {"restore"};
args.AddNonNullOrEmpty(options.TargetPath);
return ExecuteCommandLineTool(options, args, cancellationToken);
}

public Task<CommandResult> Build(DotNetBuildOptions options, CancellationToken cancellationToken = default)
{
return RunCommand(ToDotNetCommandOptions("build", options), options, cancellationToken);
}
var args = new List<string> {"build"};
args.AddNonNullOrEmpty(options.TargetPath);
return ExecuteCommandLineTool(options, args, cancellationToken); }

public Task<CommandResult> Publish(DotNetPublishOptions options, CancellationToken cancellationToken = default)
{
return RunCommand(ToDotNetCommandOptions("publish", options), options, cancellationToken);
}
var args = new List<string> {"publish"};
args.AddNonNullOrEmpty(options.TargetPath);
return ExecuteCommandLineTool(options, args, cancellationToken); }

public Task<CommandResult> Pack(DotNetPackOptions options, CancellationToken cancellationToken = default)
{
return RunCommand(ToDotNetCommandOptions("pack", options), options, cancellationToken);
}
var args = new List<string> {"pack"};
args.AddNonNullOrEmpty(options.TargetPath);
return ExecuteCommandLineTool(options, args, cancellationToken); }

public Task<CommandResult> Clean(DotNetCleanOptions options, CancellationToken cancellationToken = default)
{
return RunCommand(ToDotNetCommandOptions("clean", options), options, cancellationToken);
var args = new List<string> {"clean"};
args.AddNonNullOrEmpty(options.TargetPath);
return ExecuteCommandLineTool(options, args, cancellationToken);
}

public async Task<DotNetTestResult> Test(DotNetTestOptions options, CancellationToken cancellationToken = default)
Expand All @@ -48,65 +56,47 @@ public async Task<DotNetTestResult> Test(DotNetTestOptions options, Cancellation

options.Logger ??= new List<string>();
options.Logger.Add($"trx;logfilename={trxFilePath}");

var command = await RunCommand(ToDotNetCommandOptions("test", options), options, cancellationToken);

var trxContents = await _context.FileSystem.GetFile(trxFilePath).ReadAsync();
var args = new List<string> {"test"};
args.AddNonNullOrEmpty(options.TargetPath);
await ExecuteCommandLineTool(options, args, cancellationToken);

var trxContents = await _fileSystemContext.GetFile(trxFilePath).ReadAsync();

return _trxParser.ParseTestResult(trxContents);
}

public Task<CommandResult> Version(CommandLineOptions? options, CancellationToken cancellationToken = default)
public Task<CommandResult> Format(DotNetFormatOptions options, CancellationToken cancellationToken = default)
{
options ??= new CommandLineOptions();

return RunCommand(new DotNetCommandOptions
{
Command = new[] { "--version" },
EnvironmentVariables = options.EnvironmentVariables,
WorkingDirectory = options.WorkingDirectory,
Credentials = options.Credentials,
LogInput = options.LogInput,
LogOutput = options.LogOutput
}, null, cancellationToken);
var args = new List<string> {"format"};
args.AddNonNullOrEmpty(options.TargetPath);
return ExecuteCommandLineTool(options, args, cancellationToken);
}

public Task<CommandResult> CustomCommand(DotNetCommandOptions options, CancellationToken cancellationToken = default)
public Task<CommandResult> Version(DotNetOptions? options, CancellationToken cancellationToken = default)
{
return RunCommand(options, null, cancellationToken);
options ??= new DotNetOptions();

return ExecuteCommandLineTool(options, new[] {"--version"}, cancellationToken);
}

private static DotNetCommandOptions ToDotNetCommandOptions(string command, DotNetOptions options)
public Task<CommandResult> CustomCommand(DotNetCommandOptions options, CancellationToken cancellationToken = default)
{
return new DotNetCommandOptions
var commandLineToolOptions = options.ToCommandLineToolOptions("dotnet", options.Command ?? ArraySegment<string>.Empty) with
{
Command = new []{ command },
EnvironmentVariables = options.EnvironmentVariables,
AdditionalSwitches = options.AdditionalSwitches,
TargetPath = options.TargetPath,
WorkingDirectory = options.WorkingDirectory,
Credentials = options.Credentials,
LogInput = options.LogInput,
LogOutput = options.LogOutput
AdditionalSwitches = options.AdditionalSwitches
};

return _command.ExecuteCommandLineTool(commandLineToolOptions, cancellationToken);
}

private Task<CommandResult> RunCommand(DotNetCommandOptions options, object? optionsObject, CancellationToken cancellationToken)
private Task<CommandResult> ExecuteCommandLineTool(DotNetOptions options, IEnumerable<string> arguments, CancellationToken cancellationToken)
{
var arguments = options.Command?.ToList() ?? new List<string>();

arguments.AddNonNullOrEmpty(options.TargetPath);

return _context.Command.ExecuteCommandLineTool(new CommandLineToolOptions("dotnet")
var commandLineToolOptions = options.ToCommandLineToolOptions("dotnet", arguments) with
{
Arguments = arguments,
EnvironmentVariables = options.EnvironmentVariables,
WorkingDirectory = options.WorkingDirectory,
Credentials = options.Credentials,
LogInput = options.LogInput,
LogOutput = options.LogOutput,
AdditionalSwitches = options.AdditionalSwitches,
ArgumentsOptionObject = optionsObject
}, cancellationToken);
AdditionalSwitches = options.AdditionalSwitches
};

return _command.ExecuteCommandLineTool(commandLineToolOptions, cancellationToken);
}
}
}
6 changes: 3 additions & 3 deletions ModularPipelines.DotNet/IDotNet.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using ModularPipelines.Models;
using ModularPipelines.DotNet.Options;
using ModularPipelines.Options;

namespace ModularPipelines.DotNet;

Expand All @@ -12,8 +11,9 @@ public interface IDotNet
Task<CommandResult> Pack(DotNetPackOptions options, CancellationToken cancellationToken = default);
Task<CommandResult> Clean(DotNetCleanOptions options, CancellationToken cancellationToken = default);
Task<DotNetTestResult> Test(DotNetTestOptions options, CancellationToken cancellationToken = default);
Task<CommandResult> Format(DotNetFormatOptions options, CancellationToken cancellationToken = default);

Task<CommandResult> Version(CommandLineOptions? options = null, CancellationToken cancellationToken = default);
Task<CommandResult> Version(DotNetOptions? options = null, CancellationToken cancellationToken = default);

Task<CommandResult> CustomCommand(DotNetCommandOptions options, CancellationToken cancellationToken = default);
}
}
33 changes: 33 additions & 0 deletions ModularPipelines.DotNet/Options/DotNetFormatOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using ModularPipelines.Attributes;

namespace ModularPipelines.DotNet.Options;

public record DotNetFormatOptions : DotNetOptions
{
[CommandLongSwitch("diagnostics", SwitchValueSeparator = " ")]
public string Diagnostics { get; init; }

[BooleanCommandSwitch("severity")]
public string Severity { get; init; }

[BooleanCommandSwitch("no-restore")]
public bool NoRestore { get; init; }

[BooleanCommandSwitch("verify-no-changes")]
public bool VerifyNoChanges { get; init; } = true;

[CommandLongSwitch("include", SwitchValueSeparator = " ")]
public string Include { get; init; }

[CommandLongSwitch("exclude", SwitchValueSeparator = " ")]
public string Exclude { get; init; }

[BooleanCommandSwitch("include-generated")]
public bool IncludeGenerated { get; init; }

[CommandLongSwitch("binary-log", SwitchValueSeparator = " ")]
public string BinaryLogPath { get; init; }

[CommandLongSwitch("report", SwitchValueSeparator = " ")]
public string ReportPath { get; init; }
}
Loading