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
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ updates:
nuget-deps:
patterns:
- "*"
open-pull-requests-limit: 10
schedule:
interval:
daily
open-pull-requests-limit: 10
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace DecSm.Atom.Module.GithubWorkflows.Tests.Workflows;

[BuildDefinition]
public partial class DependabotBuild : MinimalBuildDefinition, IGithubWorkflows
{
public override IReadOnlyList<WorkflowDefinition> Workflows =>
[
Github.DependabotWorkflow(new()
{
Registries = [new("registry-1", "type1", "url1", "token1"), new("registry-2", "type2", "url2", "token2")],
Updates =
[
new("update-1", "package-ecosystem-1", "directory-1", 1, DependabotSchedule.Daily)
{
Registries = ["registry-1", "registry-2"],
Groups =
[
new("group-1")
{
Patterns = ["pattern-1", "pattern-2"],
},
],
},
new("update-2", "package-ecosystem-2", "directory-2", 2, DependabotSchedule.Monthly),
],
}),
];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: 2

registries:
registry-1:
type: type1
url: url1
token: ${{token1}}
registry-2:
type: type2
url: url2
token: ${{token2}}

updates:
- package-ecosystem: "update-1"
target-branch: "package-ecosystem-1"
directory: "directory-1"
registries:
- registry-1
- registry-2
groups:
group-1:
patterns:
- "pattern-1"
- "pattern-2"
schedule:
interval:
daily
open-pull-requests-limit: 1
- package-ecosystem: "update-2"
target-branch: "package-ecosystem-2"
directory: "directory-2"
schedule:
interval:
monthly
open-pull-requests-limit: 2
29 changes: 29 additions & 0 deletions DecSm.Atom.Module.GithubWorkflows.Tests/Workflows/WorkflowTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ Environment.OSVersion.Platform is PlatformID.Win32NT
? @"C:\Atom\.github\workflows\"
: "/Atom/.github/workflows/";

private static string DependabotDir =>
Environment.OSVersion.Platform is PlatformID.Win32NT
? @"C:\Atom\.github\"
: "/Atom/.github/";

[Test]
public void MinimalBuild_GeneratesNoWorkflows()
{
Expand Down Expand Up @@ -436,4 +441,28 @@ public async Task GithubCustomStepBuild_GeneratesWorkflow()
await Verify(workflow);
await TestContext.Out.WriteAsync(workflow);
}

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

var build = CreateTestHost<DependabotBuild>(fileSystem: fileSystem, commandLineArgs: new(true, [new GenArg()]));

// Act
await build.RunAsync();

// Assert
fileSystem
.DirectoryInfo
.New(DependabotDir)
.Exists
.ShouldBeTrue();

var workflow = await fileSystem.File.ReadAllTextAsync($"{DependabotDir}dependabot.yml");

await Verify(workflow);
await TestContext.Out.WriteAsync(workflow);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,51 +20,61 @@ protected override void WriteWorkflow(WorkflowModel workflow)

WriteLine("version: 2");

if (dependabot.Registries.Count == 0)
return;
if (dependabot.Registries.Count > 0)
{
WriteLine();

WriteLine();
using (WriteSection("registries:"))
{
foreach (var registry in dependabot.Registries)
using (WriteSection($"{registry.Name}:"))
{
WriteLine($"type: {registry.Type}");
WriteLine($"url: {registry.Url}");

using (WriteSection("registries:"))
{
foreach (var registry in dependabot.Registries)
using (WriteSection($"{registry.Name}:"))
{
WriteLine("type: nuget-feed");
WriteLine($"url: {registry.Url}");

if (registry.Token is not null)
WriteLine($"token: ${{{{{registry.Token}}}}}");
}
if (registry.Token is not null)
WriteLine($"token: ${{{{{registry.Token}}}}}");
}
}
}

WriteLine();

using (WriteSection("updates:"))
if (dependabot.Updates.Count > 0)
{
foreach (var update in dependabot.Updates)
using (WriteSection("- package-ecosystem: \"nuget\""))
{
WriteLine($"target-branch: \"{update.TargetBranch}\"");
WriteLine("directory: \"/\"");
WriteLine();

if (dependabot.Registries.Count != 0)
using (WriteSection("updates:"))
{
foreach (var update in dependabot.Updates)
using (WriteSection($"- package-ecosystem: \"{update.Ecosystem}\""))
{
WriteLine("registries:");

foreach (var registry in dependabot.Registries)
WriteLine($" - {registry.Name}");
}

using (WriteSection("groups:"))
using (WriteSection("nuget-deps:"))
using (WriteSection("patterns:"))
WriteLine("- \"*\"");
WriteLine($"target-branch: \"{update.TargetBranch}\"");
WriteLine($"directory: \"{update.Directory}\"");

WriteLine($"open-pull-requests-limit: {update.OpenPullRequestsLimit}");
if (update.Registries.Count > 0)
using (WriteSection("registries:"))
{
foreach (var registry in update.Registries)
WriteLine($"- {registry}");
}

using (WriteSection("schedule:"))
{
if (update.Groups.Count > 0)
using (WriteSection("groups:"))
{
foreach (var group in update.Groups)
using (WriteSection($"{group.Name}:"))
{
if (group.Patterns is not { Count: > 0 })
continue;

using (WriteSection("patterns:"))
{
foreach (var pattern in group.Patterns)
WriteLine($"- \"{pattern}\"");
}
}
}

using (WriteSection("schedule:"))
using (WriteSection("interval:"))
{
WriteLine(update.Schedule switch
Expand All @@ -77,8 +87,10 @@ protected override void WriteWorkflow(WorkflowModel workflow)
$"Dependabot schedule '{update.Schedule}' is not supported."),
});
}

WriteLine($"open-pull-requests-limit: {update.OpenPullRequestsLimit}");
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public sealed record DependabotUpdate(
DependabotSchedule Schedule = DependabotSchedule.Weekly
)
{
public required IReadOnlyCollection<string> Registries { get; init; } = [];
public IReadOnlyCollection<string> Registries { get; init; } = [];

public IReadOnlyCollection<DependabotUpdateGroup> Groups { get; init; } = [];
}
Expand Down
Loading