|
1 | | -var target = CommandLineParser.Val("target", args, "Default"); |
2 | | -var apiKey = CommandLineParser.Val("apiKey", args); |
3 | | -var stable = CommandLineParser.BooleanVal("stable", args); |
4 | | -var noPush = CommandLineParser.BooleanVal("noPush", args); |
5 | | -var branchName = EnvHelper.Val("BUILD_SOURCEBRANCHNAME", "local"); |
6 | | - |
7 | 1 | var solutionPath = "./WeihanLi.EntityFramework.slnx"; |
8 | 2 | string[] srcProjects = [ |
9 | 3 | "./src/WeihanLi.EntityFramework/WeihanLi.EntityFramework.csproj" |
10 | 4 | ]; |
11 | 5 | string[] testProjects = [ "./test/WeihanLi.EntityFramework.Test/WeihanLi.EntityFramework.Test.csproj" ]; |
12 | 6 |
|
13 | | -await new BuildProcessBuilder() |
14 | | - .WithSetup(() => |
15 | | - { |
16 | | - // cleanup artifacts |
17 | | - if (Directory.Exists("./artifacts/packages")) |
18 | | - Directory.Delete("./artifacts/packages", true); |
19 | | - |
20 | | - // args |
21 | | - Console.WriteLine("Arguments"); |
22 | | - Console.WriteLine($" {args.StringJoin(" ")}"); |
23 | | - }) |
24 | | - .WithTaskExecuting(task => Console.WriteLine($@"===== Task {task.Name} {task.Description} executing ======")) |
25 | | - .WithTaskExecuted(task => Console.WriteLine($@"===== Task {task.Name} {task.Description} executed ======")) |
26 | | - .WithTask("hello", b => b.WithExecution(() => Console.WriteLine("Hello dotnet-exec build"))) |
27 | | - .WithTask("build", b => |
28 | | - { |
29 | | - b.WithDescription("dotnet build") |
30 | | - .WithExecution(() => ExecuteCommandAsync($"dotnet build {solutionPath}")) |
31 | | - ; |
32 | | - }) |
33 | | - .WithTask("test", b => |
| 7 | +await DotNetPackageBuildProcess |
| 8 | + .Create(options => |
34 | 9 | { |
35 | | - b.WithDescription("dotnet test") |
36 | | - .WithDependency("build") |
37 | | - .WithExecution(async () => |
38 | | - { |
39 | | - foreach (var project in testProjects) |
40 | | - { |
41 | | - await ExecuteCommandAsync($"dotnet test --collect:\"XPlat Code Coverage;Format=cobertura,opencover;ExcludeByAttribute=ExcludeFromCodeCoverage,Obsolete,GeneratedCode,CompilerGeneratedAttribute\" {project}"); |
42 | | - } |
43 | | - }) |
44 | | - ; |
| 10 | + options.SolutionPath = solutionPath; |
| 11 | + options.SrcProjects = srcProjects; |
| 12 | + options.TestProjects = testProjects; |
45 | 13 | }) |
46 | | - .WithTask("pack", b => b.WithDescription("dotnet pack") |
47 | | - .WithDependency("build") |
48 | | - .WithExecution(async () => |
49 | | - { |
50 | | - if (stable || branchName == "master") |
51 | | - { |
52 | | - foreach (var project in srcProjects) |
53 | | - { |
54 | | - await ExecuteCommandAsync($"dotnet pack {project} -o ./artifacts/packages"); |
55 | | - } |
56 | | - } |
57 | | - else |
58 | | - { |
59 | | - var suffix = $"preview-{DateTime.UtcNow:yyyyMMdd-HHmmss}"; |
60 | | - foreach (var project in srcProjects) |
61 | | - { |
62 | | - await ExecuteCommandAsync($"dotnet pack {project} -o ./artifacts/packages --version-suffix {suffix}"); |
63 | | - } |
64 | | - } |
65 | | - |
66 | | - if (noPush) |
67 | | - { |
68 | | - Console.WriteLine("Skip push there's noPush specified"); |
69 | | - return; |
70 | | - } |
71 | | - |
72 | | - if (string.IsNullOrEmpty(apiKey)) |
73 | | - { |
74 | | - // try to get apiKey from environment variable |
75 | | - apiKey = Environment.GetEnvironmentVariable("NuGet__ApiKey"); |
76 | | - |
77 | | - if (string.IsNullOrEmpty(apiKey)) |
78 | | - { |
79 | | - Console.WriteLine("Skip push since there's no apiKey found"); |
80 | | - return; |
81 | | - } |
82 | | - } |
83 | | - |
84 | | - if (branchName != "master" && branchName != "preview") |
85 | | - { |
86 | | - Console.WriteLine($"Skip push since branch name {branchName} not support push packages"); |
87 | | - return; |
88 | | - } |
89 | | - |
90 | | - // push nuget packages |
91 | | - foreach (var file in Directory.GetFiles("./artifacts/packages/", "*.nupkg")) |
92 | | - { |
93 | | - await ExecuteCommandAsync($"dotnet nuget push {file} -k {apiKey} --skip-duplicate", [new("$NuGet__ApiKey", apiKey)]); |
94 | | - } |
95 | | - })) |
96 | | - .WithTask("Default", b => b.WithDependency("hello").WithDependency("pack")) |
97 | | - .Build() |
98 | | - .ExecuteAsync(target, ApplicationHelper.ExitToken); |
99 | | - |
100 | | -async Task ExecuteCommandAsync(string commandText, KeyValuePair<string, string>[]? replacements = null) |
101 | | -{ |
102 | | - var commandTextWithReplacements = commandText; |
103 | | - if (replacements is { Length: > 0}) |
104 | | - { |
105 | | - foreach (var item in replacements) |
106 | | - { |
107 | | - commandTextWithReplacements = commandTextWithReplacements.Replace(item.Value, item.Key); |
108 | | - } |
109 | | - } |
110 | | - Console.WriteLine($"Executing command: \n {commandTextWithReplacements}"); |
111 | | - Console.WriteLine(); |
112 | | - var result = await CommandExecutor.ExecuteCommandAndOutputAsync(commandText); |
113 | | - result.EnsureSuccessExitCode(); |
114 | | - Console.WriteLine(); |
115 | | -} |
| 14 | + .ExecuteAsync(args); |
0 commit comments