Skip to content

Commit dca590e

Browse files
authored
Merge pull request #38 from WeihanLi/dev
1.10.0
2 parents 576bf86 + 0b0758a commit dca590e

22 files changed

+352
-45
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22
<PropertyGroup>
33
<VersionMajor>1</VersionMajor>
4-
<VersionMinor>9</VersionMinor>
4+
<VersionMinor>10</VersionMinor>
55
<VersionPatch>0</VersionPatch>
66
<VersionPrefix>$(VersionMajor).$(VersionMinor).$(VersionPatch)</VersionPrefix>
77
<VersionSuffix Condition="'$(Configuration)'=='DEBUG'">develop</VersionSuffix>

azure-pipelines.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ steps:
2424
inputs:
2525
packageType: sdk
2626
version: 8.0.x
27-
includePreviewVersions: true
2827

2928
- task: UseDotNet@2
3029
displayName: 'Use .NET 9 sdk'
@@ -39,5 +38,5 @@ steps:
3938
- powershell: ./build.ps1
4039
displayName: 'Powershell Script'
4140
env:
42-
Nuget__ApiKey: $(nugetApiKey)
43-
Nuget__SourceUrl: $(nugetSourceUrl)
41+
NuGet__ApiKey: $(nugetApiKey)
42+
NuGet__SourceUrl: $(nugetSourceUrl)

build.ps1

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
[string]$SCRIPT = './build.cake'
2-
3-
# Set environment variables
4-
[System.Environment]::SetEnvironmentVariable('CI', 'true')
5-
6-
# Install cake.tool
7-
dotnet tool install --global cake.tool
8-
9-
# Start Cake
10-
[string]$CAKE_ARGS = "--verbosity=diagnostic"
1+
[string]$SCRIPT = '.\build\build.cs'
2+
3+
# Install dotnet tool
4+
dotnet tool install --global dotnet-execute
115

12-
Write-Host "dotnet cake $SCRIPT $CAKE_ARGS $ARGS" -ForegroundColor GREEN
6+
Write-Host "dotnet-exec $SCRIPT --args $ARGS" -ForegroundColor GREEN
137

14-
dotnet cake $SCRIPT $CAKE_ARGS $ARGS
8+
dotnet-exec $SCRIPT --args $ARGS

build.sh

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
#!/bin/sh
2-
SCRIPT='./build.cake'
2+
SCRIPT='./build/build.cs'
33

4-
# Install cake.tool
5-
dotnet tool install --global cake.tool
4+
# Install tool
5+
dotnet tool install --global dotnet-execute
66
export PATH="$PATH:$HOME/.dotnet/tools"
77

8-
# Start Cake
9-
CAKE_ARGS="$SCRIPT --verbosity=diagnostic"
8+
echo "dotnet-exec $SCRIPT --args=$@"
109

11-
echo "dotnet cake $CAKE_ARGS $@"
12-
13-
dotnet cake $CAKE_ARGS "$@"
10+
dotnet-exec $SCRIPT --args="$@"

build/build.cs

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
var target = CommandLineParser.Val("target", "Default", args);
2+
var apiKey = CommandLineParser.Val("apiKey", "", args);
3+
var stable = CommandLineParser.Val("stable", null, args).ToBoolean();
4+
var noPush = CommandLineParser.Val("noPush", null, args).ToBoolean();
5+
var branchName = EnvHelper.Val("BUILD_SOURCEBRANCHNAME", "local");
6+
7+
var solutionPath = "./WeihanLi.Web.Extensions.sln";
8+
string[] srcProjects = [
9+
"./src/WeihanLi.Web.Extensions/WeihanLi.Web.Extensions.csproj"
10+
];
11+
string[] testProjects = [ "./test/WeihanLi.Web.Extensions.Test/WeihanLi.Web.Extensions.Test.csproj" ];
12+
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 =>
34+
{
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+
;
45+
})
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+
var source = Environment.GetEnvironmentVariable("NuGet__SourceUrl");
92+
var sourceConfig = string.IsNullOrEmpty(source) ? "" : $"-s {source}";
93+
foreach (var file in Directory.GetFiles("./artifacts/packages/", "*.nupkg"))
94+
{
95+
await ExecuteCommandAsync($"dotnet nuget push {file} -k {apiKey} --skip-duplicate {sourceConfig}", [new("$NuGet__ApiKey", apiKey)]);
96+
}
97+
}))
98+
.WithTask("Default", b => b.WithDependency("hello").WithDependency("pack"))
99+
.Build()
100+
.ExecuteAsync(target, ApplicationHelper.ExitToken);
101+
102+
async Task ExecuteCommandAsync(string commandText, KeyValuePair<string, string>[]? replacements = null)
103+
{
104+
var commandTextWithReplacements = commandText;
105+
if (replacements is { Length: > 0})
106+
{
107+
foreach (var item in replacements)
108+
{
109+
commandTextWithReplacements = commandTextWithReplacements.Replace(item.Value, item.Key);
110+
}
111+
}
112+
Console.WriteLine($"Executing command: \n {commandTextWithReplacements}");
113+
Console.WriteLine();
114+
var result = await CommandExecutor.ExecuteCommandAndOutputAsync(commandText);
115+
result.EnsureSuccessExitCode();
116+
Console.WriteLine();
117+
}

nuget.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
3+
<config>
4+
<add key="defaultPushSource" value="nuget" />
5+
</config>
36
<packageSources>
47
<clear />
58
<add key="nuget" value="https://api.nuget.org/v3/index.json" />

samples/WeihanLi.Web.Extensions.Samples/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@
137137
options.SwaggerEndpoint("/swagger/v1/swagger.json", "v1");
138138
});
139139

140+
app.MapConfigInspector().ShortCircuit();
141+
140142
app.UseAuthentication();
141143
app.UseAuthorization();
142144
app.MapControllers();

samples/WeihanLi.Web.Extensions.Samples/WeihanLi.Web.Extensions.Samples.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
</ItemGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
14+
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
1515
</ItemGroup>
1616
</Project>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"FeatureFlags": {
3+
"ConfigInspector": true
4+
}
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"FeatureFlags": {
3+
"ConfigInspector": false
4+
}
5+
}

0 commit comments

Comments
 (0)