-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPackProjectsModule.cs
More file actions
63 lines (56 loc) · 2.22 KB
/
Copy pathPackProjectsModule.cs
File metadata and controls
63 lines (56 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using Microsoft.Extensions.Logging;
using ModularPipelines.Attributes;
using ModularPipelines.Context;
using ModularPipelines.DotNet.Extensions;
using ModularPipelines.DotNet.Options;
using ModularPipelines.Git.Extensions;
using ModularPipelines.Models;
using ModularPipelines.Modules;
using File = ModularPipelines.FileSystem.File;
namespace EnumerableAsyncProcessor.Pipeline.Modules;
[DependsOn<PackageFilesRemovalModule>]
[DependsOn<NugetVersionGeneratorModule>]
[DependsOn<RunUnitTestsModule>]
[DependsOn<BuildBenchmarkProjectsModule>]
[DependsOn<BuildExampleProjectsModule>]
public class PackProjectsModule : Module<List<CommandResult>>
{
protected override async Task<List<CommandResult>?> ExecuteAsync(IModuleContext context, CancellationToken cancellationToken)
{
var results = new List<CommandResult>();
var packageVersion = await context.GetModule<NugetVersionGeneratorModule>();
var projectFiles = context.Git().RootDirectory.GetFiles(f => GetProjectsPredicate(f, context));
foreach (var projectFile in projectFiles)
{
results.Add(await context.DotNet().Pack(new DotNetPackOptions
{
ProjectSolution = projectFile.Path,
Configuration = "Release",
Properties =
[
("PackageVersion", packageVersion.ValueOrDefault)!,
("Version", packageVersion.ValueOrDefault)!
],
IncludeSource = true
}, cancellationToken: cancellationToken));
}
return results;
}
private bool GetProjectsPredicate(File file, IModuleContext context)
{
var path = file.Path;
if (!path.EndsWith(".csproj", StringComparison.OrdinalIgnoreCase))
{
return false;
}
if (path.Contains("Tests", StringComparison.OrdinalIgnoreCase)
|| path.Contains("Benchmarks", StringComparison.OrdinalIgnoreCase)
|| path.Contains("Pipeline", StringComparison.OrdinalIgnoreCase)
|| path.Contains("Example", StringComparison.OrdinalIgnoreCase))
{
return false;
}
context.Logger.LogInformation("Found File: {File}", path);
return true;
}
}