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
*.log
*.nupkg

View file

@ -19,3 +19,13 @@ protobuf-lint:
- cd api/
- buf ls-files
- 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 Nuke.Common;
using Nuke.Common.CI;
@ -19,11 +17,7 @@ using static Nuke.Common.Tools.DotNet.DotNetTasks;
[ShutdownDotNetAfterServerBuild]
class Build : NukeBuild
{
/// Support plugins are available for:
/// - JetBrains ReSharper https://nuke.build/resharper
/// - JetBrains Rider https://nuke.build/rider
/// - Microsoft VisualStudio https://nuke.build/visualstudio
/// - Microsoft VSCode https://nuke.build/vscode
private const string NuGetSourceName = "GitLab";
public static int Main() => Execute<Build>(x => x.Compile);
[Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
@ -33,14 +27,13 @@ class Build : NukeBuild
[GitRepository] readonly GitRepository GitRepository;
[GitVersion(NoFetch = true, Framework = "net5.0")] readonly GitVersion GitVersion;
[CanBeNull]
GitLab CI => GitLab.Instance;
[CanBeNull] GitLab CI => GitLab.Instance;
AbsolutePath SourceDirectory => RootDirectory / "src";
AbsolutePath TestsDirectory => RootDirectory / "tests";
AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts";
Target PrintEnv => _ => _
.Executes(() =>
{
@ -95,6 +88,16 @@ class Build : NukeBuild
.EnableNoBuild()
.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 => _ => _
.DependsOn(Test)
.OnlyWhenStatic(() => GitRepository.IsOnMasterBranch())
@ -111,4 +114,10 @@ class Build : NukeBuild
.EnableNoBuild()
.EnableProcessLogOutput()
)));
Target Publish => _ => _
.DependsOn(Pack, AddNugetSource)
.Executes(() => DotNetPublish(s => s
.EnableNoRestore()
.SetConfiguration(Configuration)));
}