Nuke publish artifacts

This commit is contained in:
Peter 2021-02-22 15:10:34 +01:00
parent 732515e0cc
commit c3b1045079
Signed by: prskr
GPG key ID: C1DB5D2E8DB512F9
3 changed files with 31 additions and 11 deletions

1
.gitignore vendored
View file

@ -6,3 +6,4 @@ obj/
INetMock.sln.DotSettings.user INetMock.sln.DotSettings.user
*.log *.log
*.nupkg

View file

@ -19,3 +19,13 @@ protobuf-lint:
- cd api/ - cd api/
- buf ls-files - buf ls-files
- buf lint - buf lint
nuget-publish:
stage: release
only:
refs:
- master
- tags
script:
- dotnet tool restore
- dotnet nuke Publish

View file

@ -1,5 +1,3 @@
using System;
using System.Linq;
using JetBrains.Annotations; using JetBrains.Annotations;
using Nuke.Common; using Nuke.Common;
using Nuke.Common.CI; using Nuke.Common.CI;
@ -19,11 +17,7 @@ using static Nuke.Common.Tools.DotNet.DotNetTasks;
[ShutdownDotNetAfterServerBuild] [ShutdownDotNetAfterServerBuild]
class Build : NukeBuild class Build : NukeBuild
{ {
/// Support plugins are available for: private const string NuGetSourceName = "GitLab";
/// - JetBrains ReSharper https://nuke.build/resharper
/// - JetBrains Rider https://nuke.build/rider
/// - Microsoft VisualStudio https://nuke.build/visualstudio
/// - Microsoft VSCode https://nuke.build/vscode
public static int Main() => Execute<Build>(x => x.Compile); public static int Main() => Execute<Build>(x => x.Compile);
[Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")] [Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
@ -34,8 +28,7 @@ class Build : NukeBuild
[GitVersion(NoFetch = true, Framework = "net5.0")] readonly GitVersion GitVersion; [GitVersion(NoFetch = true, Framework = "net5.0")] readonly GitVersion GitVersion;
[CanBeNull] [CanBeNull] GitLab CI => GitLab.Instance;
GitLab CI => GitLab.Instance;
AbsolutePath SourceDirectory => RootDirectory / "src"; AbsolutePath SourceDirectory => RootDirectory / "src";
AbsolutePath TestsDirectory => RootDirectory / "tests"; AbsolutePath TestsDirectory => RootDirectory / "tests";
@ -95,6 +88,16 @@ class Build : NukeBuild
.EnableNoBuild() .EnableNoBuild()
.EnableProcessLogOutput())); .EnableProcessLogOutput()));
Target AddNugetSource => _ => _
.OnlyWhenStatic(() => GitRepository.IsOnMasterBranch())
.OnlyWhenStatic(() => CI != null)
.Executes(() => DotNetNuGetAddSource(s => s
.SetName(NuGetSourceName)
.SetSource($"https://gitlab.com/api/v4/projects/{CI.ProjectId}/packages/nuget/index.json")
.SetUsername("gitlab-ci-token")
.SetPassword(CI.JobToken)
.EnableStorePasswordInClearText()));
Target Pack => _ => _ Target Pack => _ => _
.DependsOn(Test) .DependsOn(Test)
.OnlyWhenStatic(() => GitRepository.IsOnMasterBranch()) .OnlyWhenStatic(() => GitRepository.IsOnMasterBranch())
@ -111,4 +114,10 @@ class Build : NukeBuild
.EnableNoBuild() .EnableNoBuild()
.EnableProcessLogOutput() .EnableProcessLogOutput()
))); )));
Target Publish => _ => _
.DependsOn(Pack, AddNugetSource)
.Executes(() => DotNetPublish(s => s
.EnableNoRestore()
.SetConfiguration(Configuration)));
} }