Skip to content

Commit

Permalink
build: update build script
Browse files Browse the repository at this point in the history
  • Loading branch information
WeihanLi committed Jan 4, 2024
1 parent 2c99cf2 commit 386c6d2
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions build/build.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Copyright (c) 2022-2023 Weihan Li. All rights reserved.
// Licensed under the Apache license version 2.0 http://www.apache.org/licenses/LICENSE-2.0

// r: "nuget: CliWrap, 3.6.4"

using CliWrap;
using Newtonsoft.Json;

//
Expand Down Expand Up @@ -109,7 +106,7 @@ await BuildProcess.CreateBuilder()
// push nuget packages
foreach (var file in Directory.GetFiles("./artifacts/packages/", "*.nupkg"))
{
await ExecuteCommandAsync($"dotnet nuget push {file} -k {apiKey} --skip-duplicate");
await ExecuteCommandAsync($"dotnet nuget push {file} -k {apiKey} --skip-duplicate", [new("$NuGet__ApiKey", apiKey)]);
}
}))
.WithTask("Default", b => b.WithDependency("hello").WithDependency("pack"))
Expand Down Expand Up @@ -152,18 +149,21 @@ bool ArgumentBool(string argumentName, bool defaultValue = default)
return null;
}

async Task ExecuteCommandAsync(string commandText)
async Task ExecuteCommandAsync(string commandText, KeyValuePair<string, string>[]? replacements = null)
{
Console.WriteLine($"Executing command: \n {commandText}");
var commandTextWithReplacements = commandText;
if (replacements is { Length: > 0})
{
foreach (var item in replacements)
{
commandTextWithReplacements = commandTextWithReplacements.Replace(item.Value, item.Key);
}
}
Console.WriteLine($"Executing command: \n {commandTextWithReplacements}");
Console.WriteLine();
var splits = commandText.Split([' '], 2);
var result = await Cli.Wrap(splits[0])
.WithArguments(splits.Length > 1 ? splits[1] : string.Empty)
.WithStandardErrorPipe(PipeTarget.ToStream(Console.OpenStandardError()))
.WithStandardOutputPipe(PipeTarget.ToStream(Console.OpenStandardOutput()))
.ExecuteAsync();
var result = await CommandExecutor.ExecuteAndOutput(commandText);
result.EnsureSuccessExitCode();
Console.WriteLine();
Console.WriteLine($"ExitCode: {result.ExitCode} ElapsedTime: {result.RunTime}");
}

file sealed class BuildProcess
Expand Down

0 comments on commit 386c6d2

Please sign in to comment.