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
5 changes: 2 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
config: [Release]
test_tfm: [net8.0, net9.0]

steps:
Expand All @@ -38,11 +37,11 @@ jobs:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/Directory.Build.targets') }}
restore-keys: |
${{ runner.os }}-nuget-
${{ runner.os }}-nuget

- name: Setup .NET Core SDK
uses: actions/[email protected]

- name: Build
run: dotnet build -c ${{ matrix.config }}
run: bash ./build.sh --target=build
shell: bash
23 changes: 7 additions & 16 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,14 @@ jobs:
8.0.x
9.0.x

- name: Build project
run: dotnet build -c Release

- name: Set Package
if: startsWith(github.ref, 'refs/tags/')
run: |
VERSION_PREFIX=${GITHUB_REF_NAME#v}
echo "VERSION_PREFIX=$VERSION_PREFIX"
dotnet pack ./src/GaussDB/GaussDB.csproj -c Release -o ./artifacts/nupkgs -p VersionPrefix=$VERSION_PREFIX

- name: Set Preview Package
if: github.event_name == 'workflow_dispatch'
run: |
VERSION_SUFFIX=preview-$(date -u +"%Y%m%d%H%M")
echo $VERSION_SUFFIX
dotnet pack ./src/GaussDB/GaussDB.csproj -c Release -o ./artifacts/nupkgs -p VersionSuffix=$VERSION_SUFFIX

- name: Push to nuget.org
VERSION=${GITHUB_REF_NAME#v}
echo "VERSION=$VERSION" >> $GITHUB_ENV

- name: Pack nuget package
run: |
dotnet nuget push "./artifacts/nupkgs/*.nupkg" -s https://api.nuget.org/v3/index.json -k ${{ secrets.NUGET_API_KEY }}
bash ./build.sh
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
120 changes: 120 additions & 0 deletions build.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
var target = CommandLineParser.Val(args, "target", "Default");
var apiKey = CommandLineParser.Val(args, "apiKey");
var noPush = CommandLineParser.BooleanVal(args, "noPush");
var version = Environment.GetEnvironmentVariable("VERSION");
var stable = CommandLineParser.BooleanVal(args, "stable") || !string.IsNullOrEmpty(version);
var runningOnGithubActions = Environment.GetEnvironmentVariable("GITHUB_ACTIONS") == "true";

Console.WriteLine($$"""
Arguments:

target: {{target}}
stable: {{stable}}
noPush: {{noPush}}
args:
{{args.StringJoin("\n")}}

""");

var solutionPath = "./GaussDB.slnx";
string[] srcProjects = [
"./src/GaussDB/GaussDB.csproj"
];
string[] testProjects = [
"./test/GaussDB.Tests/GaussDB.Tests.csproj",
"./test/GaussDB.GaussDB.DependencyInjection.Tests/GaussDB.GaussDB.DependencyInjection.Tests.csproj"
];

await new BuildProcessBuilder()
.WithSetup(() =>
{
// cleanup previous artifacts
if (Directory.Exists("./artifacts/packages"))
Directory.Delete("./artifacts/packages", true);
})
.WithTaskExecuting(task => Console.WriteLine($@"===== Task [{task.Name}] {task.Description} executing ======"))
.WithTaskExecuted(task => Console.WriteLine($@"===== Task [{task.Name}] {task.Description} executed ======"))
.WithTask("build", b =>
{
b.WithDescription("build")
.WithExecution(cancellationToken => ExecuteCommandAsync($"dotnet build {solutionPath}", cancellationToken))
;
})
.WithTask("test", b =>
{
b.WithDescription("dotnet test")
.WithDependency("build")
.WithExecution(async cancellationToken =>
{
foreach (var project in testProjects)
{
var loggerOptions = runningOnGithubActions
? "--logger GitHubActions"
: "--logger \"console;verbosity=d\"";
var command = $"dotnet test --blame --collect:\"XPlat Code Coverage;Format=cobertura,opencover;ExcludeByAttribute=ExcludeFromCodeCoverage,Obsolete,GeneratedCode,CompilerGenerated\" {loggerOptions} -v=d {project}";
await ExecuteCommandAsync(command, cancellationToken);
}
})
;
})
.WithTask("pack", b => b
.WithDescription("dotnet pack")
.WithDependency("build")
.WithExecution(async cancellationToken =>
{
var packOptions = " -o ./artifacts/packages";
if (stable)
{
if (!string.IsNullOrEmpty(version))
{
packOptions += $" -p VersionPrefix={version}";
}
}
else
{
var suffix = $"preview-{DateTime.UtcNow:yyyyMMdd-HHmmss}";
packOptions += $" --version-suffix {suffix}";
}

foreach (var project in srcProjects)
{
await ExecuteCommandAsync($"dotnet pack {project} {packOptions}", cancellationToken);
}

if (noPush)
{
Console.WriteLine("Skip push there's noPush specified");
return;
}

if (string.IsNullOrEmpty(apiKey))
{
// try to get apiKey from environment variable
apiKey = Environment.GetEnvironmentVariable("NUGET_API_KEY");

if (string.IsNullOrEmpty(apiKey))
{
Console.WriteLine("Skip push since there's no apiKey found");
return;
}
}

// push nuget packages
foreach (var file in Directory.GetFiles("./artifacts/packages/", "*.nupkg"))
{
await RetryHelper.TryInvokeAsync(() => ExecuteCommandAsync($"dotnet nuget push {file} -s https://api.nuget.org/v3/index.json -k {apiKey} --skip-duplicate", cancellationToken), cancellationToken: cancellationToken);
}
}))
.WithTask("Default", b => b.WithDependency("pack"))
.Build()
.ExecuteAsync(target, ApplicationHelper.ExitToken);

async Task ExecuteCommandAsync(string commandText, CancellationToken cancellationToken = default)
{
Console.WriteLine($"Executing command: \n {commandText}");
Console.WriteLine();

var result = await CommandExecutor.ExecuteCommandAndOutputAsync(commandText, cancellationToken: cancellationToken);
result.EnsureSuccessExitCode();
Console.WriteLine();
}
5 changes: 5 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dotnet tool update -g dotnet-execute

Write-Host 'dotnet-exec ./build.cs "--args=$ARGS"' -ForegroundColor GREEN

dotnet-exec ./build/build.cs --args $ARGS
7 changes: 7 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

dotnet tool update -g dotnet-execute
export PATH="$PATH:$HOME/.dotnet/tools"

echo "dotnet-exec ./build.cs --args $@"
dotnet-exec ./build.cs --args "$@"