Skip to content

Commit 01559e1

Browse files
authored
feat: update DotNetPackageBuildProcess push branch check
1 parent 60c48c4 commit 01559e1

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

src/WeihanLi.Common/Helpers/BuildProcess.cs

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ public sealed class DotNetPackageBuildProcess
224224
private readonly BuildProcess _buildProcess;
225225
private string? _apiKey, _branch;
226226
private bool _stable, _noPush;
227+
227228
private DotNetPackageBuildProcess(DotNetBuildProcessOptions options)
228229
{
229230
_branch = options.BranchFunc();
@@ -237,15 +238,17 @@ private DotNetPackageBuildProcess(DotNetBuildProcessOptions options)
237238
// args
238239
Console.WriteLine(@"Executing command line:");
239240
Console.WriteLine($@" {Environment.CommandLine}");
241+
Console.WriteLine($"Branch: {_branch}")
240242
})
241243
.WithTaskExecuting(task => Console.WriteLine($@"===== Task {task.Name} {task.Description} executing ======"))
242244
.WithTaskExecuted(task => Console.WriteLine($@"===== Task {task.Name} {task.Description} executed ======"))
243245
.WithTask("build", b =>
244246
{
245-
b.WithDescription("dotnet build").WithExecution(() =>
246-
CommandExecutor.ExecuteCommandAndOutput($"dotnet build {options.SolutionPath}")
247-
.EnsureSuccessExitCode()
248-
);
247+
b.WithDescription("dotnet build")
248+
.WithExecution(() =>
249+
CommandExecutor.ExecuteCommandAndOutput($"dotnet build {options.SolutionPath}")
250+
.EnsureSuccessExitCode()
251+
);
249252
})
250253
.WithTask("test", b =>
251254
{
@@ -266,7 +269,7 @@ private DotNetPackageBuildProcess(DotNetBuildProcessOptions options)
266269
.WithDependency("test")
267270
.WithExecution(() =>
268271
{
269-
if (options.SrcProjects is not { Length: > 0})
272+
if (options.SrcProjects is not { Length: > 0 })
270273
return;
271274

272275
if (_stable)
@@ -275,8 +278,7 @@ private DotNetPackageBuildProcess(DotNetBuildProcessOptions options)
275278
{
276279
CommandExecutor.ExecuteCommandAndOutput(
277280
$"dotnet pack {project} -o {options.ArtifactsPath}"
278-
)
279-
.EnsureSuccessExitCode();
281+
).EnsureSuccessExitCode();
280282
}
281283
}
282284
else
@@ -295,11 +297,23 @@ private DotNetPackageBuildProcess(DotNetBuildProcessOptions options)
295297
Console.WriteLine(@"Skip push there's noPush specified");
296298
return;
297299
}
298-
299-
if (!_stable && _branch != "preview" && (!options.AllowLocalPush && _branch is "local"))
300+
301+
if (_branch == "local")
300302
{
301-
Console.WriteLine($@"Skip push since branch [{_branch}] not supported to push packages");
302-
return;
303+
if (!options.AllowLocalPush)
304+
{
305+
Console.WriteLine($@"Skip push since local branch is not allowed to push packages");
306+
return;
307+
}
308+
}
309+
else
310+
{
311+
// check preview branch
312+
if (!_stable && _branch is "preview")
313+
{
314+
Console.WriteLine($@"Skip push since branch [{_branch}] not supported to push packages");
315+
return;
316+
}
303317
}
304318

305319
if (string.IsNullOrEmpty(_apiKey))
@@ -341,6 +355,11 @@ public async Task ExecuteAsync(string[] args, CancellationToken cancellation = d
341355
_stable = _branch is "main" or "master" ||
342356
_branch?.StartsWith("release/", StringComparison.OrdinalIgnoreCase) == true;
343357
}
358+
else
359+
{
360+
// only specify `stable` locally
361+
_stable = _branch == "local";
362+
}
344363
var target = CommandLineParser.Val(args, "target", "Default");
345364
await _buildProcess.ExecuteAsync(target, cancellation);
346365
}

0 commit comments

Comments
 (0)