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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing" Version="1.1.2" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="5.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageReference Include="System.Formats.Asn1" Version="10.0.0" />
<PackageReference Include="System.Formats.Asn1" Version="10.0.1" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FakeItEasy" Version="8.3.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="10.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="10.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageReference Include="NUnit" Version="4.4.0" />
<PackageReference Include="NUnit3TestAdapter" Version="6.0.0" />
Expand Down
14 changes: 7 additions & 7 deletions DecSm.Atom.Module.DevopsWorkflows/IDevopsWorkflows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ protected static partial void ConfigureBuilder(IHostApplicationBuilder builder)
builder
.Services
.AddSingleton<IOutcomeReportWriter, DevopsSummaryOutcomeReportWriter>()
.ProvidePath((key, locator) => Devops.IsDevopsPipelines
.ProvidePath((key, fileSystem) => Devops.IsDevopsPipelines
? key switch
{
AtomPaths.Artifacts => locator(AtomPaths.Root)
.Parent! /
"a", // Corresponds to $(Build.ArtifactStagingDirectory)
AtomPaths.Publish => locator(AtomPaths.Root)
.Parent! /
"b", // Corresponds to $(Build.BinariesDirectory)
// Corresponds to $(Build.ArtifactStagingDirectory)
AtomPaths.Artifacts => fileSystem.AtomRootDirectory.Parent! / "a",

// Corresponds to $(Build.BinariesDirectory)
AtomPaths.Publish => fileSystem.AtomRootDirectory.Parent! / "b",

_ => null,
}
: null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FakeItEasy" Version="8.3.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="10.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="10.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageReference Include="NUnit" Version="4.4.0" />
<PackageReference Include="NUnit3TestAdapter" Version="5.2.0" />
<PackageReference Include="NUnit3TestAdapter" Version="6.0.0" />
<PackageReference Include="Shouldly" Version="4.3.0" />
<PackageReference Include="Spectre.Console.Testing" Version="0.54.0" />
<PackageReference Include="TestableIO.System.IO.Abstractions.TestingHelpers" Version="22.1.0" />
<PackageReference Include="Verify.NUnit" Version="31.7.3" />
<PackageReference Include="Verify.NUnit" Version="31.8.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
namespace DecSm.Atom.Module.GithubWorkflows.Tests.Workflows;

[BuildDefinition]
public partial class ManualInputStabilityBuild : BuildDefinition, IGithubWorkflows, IManualInputStabilityTarget
{
public override IReadOnlyList<WorkflowDefinition> Workflows =>
[
new("manual-input-stability-workflow")
{
Triggers =
[
new ManualTrigger
{
Inputs =
[
ManualStringInput.ForParam(Params.StringParamWithoutDefault),
ManualStringInput.ForParam(Params.StringParamWithDefault),
ManualBoolInput.ForParam(Params.BoolParamWithoutDefault),
ManualBoolInput.ForParam(Params.BoolParamWithDefault),
ManualChoiceInput.ForParam(Params.ChoiceParamWithoutDefault,
["choice 1", "choice 2", "choice 3"]),
ManualChoiceInput.ForParam(Params.ChoiceParamWithDefault,
["choice 1", "choice 2", "choice 3"]),
],
},
],
Targets = [WorkflowTargets.ManualInputTarget],
WorkflowTypes = [Github.WorkflowType],
},
];
}

[TargetDefinition]
public partial interface IManualInputStabilityTarget
{
[ParamDefinition("string-param-without-default", "String param")]
string StringParamWithoutDefault => GetParam(() => StringParamWithoutDefault)!;

[ParamDefinition("string-param-with-default", "String param")]
string StringParamWithDefault => GetParam(() => StringParamWithDefault, "default-value");

[ParamDefinition("bool-param-without-default", "Bool param")]
bool? BoolParamWithoutDefault => GetParam(() => BoolParamWithoutDefault);

[ParamDefinition("bool-param-with-default", "Bool param")]
bool BoolParamWithDefault => GetParam(() => BoolParamWithDefault, true);

[ParamDefinition("choice-param-without-default", "Choice param")]
string ChoiceParamWithoutDefault => GetParam(() => ChoiceParamWithoutDefault)!;

[ParamDefinition("choice-param-with-default", "Choice param")]
string ChoiceParamWithDefault => GetParam(() => ChoiceParamWithDefault, "choice 1");

Target ManualInputTarget => t => t;
}
65 changes: 65 additions & 0 deletions DecSm.Atom.Module.GithubWorkflows.Tests/Workflows/WorkflowTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,71 @@ public async Task ManualInputBuild_GeneratesWorkflow()
await TestContext.Out.WriteAsync(workflow);
}

[Test]
public async Task ManualInputStabilityBuild_GeneratesWorkflowWithStableInputs()
{
// Arrange
var fileSystem = FileSystemUtils.DefaultMockFileSystem;

var build1 = CreateTestHost<ManualInputStabilityBuild>(fileSystem: fileSystem,
commandLineArgs: new(true,
[
new GenArg(),
new ParamArg("--string-param-without-default",
nameof(IManualInputStabilityTarget.StringParamWithoutDefault),
"1"),
new ParamArg("--string-param-with-default",
nameof(IManualInputStabilityTarget.StringParamWithDefault),
"1"),
new ParamArg("--bool-param-without-default",
nameof(IManualInputStabilityTarget.BoolParamWithoutDefault),
"true"),
new ParamArg("--bool-param-with-default",
nameof(IManualInputStabilityTarget.BoolParamWithDefault),
"true"),
new ParamArg("--choice-param-without-default",
nameof(IManualInputStabilityTarget.ChoiceParamWithoutDefault),
"choice 1"),
new ParamArg("--choice-param-with-default",
nameof(IManualInputStabilityTarget.ChoiceParamWithDefault),
"choice 1"),
]));

var build2 = CreateTestHost<ManualInputStabilityBuild>(fileSystem: fileSystem,
commandLineArgs: new(true,
[
new GenArg(),
new ParamArg("--string-param-without-default",
nameof(IManualInputStabilityTarget.StringParamWithoutDefault),
"2"),
new ParamArg("--string-param-with-default",
nameof(IManualInputStabilityTarget.StringParamWithDefault),
"2"),
new ParamArg("--bool-param-without-default",
nameof(IManualInputStabilityTarget.BoolParamWithoutDefault),
"false"),
new ParamArg("--bool-param-with-default",
nameof(IManualInputStabilityTarget.BoolParamWithDefault),
"false"),
new ParamArg("--choice-param-without-default",
nameof(IManualInputStabilityTarget.ChoiceParamWithoutDefault),
"choice 2"),
new ParamArg("--choice-param-with-default",
nameof(IManualInputStabilityTarget.ChoiceParamWithDefault),
"choice 2"),
]));

// Act
await build1.RunAsync();
var workflow1 = await fileSystem.File.ReadAllTextAsync($"{WorkflowDir}manual-input-stability-workflow.yml");

await build2.RunAsync();
var workflow2 = await fileSystem.File.ReadAllTextAsync($"{WorkflowDir}manual-input-stability-workflow.yml");

// Assert
workflow1.ShouldBe(workflow2);
}

[Test]
public async Task SetupDotnetBuild_GeneratesWorkflow()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ internal sealed class GithubWorkflowWriter(
IAtomFileSystem fileSystem,
IBuildDefinition buildDefinition,
BuildModel buildModel,
IParamService paramService,
ILogger<GithubWorkflowWriter> logger
) : WorkflowFileWriter<GithubWorkflowType>(fileSystem, logger)
{
Expand Down Expand Up @@ -49,7 +50,7 @@ protected override void WriteWorkflow(WorkflowModel workflow)
switch (input)
{
case ManualBoolInput boolInput:

{
bool? defaultBoolValue = null;

if (boolInput.DefaultValue.HasValue)
Expand All @@ -58,14 +59,19 @@ protected override void WriteWorkflow(WorkflowModel workflow)
}
else
{
using var defaultValuesOnlyScope =
paramService.CreateDefaultValuesOnlyScope();

var accessedParam = buildDefinition.AccessParam(inputParamName);

switch (accessedParam)
{
case bool boolParam:
{
defaultBoolValue = boolParam;

break;
}

case string stringParam:
{
Expand All @@ -89,8 +95,12 @@ protected override void WriteWorkflow(WorkflowModel workflow)
WriteLine($"default: {(defaultBoolValue.Value ? "true" : "false")}");

break;
}

case ManualStringInput stringInput:
{
using var defaultValuesOnlyScope =
paramService.CreateDefaultValuesOnlyScope();

var defaultStringValue = stringInput.DefaultValue is { Length: > 0 }
? stringInput.DefaultValue
Expand All @@ -111,8 +121,12 @@ protected override void WriteWorkflow(WorkflowModel workflow)
WriteLine($"default: {defaultStringValue}");

break;
}

case ManualChoiceInput choiceInput:
{
using var defaultValuesOnlyScope =
paramService.CreateDefaultValuesOnlyScope();

var defaultChoiceValue = choiceInput.DefaultValue is { Length: > 0 }
? choiceInput.DefaultValue
Expand All @@ -139,6 +153,7 @@ protected override void WriteWorkflow(WorkflowModel workflow)
WriteLine($"default: {defaultChoiceValue}");

break;
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions DecSm.Atom.Module.GithubWorkflows/IGithubWorkflows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ protected static partial void ConfigureBuilder(IHostApplicationBuilder builder)
builder
.Services
.AddSingleton<IOutcomeReportWriter, GithubSummaryOutcomeReportWriter>()
.ProvidePath((key, locator) => Github.IsGithubActions
.ProvidePath((key, fileSystem) => Github.IsGithubActions
? key switch
{
AtomPaths.Artifacts => locator(AtomPaths.Root) / ".github" / "artifacts",
AtomPaths.Publish => locator(AtomPaths.Root) / ".github" / "publish",
AtomPaths.Artifacts => fileSystem.AtomRootDirectory / ".github" / "artifacts",
AtomPaths.Publish => fileSystem.AtomRootDirectory / ".github" / "publish",
_ => null,
}
: null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="5.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageReference Include="NUnit" Version="4.4.0" />
<PackageReference Include="NUnit3TestAdapter" Version="5.2.0" />
<PackageReference Include="NUnit3TestAdapter" Version="6.0.0" />
<PackageReference Include="Shouldly" Version="4.3.0" />
<PackageReference Include="System.Formats.Asn1" Version="10.0.0" />
<PackageReference Include="Verify.NUnit" Version="31.7.3" />
<PackageReference Include="System.Formats.Asn1" Version="10.0.1" />
<PackageReference Include="Verify.NUnit" Version="31.8.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ private static void GeneratePartial(
/// <summary>
/// {{projectPath}}
/// </summary>
public interface {{validIdentifier}} : IFileMarker
public interface {{validIdentifier}} : IPathLocator
{
public const string Name = @"{{kvp.Key}}";

static RootedPath IFileMarker.Path(IAtomFileSystem fileSystem) =>
static RootedPath IPathLocator.Path(IAtomFileSystem fileSystem) =>
fileSystem.CreateRootedPath(@"{{projectPath}}");

new static RootedPath Path(IAtomFileSystem fileSystem) =>
Expand All @@ -204,11 +204,11 @@ static RootedPath IFileMarker.Path(IAtomFileSystem fileSystem) =>
/// <summary>
/// {{solutionPathNormalized}}
/// </summary>
public interface Solution : IFileMarker
public interface Solution : IPathLocator
{
public const string Name = @"{{solutionName}}";

static RootedPath IFileMarker.Path(IAtomFileSystem fileSystem) =>
static RootedPath IPathLocator.Path(IAtomFileSystem fileSystem) =>
fileSystem.CreateRootedPath(@"{{solutionPathNormalized}}");
}

Expand Down
2 changes: 1 addition & 1 deletion DecSm.Atom.TestUtils/DecSm.Atom.TestUtils.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.1" />
<PackageReference Include="Roslynator.Analyzers" Version="4.14.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
16 changes: 8 additions & 8 deletions DecSm.Atom.Tests/BuildTests/FileSystem/FileSystemTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public void Minimal_BuildDefinition_WithCustomLocator_Locates_AtomRootDirectory(
{
// Arrange
var host = CreateTestHost<MinimalAtomBuild>(configure: builder =>
builder.Services.AddSingleton<IPathProvider>(provider => new PathProvider
builder.Services.AddSingleton<IPathProvider>(provider => new FunctionPathProvider
{
Locator = (key, _) => key is AtomPaths.Root
Resolver = key => key is AtomPaths.Root
? provider
.GetRequiredService<IAtomFileSystem>()
.CreateRootedPath(Environment.OSVersion.Platform is PlatformID.Win32NT
Expand Down Expand Up @@ -73,9 +73,9 @@ public void Minimal_BuildDefinition_WithCustomLocator_Locates_AtomArtifactsDirec
{
// Arrange
var host = CreateTestHost<MinimalAtomBuild>(configure: builder =>
builder.Services.AddSingleton<IPathProvider>(provider => new PathProvider
builder.Services.AddSingleton<IPathProvider>(provider => new FunctionPathProvider
{
Locator = (key, _) => key is AtomPaths.Artifacts
Resolver = key => key is AtomPaths.Artifacts
? provider
.GetRequiredService<IAtomFileSystem>()
.CreateRootedPath(Environment.OSVersion.Platform is PlatformID.Win32NT
Expand Down Expand Up @@ -120,9 +120,9 @@ public void Minimal_BuildDefinition_WithCustomLocator_Locates_AtomPublishDirecto
{
// Arrange
var host = CreateTestHost<MinimalAtomBuild>(configure: builder =>
builder.Services.AddSingleton<IPathProvider>(provider => new PathProvider
builder.Services.AddSingleton<IPathProvider>(provider => new FunctionPathProvider
{
Locator = (key, _) => key is AtomPaths.Publish
Resolver = key => key is AtomPaths.Publish
? provider
.GetRequiredService<IAtomFileSystem>()
.CreateRootedPath(Environment.OSVersion.Platform is PlatformID.Win32NT
Expand Down Expand Up @@ -167,9 +167,9 @@ public void Minimal_BuildDefinition_WithCustomLocator_Locates_AtomTempDirectory(
{
// Arrange
var host = CreateTestHost<MinimalAtomBuild>(configure: builder =>
builder.Services.AddSingleton<IPathProvider>(provider => new PathProvider
builder.Services.AddSingleton<IPathProvider>(provider => new FunctionPathProvider
{
Locator = (key, _) => key is AtomPaths.Temp
Resolver = key => key is AtomPaths.Temp
? provider
.GetRequiredService<IAtomFileSystem>()
.CreateRootedPath(Environment.OSVersion.Platform is PlatformID.Win32NT
Expand Down
Loading