forked from signalfx/splunk-otel-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuild.cs
177 lines (153 loc) · 6.42 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
using Nuke.Common;
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Tools.MSBuild;
using System;
using System.IO;
using System.IO.Compression;
using static Nuke.Common.Tools.DotNet.DotNetTasks;
class Build : NukeBuild
{
[Solution("Splunk.OpenTelemetry.AutoInstrumentation.sln")] readonly Solution Solution;
public static int Main() => Execute<Build>(x => x.Workflow);
[Parameter("Configuration to build - Default is 'Release'")]
readonly Configuration Configuration = Configuration.Release;
[Parameter("Platform to build - x86 or x64. Default is 'x64'")]
readonly MSBuildTargetPlatform Platform = MSBuildTargetPlatform.x64;
const string OpenTelemetryAutoInstrumentationDefaultVersion = "v0.5.1-beta.2";
[Parameter($"OpenTelemetry AutoInstrumentation dependency version - Default is '{OpenTelemetryAutoInstrumentationDefaultVersion}'")]
readonly string OpenTelemetryAutoInstrumentationVersion = OpenTelemetryAutoInstrumentationDefaultVersion;
readonly AbsolutePath OpenTelemetryDistributionFolder = RootDirectory / "OpenTelemetryDistribution";
Target Clean => _ => _
.Executes(() =>
{
DotNetClean();
FileSystemTasks.DeleteDirectory(OpenTelemetryDistributionFolder);
FileSystemTasks.DeleteDirectory(RootDirectory / GetOTelAutoInstrumentationFileName());
});
Target Restore => _ => _
.After(Clean)
.Executes(() =>
{
DotNetRestore();
});
Target DownloadAutoInstrumentationDistribution => _ => _
.Executes(async () =>
{
var fileName = GetOTelAutoInstrumentationFileName();
var uri =
$"https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/releases/download/{OpenTelemetryAutoInstrumentationVersion}/{fileName}";
await HttpTasks.HttpDownloadFileAsync(uri, RootDirectory / fileName, clientConfigurator: httpClient =>
{
httpClient.Timeout = TimeSpan.FromMinutes(3);
return httpClient;
});
});
Target UnpackAutoInstrumentationDistribution => _ => _
.After(DownloadAutoInstrumentationDistribution)
.After(Clean)
.Executes(() =>
{
var fileName = GetOTelAutoInstrumentationFileName();
FileSystemTasks.DeleteDirectory(OpenTelemetryDistributionFolder);
CompressionTasks.UncompressZip(fileName, OpenTelemetryDistributionFolder);
FileSystemTasks.DeleteFile(RootDirectory / fileName);
});
static string GetOTelAutoInstrumentationFileName()
{
string fileName;
switch (EnvironmentInfo.Platform)
{
case PlatformFamily.Windows:
fileName = "opentelemetry-dotnet-instrumentation-windows.zip";
break;
case PlatformFamily.Linux:
fileName = Environment.GetEnvironmentVariable("IsAlpine") == "true"
? "opentelemetry-dotnet-instrumentation-linux-musl.zip"
: "opentelemetry-dotnet-instrumentation-linux-glibc.zip";
break;
case PlatformFamily.OSX:
fileName = "opentelemetry-dotnet-instrumentation-macos.zip";
break;
case PlatformFamily.Unknown:
throw new NotSupportedException();
default:
throw new ArgumentOutOfRangeException();
}
return fileName;
}
Target AddSplunkPlugins => _ => _
.After(Compile)
.Executes(() =>
{
FileSystemTasks.CopyFileToDirectory(
RootDirectory / "src" / "Splunk.OpenTelemetry.AutoInstrumentation" / "bin" / Configuration /
"net6.0" / "Splunk.OpenTelemetry.AutoInstrumentation.dll",
OpenTelemetryDistributionFolder / "net");
if (EnvironmentInfo.IsWin)
{
FileSystemTasks.CopyFileToDirectory(
RootDirectory / "src" / "Splunk.OpenTelemetry.AutoInstrumentation" / "bin" / Configuration /
"net462" / "Splunk.OpenTelemetry.AutoInstrumentation.dll",
OpenTelemetryDistributionFolder / "netfx");
}
});
Target CopyInstrumentScripts => _ => _
.After(AddSplunkPlugins)
.Executes(() =>
{
var source = RootDirectory / "instrument.sh";
var dest = OpenTelemetryDistributionFolder;
FileSystemTasks.CopyFileToDirectory(source, dest, FileExistsPolicy.Overwrite);
});
Target PackSplunkDistribution => _ => _
.After(CopyInstrumentScripts)
.Executes(() =>
{
var fileName = GetOTelAutoInstrumentationFileName();
CompressionTasks.CompressZip(OpenTelemetryDistributionFolder, RootDirectory / "bin" / ("splunk-" + fileName), compressionLevel: CompressionLevel.SmallestSize, fileMode: FileMode.Create);
});
Target Compile => _ => _
.After(Restore)
.After(UnpackAutoInstrumentationDistribution)
.Executes(() =>
{
DotNetBuild(s => s
.SetNoRestore(true)
.SetConfiguration(Configuration)
.SetPlatform(Platform));
});
Target RunUnitTests => _ => _
.After(Compile)
.Executes(() =>
{
var project = Solution.GetProject("Splunk.OpenTelemetry.AutoInstrumentation.Tests");
DotNetTest(s => s
.SetNoBuild(true)
.SetProjectFile(project)
.SetConfiguration(Configuration));
});
Target RunIntegrationTests => _ => _
.After(Compile)
.After(AddSplunkPlugins)
.Executes(() =>
{
var project = Solution.GetProject("Splunk.OpenTelemetry.AutoInstrumentation.IntegrationTests");
DotNetTest(s => s
.SetNoBuild(true)
.SetProjectFile(project)
.SetConfiguration(Configuration));
});
Target Workflow => _ => _
.DependsOn(Clean)
.DependsOn(Restore)
.DependsOn(DownloadAutoInstrumentationDistribution)
.DependsOn(UnpackAutoInstrumentationDistribution)
.DependsOn(Compile)
.DependsOn(AddSplunkPlugins)
.DependsOn(CopyInstrumentScripts)
.DependsOn(RunUnitTests)
.DependsOn(RunIntegrationTests)
.DependsOn(PackSplunkDistribution);
}