forked from hsu-net/NullModemEmulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuild.cs
173 lines (150 loc) · 5.69 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
using Nuke.Common;
using Nuke.Common.CI;
using Nuke.Common.CI.AzurePipelines;
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Tools.MSBuild;
using Nuke.Common.Utilities.Collections;
using Serilog;
using System;
using System.Linq;
using static Nuke.Common.IO.FileSystemTasks;
using static Nuke.Common.IO.PathConstruction;
using static Nuke.Common.Tools.DotNet.DotNetTasks;
using static Nuke.Common.Tools.MSBuild.MSBuildTasks;
[ShutdownDotNetAfterServerBuild]
internal partial 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
public static int Main() => Execute<Build>(x => x.Push);
[Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
private readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;
[Parameter("Api key to push packages to nuget.org.")]
[Secret]
private string NuGetApiKey;
[Parameter("Api key to push packages to myget.org.")]
[Secret]
private string MyGetApiKey;
[Parameter("Github personal access token.")]
[Secret]
private string GitAccessToken;
[CI] private readonly AzurePipelines AzurePipelines;
[Solution] private readonly Solution Solution;
[PathExecutable] private readonly Tool Cmd;
private AbsolutePath SourceDirectory => RootDirectory / "src";
private AbsolutePath OutputDirectory => RootDirectory / "output";
private AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts";
protected override void OnBuildInitialized()
{
base.OnBuildInitialized();
NuGetApiKey ??= Environment.GetEnvironmentVariable(nameof(NuGetApiKey));
MyGetApiKey ??= Environment.GetEnvironmentVariable(nameof(MyGetApiKey));
GitAccessToken ??= Environment.GetEnvironmentVariable(nameof(GitAccessToken));
}
private Target Initial => _ => _
.Description("Initial")
.OnlyWhenStatic(() => IsServerBuild)
.Executes(() =>
{
});
private Target Clean => _ => _
.Description("Clean Solution")
.DependsOn(Initial)
.Executes(() =>
{
SourceDirectory.GlobDirectories("**/bin", "**/obj").ForEach(DeleteDirectory);
EnsureCleanDirectory(OutputDirectory);
EnsureCleanDirectory(ArtifactsDirectory);
});
private Target Restore => _ => _
.Description("Restore Solution")
.DependsOn(Clean)
.Executes(() =>
{
MSBuild(s => s
.SetTargetPath(Solution)
.SetTargets("Restore"));
});
private Target Compile => _ => _
.Description("Compile Solution")
.DependsOn(Restore)
.Executes(() =>
{
MSBuild(s => s
.SetTargetPath(Solution)
.SetTargets("Rebuild")
.SetConfiguration(Configuration)
.SetMaxCpuCount(Environment.ProcessorCount)
.SetNodeReuse(IsLocalBuild));
});
//private Target Pack => _ => _
// .Description("Pack NuGet Package")
// .DependsOn(Compile)
// .Executes(() =>
// {
// MSBuild(s => s
// .SetTargetPath(Solution)
// .SetTargets("Pack")
// .SetConfiguration(Configuration)
// .SetMaxCpuCount(Environment.ProcessorCount)
// .SetNodeReuse(IsLocalBuild));
// });
private Target Copy => _ => _
.Description("Copy NuGet Package")
.OnlyWhenStatic(() => IsServerBuild, () => Configuration.Equals(Configuration.Release))
.DependsOn(Compile)
.Executes(() =>
{
GlobFiles(OutputDirectory, "**/*.nupkg")
?.Where(x => !x.EndsWith(".symbols.nupkg"))
.ForEach(x => CopyFileToDirectory(x, ArtifactsDirectory / "packages", FileExistsPolicy.OverwriteIfNewer));
});
private Target Artifacts => _ => _
.DependsOn(Copy)
.OnlyWhenStatic(() => IsServerBuild)
.Description("Upload Artifacts")
.Executes(() =>
{
//Log.Information("Upload artifacts to azure...");
//AzurePipelines
// .UploadArtifacts("artifacts", "artifacts", ArtifactsDirectory);
//Log.Information("Upload artifacts to azure finished.");
});
private Target Push => _ => _
.Description("Push NuGet Package")
.OnlyWhenStatic(() => IsServerBuild, () => Configuration.Equals(Configuration.Release))
.DependsOn(Copy)
.Requires(() => NuGetApiKey)
.Requires(() => MyGetApiKey)
.Executes(() =>
{
GlobFiles(ArtifactsDirectory / "packages", "**/*.nupkg")
?.Where(x => !x.EndsWith(".symbols.nupkg"))
.ForEach(Nuget);
});
private Target Deploy => _ => _
.Description("Deploy")
.DependsOn(Push, Artifacts)
.Executes(() =>
{
Log.Information("Deployed");
});
private void Nuget(string x)
{
Nuget(x, "https://www.myget.org/F/godsharp/api/v2/package", MyGetApiKey);
Nuget(x, "https://api.nuget.org/v3/index.json", NuGetApiKey);
}
private void Nuget(string x, string source, string key) =>
DotNetNuGetPush(s => s
.SetTargetPath(x)
.SetSource(source)
.SetApiKey(key)
.SetSkipDuplicate(true)
);
}