@@ -13,6 +13,7 @@ open Argu
13
13
open BuildInformation
14
14
open CommandLine
15
15
open Octokit
16
+ open Proc.Fs
16
17
17
18
///
18
19
/// This module is hard to read, with so many file manipulations it's kinda hard to avoid.
@@ -49,26 +50,26 @@ let private distroAsset (asset: ReleaseAsset) = fileInfo distroFolder (asset.Nam
49
50
50
51
let pluginFiles tfm =
51
52
[ " dll" ; " pdb" ; " xml" ]
52
- |> List.map( fun e -> $" Elastic.OpenTelemetry.%s {e}" )
53
- |> List.map( fun f -> Path.Combine( " .artifacts" , " bin" , " Elastic.OpenTelemetry" , $" release_%s {tfm}" , " " , f))
53
+ |> List.map( fun e -> $" Elastic.OpenTelemetry.AutoInstrumentation. %s {e}" )
54
+ |> List.map( fun f -> Path.Combine( " .artifacts" , " bin" , " Elastic.OpenTelemetry.AutoInstrumentation " , $" release_%s {tfm}" , " " , f))
54
55
|> List.map( fun f -> FileInfo( f))
55
-
56
56
57
57
/// downloads the artifacts if they don't already exist locally
58
58
let downloadArtifacts ( _ : ParseResults < Build >) =
59
- let client = GitHubClient( ProductHeaderValue( " Elastic.OpenTelemetry" ) )
60
- let token = Environment.GetEnvironmentVariable( " GITHUB_TOKEN" )
59
+ let client = GitHubClient( ProductHeaderValue " Elastic.OpenTelemetry" )
60
+ let token = Environment.GetEnvironmentVariable " GITHUB_TOKEN"
61
61
if not ( String.IsNullOrWhiteSpace( token)) then
62
62
printfn " using GITHUB_TOKEN" ;
63
63
let tokenAuth = Credentials( token);
64
64
client.Credentials <- tokenAuth
65
65
66
66
let assets =
67
67
async {
68
- let! release = client.Repository.Release.Get( " open-telemetry" , " opentelemetry-dotnet-instrumentation" , $" v{otelAutoVersion.AsString}" ) |> Async.AwaitTask;
69
- Console.WriteLine( $" Release %s {release.Name} has %i {release.Assets.Count} assets" );
68
+ let! release = client.Repository.Release.Get( " open-telemetry" ,
69
+ " opentelemetry-dotnet-instrumentation" , $" v{otelAutoVersion.AsString}" ) |> Async.AwaitTask;
70
+ Console.WriteLine $" Release %s {release.Name} has %i {release.Assets.Count} assets" ;
70
71
return release.Assets
71
- |> Seq.map ( fun asset -> ( asset, downloadAsset asset) )
72
+ |> Seq.map ( fun asset -> asset, downloadAsset asset)
72
73
|> Seq.toList
73
74
} |> Async.RunSynchronously
74
75
@@ -78,9 +79,9 @@ let downloadArtifacts (_:ParseResults<Build>) =
78
79
|> Seq.filter ( fun ( _ , f ) -> not f.Exists)
79
80
|> Seq.iter ( fun ( asset , f ) ->
80
81
async {
81
- Console.WriteLine( $" Retrieving {asset.Name}" ) ;
82
- let! fileData = httpClient.GetByteArrayAsync( asset.BrowserDownloadUrl) |> Async.AwaitTask
83
- Console.WriteLine( $" Saving %i {fileData.Length} bytes to {f.FullName}" )
82
+ Console.WriteLine $" Retrieving {asset.Name}" ;
83
+ let! fileData = httpClient.GetByteArrayAsync asset.BrowserDownloadUrl |> Async.AwaitTask
84
+ Console.WriteLine $" Saving %i {fileData.Length} bytes to {f.FullName}"
84
85
File.WriteAllBytes( f.FullName, fileData)
85
86
f.Refresh()
86
87
} |> Async.RunSynchronously
@@ -94,7 +95,7 @@ let injectPluginFiles (asset: ReleaseAsset) (stagedZip: FileInfo) tfm target =
94
95
printfn $" Staging zip: %s {stagedZip.Name}, Adding: %s {f.Name} (%s {tfm}) to %s {target}"
95
96
zipArchive.CreateEntryFromFile( f.FullName, Path.Combine( target, f.Name)) |> ignore
96
97
)
97
-
98
+
98
99
let injectPluginScripts ( stagedZip : FileInfo ) ( otelScript : FileInfo ) ( script : FileInfo ) =
99
100
use zipArchive = ZipFile.Open( stagedZip.FullName, ZipArchiveMode.Update)
100
101
@@ -106,7 +107,7 @@ let injectPluginScripts (stagedZip: FileInfo) (otelScript: FileInfo) (script: Fi
106
107
entry.Delete()
107
108
108
109
zipArchive.CreateEntryFromFile( script.FullName, script.Name) |> ignore
109
-
110
+
110
111
let stageInstrumentationScript ( stagedZips : List < ReleaseAsset * FileInfo >) =
111
112
let openTelemetryVersion = downloadFileInfo " opentelemetry-instrument.sh"
112
113
let stageVersion = downloadFileInfo " _instrument.sh"
@@ -117,7 +118,7 @@ let stageInstrumentationScript (stagedZips:List<ReleaseAsset * FileInfo>) =
117
118
let instrumentShZip =
118
119
stagedZips
119
120
|> List.map( fun ( _ , p ) -> p)
120
- |> List.find ( fun p -> not <| p.Name.EndsWith( " -windows.zip" ) )
121
+ |> List.find ( fun p -> not <| p.Name.EndsWith " -windows.zip" )
121
122
use zipArchive = ZipFile.Open( instrumentShZip.FullName, ZipArchiveMode.Read)
122
123
let shArchive = zipArchive.Entries |> Seq.find( fun e -> e.Name = " instrument.sh" )
123
124
shArchive.ExtractToFile openTelemetryVersion.FullName
@@ -142,12 +143,14 @@ let stageInstallationBashScript () =
142
143
143
144
let elasticInstall = distroFile installScript
144
145
File.WriteAllText( elasticInstall.FullName, contents)
145
- let permissions =
146
- UnixFileMode.UserRead ||| UnixFileMode.UserWrite ||| UnixFileMode.UserExecute
147
- ||| UnixFileMode.GroupRead ||| UnixFileMode.GroupWrite ||| UnixFileMode.GroupExecute
148
- ||| UnixFileMode.OtherRead ||| UnixFileMode.OtherWrite ||| UnixFileMode.OtherExecute
149
- File.SetUnixFileMode( elasticInstall.FullName, permissions);
150
-
146
+
147
+ if not ( OperatingSystem.IsWindows()) then
148
+ let permissions =
149
+ UnixFileMode.UserRead ||| UnixFileMode.UserWrite ||| UnixFileMode.UserExecute
150
+ ||| UnixFileMode.GroupRead ||| UnixFileMode.GroupWrite ||| UnixFileMode.GroupExecute
151
+ ||| UnixFileMode.OtherRead ||| UnixFileMode.OtherWrite ||| UnixFileMode.OtherExecute
152
+ File.SetUnixFileMode( elasticInstall.FullName, permissions);
153
+
151
154
let stageInstallationPsScript () =
152
155
let installScript = downloadFileInfo " OpenTelemetry.DotNet.Auto.psm1"
153
156
let staged = installScript.CopyTo (( stageFile installScript) .FullName, true )
@@ -163,35 +166,34 @@ let stageInstallationPsScript () =
163
166
[
164
167
envMarker
165
168
" #Elastic Distribution"
166
- " \" OTEL_DOTNET_AUTO_PLUGINS\" = \" Elastic.OpenTelemetry.AutoInstrumentationPlugin, Elastic.OpenTelemetry\" "
169
+ " \" OTEL_DOTNET_AUTO_PLUGINS\" = \" Elastic.OpenTelemetry.AutoInstrumentationPlugin, Elastic.OpenTelemetry.AutoInstrumentation \" "
167
170
]
168
171
|> String.concat " \r\n "
169
172
)
170
173
.Replace( " v" + Software.OpenTelemetryAutoInstrumentationVersion.AsString, Software.Version.NormalizeToShorter())
171
174
let elasticInstall = distroFile installScript
172
175
//ensure we write our new module name
173
176
File.WriteAllText( elasticInstall.FullName.Replace( " elastic.DotNet.Auto" , " Elastic.OpenTelemetry.DotNet" ), contents);
174
-
175
-
177
+
176
178
/// moves artifacts from open-distribution to elastic-distribution and renames them to `staged-dotnet-instrumentation*`.
177
179
/// staged meaning we haven't injected our opentelemetry dll into the zip yet,
178
180
let stageArtifacts ( assets : List < ReleaseAsset * FileInfo >) =
179
181
let stagedZips =
180
182
assets
181
- |> List.filter( fun ( a , _ ) -> a.Name.EndsWith( " .zip" ) )
182
- |> List.filter( fun ( a , _ ) -> not <| a.Name.EndsWith( " nuget-packages.zip" ) )
183
+ |> List.filter( fun ( a , _ ) -> a.Name.EndsWith " .zip" )
184
+ |> List.filter( fun ( a , _ ) -> not <| a.Name.EndsWith " nuget-packages.zip" )
183
185
|> List.map( fun ( z , f ) ->
184
186
let stage = stageAsset z
185
187
z, f.CopyTo( stage.FullName, true )
186
188
)
187
189
188
- let ( otelScript , wrapperScript ) = stageInstrumentationScript stagedZips
190
+ let otelScript , wrapperScript = stageInstrumentationScript stagedZips
189
191
printfn $" Staged (%s {wrapperScript.Name}) calling into (%s {otelScript.Name} for repackaging)"
190
192
191
193
stagedZips |> List.iter ( fun ( asset , path ) ->
192
194
193
195
injectPluginFiles asset path " netstandard2.1" " net"
194
- if asset.Name.EndsWith( " -windows.zip" ) then
196
+ if asset.Name.EndsWith " -windows.zip" then
195
197
injectPluginFiles asset path " net462" " netfx"
196
198
197
199
injectPluginScripts path otelScript wrapperScript
@@ -203,20 +205,16 @@ let stageArtifacts (assets:List<ReleaseAsset * FileInfo>) =
203
205
printfn $" Moved staging to: %s {distro.FullName}"
204
206
)
205
207
stagedZips
206
-
207
-
208
-
208
+
209
209
let redistribute ( arguments : ParseResults < Build >) =
210
+ exec { run " dotnet" " build" " src/Elastic.OpenTelemetry.AutoInstrumentation/Elastic.OpenTelemetry.AutoInstrumentation.csproj" " -f" " netstandard2.1" " -c" " release" }
211
+ exec { run " dotnet" " build" " src/Elastic.OpenTelemetry.AutoInstrumentation/Elastic.OpenTelemetry.AutoInstrumentation.csproj" " -f" " net462" " -c" " release" }
210
212
let assets = downloadArtifacts arguments
211
213
printfn " "
212
214
assets |> List.iter ( fun ( asset , path ) ->
213
215
printfn " Asset: %s " asset.Name
214
216
)
215
-
216
217
stageInstallationBashScript()
217
218
stageInstallationPsScript()
218
219
let staged = stageArtifacts assets
219
220
ignore()
220
-
221
-
222
-
0 commit comments