-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBuild.cs
More file actions
103 lines (88 loc) · 3.81 KB
/
Build.cs
File metadata and controls
103 lines (88 loc) · 3.81 KB
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
using System;
[UnsetVisualStudioEnvironmentVariables]
class Build : NukeBuild
{
[Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")] readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;
[Solution] readonly Solution Solution;
[Parameter("Branch name for OctoVersion to use to calculate the version number. Can be set via the environment variable OCTOVERSION_CurrentBranch.",
Name = "OCTOVERSION_CurrentBranch")]
readonly string BranchName;
[Parameter("Whether to auto-detect the branch name - this is okay for a local build, but should not be used under CI.")] readonly bool AutoDetectBranch = IsLocalBuild;
[OctoVersion(UpdateBuildNumber = true, BranchParameter = nameof(BranchName),
AutoDetectBranchParameter = nameof(AutoDetectBranch), Framework = "net6.0")]
readonly OctoVersionInfo OctoVersionInfo;
AbsolutePath SourceDirectory => RootDirectory / "source";
AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts";
AbsolutePath LocalPackagesDirectory => RootDirectory / ".." / "LocalPackages";
Target Clean => _ => _
.Before(Restore)
.Executes(() =>
{
SourceDirectory.GlobDirectories("**/bin", "**/obj").ForEach(DeleteDirectory);
EnsureCleanDirectory(ArtifactsDirectory);
});
Target Restore => _ => _
.Executes(() =>
{
DotNetRestore(_ => _
.SetProjectFile(Solution));
});
Target CalculateVersion => _ => _
.Executes(() =>
{
//all the magic happens inside `[NukeOctoVersion]` above. we just need a target for TeamCity to call
});
Target Compile => _ => _
.DependsOn(CalculateVersion)
.DependsOn(Clean)
.DependsOn(Restore)
.Executes(() =>
{
Serilog.Log.Information("Building Octopus.Ocl v{0}", OctoVersionInfo.NuGetVersion);
Serilog.Log.Information("Informational Version {0}", OctoVersionInfo.InformationalVersion);
DotNetBuild(_ => _
.SetProjectFile(Solution)
.SetConfiguration(Configuration)
.SetVersion(OctoVersionInfo.FullSemVer)
.SetInformationalVersion(OctoVersionInfo.InformationalVersion)
.EnableNoRestore());
});
Target Test => _ => _
.DependsOn(Compile)
.Executes(() =>
{
DotNetTest(_ => _
.SetProjectFile(Solution)
.SetConfiguration(Configuration)
.SetNoBuild(true)
.EnableNoRestore());
});
Target Pack => _ => _
.DependsOn(CalculateVersion)
.DependsOn(Compile)
.DependsOn(Test)
.Executes(() =>
{
DotNetPack(_ => _
.SetProject(Solution)
.SetConfiguration(Configuration)
.SetOutputDirectory(ArtifactsDirectory)
.SetNoBuild(true)
.AddProperty("Version", OctoVersionInfo.NuGetVersion)
);
});
Target CopyToLocalPackages => _ => _
.OnlyWhenStatic(() => IsLocalBuild)
.TriggeredBy(Pack)
.Executes(() =>
{
EnsureExistingDirectory(LocalPackagesDirectory);
CopyFileToDirectory(ArtifactsDirectory / $"Octopus.Ocl.{OctoVersionInfo.NuGetVersion}.nupkg", LocalPackagesDirectory, FileExistsPolicy.Overwrite);
});
/// 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 => x.Pack);
}