Integrate some GitLab metadata

This commit is contained in:
Peter 2021-02-22 13:54:22 +01:00
parent bb7dafcb7c
commit 732515e0cc
Signed by: prskr
GPG key ID: C1DB5D2E8DB512F9

View file

@ -1,7 +1,9 @@
using System; using System;
using System.Linq; using System.Linq;
using JetBrains.Annotations;
using Nuke.Common; using Nuke.Common;
using Nuke.Common.CI; using Nuke.Common.CI;
using Nuke.Common.CI.GitLab;
using Nuke.Common.Execution; using Nuke.Common.Execution;
using Nuke.Common.Git; using Nuke.Common.Git;
using Nuke.Common.IO; using Nuke.Common.IO;
@ -22,7 +24,6 @@ class Build : NukeBuild
/// - JetBrains Rider https://nuke.build/rider /// - JetBrains Rider https://nuke.build/rider
/// - Microsoft VisualStudio https://nuke.build/visualstudio /// - Microsoft VisualStudio https://nuke.build/visualstudio
/// - Microsoft VSCode https://nuke.build/vscode /// - 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)")]
@ -32,9 +33,29 @@ class Build : NukeBuild
[GitRepository] readonly GitRepository GitRepository; [GitRepository] readonly GitRepository GitRepository;
[GitVersion(NoFetch = true, Framework = "net5.0")] readonly GitVersion GitVersion; [GitVersion(NoFetch = true, Framework = "net5.0")] readonly GitVersion GitVersion;
[CanBeNull]
GitLab CI => GitLab.Instance;
AbsolutePath SourceDirectory => RootDirectory / "src"; AbsolutePath SourceDirectory => RootDirectory / "src";
AbsolutePath TestsDirectory => RootDirectory / "tests"; AbsolutePath TestsDirectory => RootDirectory / "tests";
AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts"; AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts";
Target PrintEnv => _ => _
.Executes(() =>
{
if (CI == null)
{
Logger.Info("Running in local environment");
Logger.Info($"Git commit: {GitRepository.Commit}");
}
else
{
Logger.Info("Running in GitLab CI");
Logger.Info($"Git commit: {CI.CommitSha}");
Logger.Info($"Pipeline ID: {CI.PipelineId}");
}
});
Target Clean => _ => _ Target Clean => _ => _
.Before(Restore) .Before(Restore)
@ -53,7 +74,7 @@ class Build : NukeBuild
}); });
Target Compile => _ => _ Target Compile => _ => _
.DependsOn(Restore) .DependsOn(Restore, PrintEnv)
.Executes(() => .Executes(() =>
{ {
DotNetBuild(s => s DotNetBuild(s => s