Skip to content

Commit 16359ed

Browse files
committed
build and push nugets
1 parent dcde4d4 commit 16359ed

File tree

4 files changed

+98
-1
lines changed

4 files changed

+98
-1
lines changed

.build/Build.cs

-1
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,4 @@ partial class Build : NukeBuild
2424

2525
// paths
2626
AbsolutePath OutputDirectory => RootDirectory / ".local" / "builds";
27-
AbsolutePath SharedDirectory => OutputDirectory / "RestApia.Shared";
2827
}

.build/README.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## Common targets
2+
3+
- `.\build.ps1 Clean` - Clean up output directories
4+
5+
## Extensions build
6+
7+
- `.\build.ps1 Extension_Build --ExtensionName RestApia.Extensions.Auth.OAuth2` - build NuGet package for the OAuth2 extension
8+
- optional `--ExtensionLibVersion 1.0.0` to specify the version
9+
- `.\build.ps1 Extension_Push --ExtensionName RestApia.Extensions.Auth.OAuth2` - build the OAuth2 extension and push it to the NuGet server
10+
11+
## Shared library build
12+
13+
- `.\build.ps1 Shared_Build` - build NuGet package for the shared library
14+
- optional `--SharedLibVersion 1.0.0` to specify the version
15+
- `.\build.ps1 Shared_Push` - build the shared library and push it to the NuGet server
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using System;
2+
using System.Diagnostics.CodeAnalysis;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Threading;
6+
using NuGet.Common;
7+
using NuGet.Protocol;
8+
using NuGet.Protocol.Core.Types;
9+
using NuGet.Versioning;
10+
using Nuke.Common;
11+
using Nuke.Common.IO;
12+
using Nuke.Common.Tools.DotNet;
13+
using Serilog;
14+
using static Nuke.Common.Tools.DotNet.DotNetTasks;
15+
16+
[SuppressMessage("ReSharper", "AllUnderscoreLocalParameterName")]
17+
[SuppressMessage("ReSharper", "UnusedMember.Local")]
18+
[SuppressMessage("ReSharper", "CheckNamespace")]
19+
partial class Build
20+
{
21+
[Required]
22+
[Parameter("Extension library name")]
23+
string ExtensionName = EnvironmentInfo.GetVariable<string>("EXTENSION_NAME") ?? string.Empty;
24+
25+
[Parameter("Extension library version")]
26+
string ExtensionLibVersion = EnvironmentInfo.GetVariable<string>("EXTENSION_VERSION") ?? string.Empty;
27+
28+
AbsolutePath ExtensionDirectory => OutputDirectory / ExtensionName;
29+
30+
Target Extension_FindNextVersion => _ => _
31+
.Requires(() => !string.IsNullOrWhiteSpace(ExtensionName))
32+
.OnlyWhenDynamic(() => string.IsNullOrWhiteSpace(ExtensionLibVersion))
33+
.Executes(async () =>
34+
{
35+
var repository = Repository.Factory.GetCoreV3("https://api.nuget.org/v3/index.json");
36+
var resources = await repository.GetResourceAsync<FindPackageByIdResource>();
37+
var metadata = await resources.GetAllVersionsAsync(ExtensionName, new SourceCacheContext(), NullLogger.Instance, CancellationToken.None);
38+
var currentVersion = metadata
39+
.OrderByDescending(x => x)
40+
.FirstOrDefault() ?? new NuGetVersion("0.1.0");
41+
42+
ExtensionLibVersion = currentVersion.Version.Major + "." + currentVersion.Version.Minor + "." + (currentVersion.Version.Build + 1);
43+
Log.Information("Extension library version: {SharedLibVersion}", ExtensionLibVersion);
44+
});
45+
46+
Target Extension_Build => _ => _
47+
.Requires(() => !string.IsNullOrWhiteSpace(ExtensionName))
48+
.DependsOn(Solution_Restore, Extension_FindNextVersion)
49+
.Executes(() =>
50+
{
51+
var project = Solution
52+
.SolutionFolders
53+
.First(x => x.Name.Equals("Extensions", StringComparison.Ordinal))
54+
.Projects
55+
.FirstOrDefault(x => x.Name.Equals(ExtensionName, StringComparison.Ordinal));
56+
57+
if (project == null) throw new FileNotFoundException($"Extension library project '{ExtensionName}' wasn't found.");
58+
59+
DotNetBuild(x => x
60+
.SetProjectFile(project)
61+
.SetConfiguration(Configuration)
62+
.SetVersion(ExtensionLibVersion)
63+
.SetOutputDirectory(ExtensionDirectory));
64+
});
65+
66+
Target Extension_Push => _ => _
67+
.Requires(() => !string.IsNullOrWhiteSpace(ExtensionName))
68+
.DependsOn(Extension_Build)
69+
.Executes(() =>
70+
{
71+
var path = Directory.GetFiles(ExtensionDirectory, "*.nupkg", SearchOption.AllDirectories).FirstOrDefault();
72+
if (string.IsNullOrWhiteSpace(path)) throw new FileNotFoundException("Extension library wasn't found.");
73+
74+
DotNetNuGetPush(x => x
75+
.SetTargetPath(path)
76+
.SetSource("https://api.nuget.org/v3/index.json")
77+
.SetApiKey(PushApiKey));
78+
});
79+
}

.build/Targets/Shared_Targets.cs

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using NuGet.Protocol.Core.Types;
99
using NuGet.Versioning;
1010
using Nuke.Common;
11+
using Nuke.Common.IO;
1112
using Nuke.Common.Tools.DotNet;
1213
using Serilog;
1314
using static Nuke.Common.Tools.DotNet.DotNetTasks;
@@ -17,9 +18,12 @@
1718
[SuppressMessage("ReSharper", "UnusedMember.Local")]
1819
partial class Build
1920
{
21+
AbsolutePath SharedDirectory => OutputDirectory / "RestApia.Shared";
22+
2023
[Parameter("Shared library version")]
2124
string SharedLibVersion = EnvironmentInfo.GetVariable<string>("SHARED_LIB_VERSION") ?? string.Empty;
2225

26+
[Parameter("NuGet push API key")]
2327
string PushApiKey => EnvironmentInfo.GetVariable<string>("NUGET_API") ?? Settings.Value<string>("nuget_push_api_key");
2428

2529
Target Shared_FindNextVersion => _ => _

0 commit comments

Comments
 (0)