-
Notifications
You must be signed in to change notification settings - Fork 364
/
Build.cs
192 lines (160 loc) Β· 7.59 KB
/
Build.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// Copyright 2023 Maintainers of NUKE.
// Distributed under the MIT License.
// https://github.com/nuke-build/nuke/blob/master/LICENSE
using System;
using System.Collections.Generic;
using System.Linq;
using NuGet.Packaging;
using Nuke.Common;
using Nuke.Common.CI;
using Nuke.Common.CI.AppVeyor;
using Nuke.Common.CI.AzurePipelines;
using Nuke.Common.CI.GitHubActions;
using Nuke.Common.CI.TeamCity;
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.Components;
using static Nuke.Common.ControlFlow;
using static Nuke.Common.Tools.DotNet.DotNetTasks;
using static Nuke.Common.Tools.ReSharper.ReSharperTasks;
[DotNetVerbosityMapping]
[ShutdownDotNetAfterServerBuild]
partial class Build
: NukeBuild,
IHazTwitterCredentials,
IHazChangelog,
IHazGitRepository,
IHazGitVersion,
IHazSolution,
IRestore,
ICompile,
IPack,
ITest,
IReportCoverage,
IReportIssues,
IReportDuplicates,
IPublish,
ICreateGitHubRelease
{
/// 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
public static int Main() => Execute<Build>(x => ((IPack)x).Pack);
[CI] readonly TeamCity TeamCity;
[CI] readonly AzurePipelines AzurePipelines;
[CI] readonly AppVeyor AppVeyor;
[CI] readonly GitHubActions GitHubActions;
GitVersion GitVersion => From<IHazGitVersion>().Versioning;
GitRepository GitRepository => From<IHazGitRepository>().GitRepository;
[Solution(GenerateProjects = true)] readonly Solution Solution;
Nuke.Common.ProjectModel.Solution IHazSolution.Solution => Solution;
IHazTwitterCredentials TwitterCredentials => From<IHazTwitterCredentials>();
AbsolutePath OutputDirectory => RootDirectory / "output";
AbsolutePath SourceDirectory => RootDirectory / "source";
const string MasterBranch = "master";
const string DevelopBranch = "develop";
const string ReleaseBranchPrefix = "release";
const string HotfixBranchPrefix = "hotfix";
AbsolutePath IHazArtifacts.ArtifactsDirectory => RootDirectory / "output";
Target Clean => _ => _
.Before<IRestore>()
.Executes(() =>
{
SourceDirectory.GlobDirectories("*/bin", "*/obj").DeleteDirectories();
OutputDirectory.CreateOrCleanDirectory();
});
Configure<DotNetBuildSettings> ICompile.CompileSettings => _ => _
.When(!ScheduledTargets.Contains(((IPublish)this).Publish) && !ScheduledTargets.Contains(Install), _ => _
.ClearProperties());
Configure<DotNetPublishSettings> ICompile.PublishSettings => _ => _
.When(!ScheduledTargets.Contains(((IPublish)this).Publish) && !ScheduledTargets.Contains(Install), _ => _
.ClearProperties());
IEnumerable<(Nuke.Common.ProjectModel.Project Project, string Framework)> ICompile.PublishConfigurations =>
from project in new[] { Solution.Nuke_GlobalTool, Solution.Nuke_MSBuildTasks }
from framework in project.GetTargetFrameworks()
select (project, framework);
IEnumerable<Nuke.Common.ProjectModel.Project> ITest.TestProjects => Partition.GetCurrent(Solution.GetAllProjects("*.Tests"));
[Parameter]
public int TestDegreeOfParallelism { get; } = 1;
Configure<DotNetTestSettings> ITest.TestSettings => _ => _
.SetProcessEnvironmentVariable("NUKE_TELEMETRY_OPTOUT", bool.TrueString);
Target ITest.Test => _ => _
.Inherit<ITest>()
.Partition(2);
bool IReportCoverage.CreateCoverageHtmlReport => true;
bool IReportCoverage.ReportToCodecov => false;
IEnumerable<(string PackageId, string Version)> IReportIssues.InspectCodePlugins
=> new (string PackageId, string Version)[]
{
new("ReSharperPlugin.CognitiveComplexity", ReSharperPluginLatest)
};
bool IReportIssues.InspectCodeFailOnWarning => false;
bool IReportIssues.InspectCodeReportWarnings => true;
IEnumerable<string> IReportIssues.InspectCodeFailOnIssues => new string[0];
IEnumerable<string> IReportIssues.InspectCodeFailOnCategories => new string[0];
Configure<DotNetPackSettings> IPack.PackSettings => _ => _
.When(Host is Terminal or GitHubActions { Workflow: AlphaDeployment }, _ => _
.SetVersion(DefaultDeploymentVersion));
string PublicNuGetSource => "https://api.nuget.org/v3/index.json";
string FeedzNuGetSource => "https://f.feedz.io/nuke/alpha/nuget";
string DefaultDeploymentVersion => "9999.0.0";
[Parameter] [Secret] readonly string PublicNuGetApiKey;
[Parameter] [Secret] readonly string FeedzNuGetApiKey;
bool IsPublicRelease => GitRepository.IsOnMasterBranch() || GitRepository.IsOnReleaseBranch();
string IPublish.NuGetSource => IsPublicRelease ? PublicNuGetSource : FeedzNuGetSource;
string IPublish.NuGetApiKey => IsPublicRelease ? PublicNuGetApiKey : FeedzNuGetApiKey;
Target IPublish.Publish => _ => _
.Inherit<IPublish>()
.Consumes(From<IPack>().Pack)
.Requires(() => IsPublicRelease && Host is AppVeyor || GitRepository.IsOnDevelopBranch() && Host is GitHubActions && GitHubActions.Workflow == AlphaDeployment)
.WhenSkipped(DependencyBehavior.Execute);
IEnumerable<AbsolutePath> NuGetPackageFiles
=> From<IPack>().PackagesDirectory.GlobFiles("*.nupkg");
Target DeletePackages => _ => _
.DependentFor<IPublish>()
.After<IPack>()
.OnlyWhenStatic(() => Host is Terminal or GitHubActions { Workflow: AlphaDeployment })
.Executes(() =>
{
if (Host is Terminal)
{
var packagesDirectory = NuGetPackageResolver.GetPackagesDirectory(packagesConfigFile: BuildProjectFile);
var packageDirectories = packagesDirectory.GlobDirectories($"nuke.*/{DefaultDeploymentVersion}");
packageDirectories.DeleteDirectories();
}
else if (Host is GitHubActions)
{
void DeletePackage(string id, string version)
=> DotNet(
$"nuget delete {id} {version} --source {FeedzNuGetSource} --api-key {FeedzNuGetApiKey} --non-interactive",
logOutput: false);
var packageIds = NuGetPackageFiles.Select(x => new PackageArchiveReader(x).NuspecReader.GetId());
foreach (var packageId in packageIds)
SuppressErrors(() => DeletePackage(packageId, DefaultDeploymentVersion), logWarning: false);
}
});
string ICreateGitHubRelease.Name => MajorMinorPatchVersion;
IEnumerable<AbsolutePath> ICreateGitHubRelease.AssetFiles => NuGetPackageFiles;
Target ICreateGitHubRelease.CreateGitHubRelease => _ => _
.Inherit<ICreateGitHubRelease>()
.TriggeredBy<IPublish>()
.ProceedAfterFailure()
.OnlyWhenStatic(() => GitRepository.IsOnMasterBranch());
Target Install => _ => _
.DependsOn<IPack>()
.Executes(() =>
{
SuppressErrors(() => DotNet($"tool uninstall -g {Solution.Nuke_GlobalTool.Name}"));
DotNet($"tool install -g {Solution.Nuke_GlobalTool.Name} --add-source {OutputDirectory} --version {DefaultDeploymentVersion}");
});
T From<T>()
where T : INukeBuild
=> (T)(object)this;
}