2022-01-27 10:03:21 +00:00
|
|
|
using NuGet.Versioning;
|
2021-02-16 08:36:04 +00:00
|
|
|
using Nuke.Common;
|
|
|
|
using Nuke.Common.CI;
|
2021-02-22 12:54:22 +00:00
|
|
|
using Nuke.Common.CI.GitLab;
|
2021-02-16 08:36:04 +00:00
|
|
|
using Nuke.Common.Execution;
|
|
|
|
using Nuke.Common.Git;
|
|
|
|
using Nuke.Common.IO;
|
|
|
|
using Nuke.Common.ProjectModel;
|
|
|
|
using Nuke.Common.Tooling;
|
|
|
|
using Nuke.Common.Tools.DotNet;
|
|
|
|
using Nuke.Common.Tools.GitVersion;
|
|
|
|
using Nuke.Common.Utilities.Collections;
|
|
|
|
using static Nuke.Common.IO.FileSystemTasks;
|
|
|
|
using static Nuke.Common.Tools.DotNet.DotNetTasks;
|
|
|
|
|
|
|
|
[CheckBuildProjectConfigurations]
|
|
|
|
[ShutdownDotNetAfterServerBuild]
|
|
|
|
class Build : NukeBuild
|
|
|
|
{
|
2021-02-22 14:10:34 +00:00
|
|
|
private const string NuGetSourceName = "GitLab";
|
2022-01-26 14:19:04 +00:00
|
|
|
public static int Main() => Execute<Build>(x => x.Test);
|
2021-02-16 08:36:04 +00:00
|
|
|
|
|
|
|
[Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
|
|
|
|
readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;
|
|
|
|
|
2022-01-27 10:03:21 +00:00
|
|
|
[Solution] readonly Solution? Solution;
|
|
|
|
[GitRepository] readonly GitRepository? GitRepository;
|
2022-09-26 14:41:39 +00:00
|
|
|
[GitVersion(Framework = "net6.0", NoFetch = true)] readonly GitVersion? GitVersion;
|
2021-02-16 08:36:04 +00:00
|
|
|
|
2021-02-22 14:10:34 +00:00
|
|
|
|
2022-01-27 10:03:21 +00:00
|
|
|
GitLab? CI => GitLab.Instance;
|
2021-02-22 12:54:22 +00:00
|
|
|
|
2021-02-16 08:36:04 +00:00
|
|
|
AbsolutePath SourceDirectory => RootDirectory / "src";
|
|
|
|
AbsolutePath TestsDirectory => RootDirectory / "tests";
|
|
|
|
AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts";
|
2021-02-22 14:10:34 +00:00
|
|
|
|
2021-02-16 08:36:04 +00:00
|
|
|
Target Clean => _ => _
|
|
|
|
.Before(Restore)
|
|
|
|
.Executes(() =>
|
|
|
|
{
|
|
|
|
SourceDirectory.GlobDirectories("**/bin", "**/obj").ForEach(DeleteDirectory);
|
|
|
|
TestsDirectory.GlobDirectories("**/bin", "**/obj").ForEach(DeleteDirectory);
|
|
|
|
EnsureCleanDirectory(ArtifactsDirectory);
|
|
|
|
});
|
|
|
|
|
|
|
|
Target Restore => _ => _
|
|
|
|
.Executes(() =>
|
|
|
|
{
|
|
|
|
DotNetRestore(s => s
|
|
|
|
.SetProjectFile(Solution));
|
|
|
|
});
|
|
|
|
|
|
|
|
Target Compile => _ => _
|
2022-01-26 14:19:04 +00:00
|
|
|
.DependsOn(Restore)
|
2021-02-16 08:36:04 +00:00
|
|
|
.Executes(() =>
|
|
|
|
{
|
2022-01-27 10:03:21 +00:00
|
|
|
var assemblyVersion = GitVersion?.AssemblySemVer ??
|
|
|
|
SemanticVersion.Parse(CI?.CommitTag?.TrimStart('v') ?? "0.0.1").ToNormalizedString();
|
|
|
|
var informationalVersion = GitVersion?.InformationalVersion ??
|
|
|
|
SemanticVersion.Parse(CI?.CommitTag?.TrimStart('v') ?? "0.0.1").ToFullString();
|
|
|
|
|
2021-02-16 08:36:04 +00:00
|
|
|
DotNetBuild(s => s
|
|
|
|
.SetProjectFile(Solution)
|
|
|
|
.SetConfiguration(Configuration)
|
2022-01-27 10:03:21 +00:00
|
|
|
.SetAssemblyVersion(assemblyVersion)
|
|
|
|
.SetFileVersion(assemblyVersion)
|
|
|
|
.SetInformationalVersion(informationalVersion)
|
2021-02-16 08:36:04 +00:00
|
|
|
.EnableNoRestore());
|
|
|
|
});
|
|
|
|
|
2022-01-26 14:19:04 +00:00
|
|
|
Target Format => _ => _
|
|
|
|
.DependsOn(Restore)
|
|
|
|
.Executes(() => DotNet(CI == null ? "format --no-restore" : "format --no-restore --verify-no-changes"));
|
2021-02-28 11:40:40 +00:00
|
|
|
|
2021-02-16 08:36:04 +00:00
|
|
|
Target Test => _ => _
|
2022-01-26 14:19:04 +00:00
|
|
|
.DependsOn(Compile, Format)
|
2021-02-16 08:36:04 +00:00
|
|
|
.Executes(() => DotNetTest(s => s
|
|
|
|
.SetProjectFile(Solution)
|
|
|
|
.SetConfiguration(Configuration)
|
|
|
|
.EnableNoRestore()
|
|
|
|
.EnableNoBuild()
|
|
|
|
.EnableProcessLogOutput()));
|
|
|
|
|
|
|
|
Target Pack => _ => _
|
2022-01-26 14:19:04 +00:00
|
|
|
.DependsOn(Compile)
|
2022-01-27 10:03:21 +00:00
|
|
|
.OnlyWhenStatic(() => CI != null && !string.IsNullOrEmpty(CI.CommitTag))
|
2021-02-16 08:36:04 +00:00
|
|
|
.Executes(() => SourceDirectory
|
|
|
|
.GlobFiles("**/*.csproj")
|
|
|
|
.ForEach(csproj => DotNetPack(s => s
|
|
|
|
.SetProject(csproj)
|
|
|
|
.SetConfiguration(Configuration)
|
|
|
|
.SetOutputDirectory(ArtifactsDirectory)
|
2022-09-26 14:41:39 +00:00
|
|
|
.SetVersion(GitVersion?.NuGetVersionV2 ?? SemanticVersion.Parse(CI?.CommitTag?.TrimStart('v') ?? "0.0.1").ToNormalizedString())
|
2021-02-16 08:36:04 +00:00
|
|
|
.EnableIncludeSource()
|
|
|
|
.EnableIncludeSymbols()
|
|
|
|
.EnableNoRestore()
|
|
|
|
.EnableNoBuild()
|
|
|
|
.EnableProcessLogOutput()
|
|
|
|
)));
|
2021-02-22 14:10:34 +00:00
|
|
|
|
2022-01-27 10:03:21 +00:00
|
|
|
Target AddNugetSource => _ => _
|
2022-01-28 06:29:44 +00:00
|
|
|
.OnlyWhenStatic(() => CI != null && !string.IsNullOrEmpty(CI.CommitTag) && !string.IsNullOrEmpty(CI.JobToken))
|
2022-01-27 10:03:21 +00:00
|
|
|
.ProceedAfterFailure()
|
|
|
|
.Executes(() => DotNetNuGetAddSource(s => s
|
|
|
|
.SetName(NuGetSourceName)
|
|
|
|
.SetSource($"https://gitlab.com/api/v4/projects/{CI?.ProjectId}/packages/nuget/index.json")
|
2022-01-28 06:29:44 +00:00
|
|
|
.SetUsername("gitlab-ci-token")
|
|
|
|
.SetPassword(CI!.JobToken)
|
2022-01-27 10:03:21 +00:00
|
|
|
.EnableStorePasswordInClearText()));
|
|
|
|
|
2021-02-22 15:26:04 +00:00
|
|
|
Target NuGetPush => _ => _
|
2021-02-22 14:10:34 +00:00
|
|
|
.DependsOn(Pack, AddNugetSource)
|
2022-01-27 10:03:21 +00:00
|
|
|
.OnlyWhenStatic(() => CI != null && !string.IsNullOrEmpty(CI.CommitTag))
|
2021-02-22 15:26:04 +00:00
|
|
|
.Executes(() => ArtifactsDirectory
|
|
|
|
.GlobFiles("**/*.nupkg")
|
|
|
|
.ForEach(nupkg => DotNetNuGetPush(s => s
|
|
|
|
.SetSource(NuGetSourceName)
|
|
|
|
.SetTargetPath(nupkg)
|
|
|
|
.EnableProcessLogOutput())));
|
2021-02-16 08:36:04 +00:00
|
|
|
}
|