diff --git a/.gitignore b/.gitignore index 1fb6416..b6047bc 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ obj/ INetMock.sln.DotSettings.user *.log +*.nupkg diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ffbef48..c00f4e7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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 diff --git a/build/Build.cs b/build/Build.cs index d3278f8..0813964 100644 --- a/build/Build.cs +++ b/build/Build.cs @@ -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(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))); }