forked from Azure/azure-functions-core-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.fsx
298 lines (263 loc) · 10.4 KB
/
build.fsx
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#r "packages/FAKE/tools/FakeLib.dll"
#r "packages/WindowsAzure.Storage/lib/net40/Microsoft.WindowsAzure.Storage.dll"
#r "Microsoft.VisualBasic"
open System
open System.IO
open System.Net
open System.Threading.Tasks
open Microsoft.VisualBasic.FileIO
open Microsoft.WindowsAzure
open Microsoft.WindowsAzure.Storage
open Microsoft.WindowsAzure.Storage.Blob
open Microsoft.WindowsAzure.Storage.Queue
open Fake
open Fake.AssemblyInfoFile
open Fake.ProcessHelper
open Fake.Testing
type Result<'TSuccess,'TFailure> =
| Success of 'TSuccess
| Failure of 'TFailure
let inline awaitTask (task: Task) =
task
|> Async.AwaitTask
|> Async.RunSynchronously
let MoveFileTo (source, destination) =
if File.Exists destination then
File.Delete destination
File.Move (source, destination)
let env = Environment.GetEnvironmentVariable
let connectionString =
"DefaultEndpointsProtocol=https;AccountName=" + (env "FILES_ACCOUNT_NAME") + ";AccountKey=" + (env "FILES_ACCOUNT_KEY")
let buildDir = "./dist/build/"
let testDir = "./dist/test/"
let downloadDir = "./dist/download/"
let deployDir = "./deploy/"
let packagesDir = "./packages/"
let toolsDir = "./buildtools/"
let sigCheckExe = toolsDir @@ "sigcheck.exe"
let nugetUri = Uri ("https://dist.nuget.org/win-x86-commandline/v3.5.0/nuget.exe")
let version = if isNull appVeyorBuildVersion then "1.0.0.0" else appVeyorBuildVersion
let toSignZipName = version + ".zip"
let toSignThirdPartyName = version + "-thridparty.zip"
let toSignZipPath = deployDir @@ toSignZipName
let toSignThridPartyPath = deployDir @@ toSignThirdPartyName
let signedZipPath = downloadDir @@ ("signed-" + toSignZipName)
let signedThridPartyPath = downloadDir @@ ("signed-" + toSignThirdPartyName)
let finalZipPath = deployDir @@ "Azure.Functions.Cli.zip"
Target "RestorePackages" (fun _ ->
!! "./**/packages.config"
|> Seq.iter (RestorePackage (fun p ->
{p with
Sources =
[
"https://www.nuget.org/api/v2/"
"https://www.myget.org/F/azure-appservice/api/v2"
"https://www.myget.org/F/fusemandistfeed/api/v2"
"https://www.myget.org/F/30de4ee06dd54956a82013fa17a3accb/"
"https://www.myget.org/F/xunit/api/v3/index.json"
]}))
)
Target "Clean" (fun _ ->
if not <| Directory.Exists toolsDir then Directory.CreateDirectory toolsDir |> ignore
CleanDirs [buildDir; testDir; downloadDir; deployDir]
)
Target "SetVersion" (fun _ ->
CreateCSharpAssemblyInfo "./src/Azure.Functions.Cli/Properties/AssemblyInfo.cs"
[Attribute.Title "Azure Functions Cli"
Attribute.Description ""
Attribute.Guid "6608738c-3bdb-47f5-bc62-66a8bdf9d884"
Attribute.Product "Azure.Functions.Cli"
Attribute.Version version
Attribute.FileVersion version
Attribute.InternalsVisibleTo "Azure.Functions.Cli.Tests"
Attribute.InternalsVisibleTo "DynamicProxyGenAssembly2"]
)
Target "Compile" (fun _ ->
!! @"src\**\*.csproj"
|> MSBuildRelease buildDir "Build"
|> Log "AppBuild-Output: "
)
Target "CompileTest" (fun _ ->
!! @"test\**\*.csproj"
|> MSBuildDebug testDir "Build"
|> Log "TestBuild-Output: "
)
Target "XUnitTest" (fun _ ->
!! (testDir + @"\Azure.Functions.Cli.Tests.dll")
|> xUnit2 (fun p ->
{p with
HtmlOutputPath = Some (testDir @@ "result.html")
ToolPath = packagesDir @@ @"xunit.runner.console\tools\net452\xunit.console.exe"
Parallel = NoParallelization
})
)
let excludedFiles = [
"/**/*.pdb"
"/**/*.xml"
"/**/*.resources.dll"
]
Target "Zip" (fun _ ->
!! (buildDir @@ @"/**/*.*")
|> (fun f -> List.fold (--) f excludedFiles)
|> Zip buildDir finalZipPath
)
type SigningInfo =
{ Path: string;
Verified: string;
Date: string;
Publisher: string;
Company: string;
Description: string;
Product: string;
``Product Version``: string;
``File Version``: string;
``Machine Type``: string; }
Target "GenerateZipToSign" (fun _ ->
let sigCheckResult =
ExecProcessAndReturnMessages (fun info ->
info.FileName <- sigCheckExe
info.WorkingDirectory <- Environment.CurrentDirectory
info.Arguments <- "-nobanner -c -accepteula -e " + buildDir
) (TimeSpan.FromMinutes 2.0)
|> fun result ->
result.Messages
|> Seq.skip 1
|> String.concat Environment.NewLine
|> (fun csv ->
use parser = new TextFieldParser (new StringReader (csv))
parser.TextFieldType <- FieldType.Delimited
parser.SetDelimiters [| "," |]
seq {
while (not parser.EndOfData) do
let fields = parser.ReadFields ()
yield { Path = fields.[0]; Verified = fields.[1]; Date = fields.[2];
Publisher = fields.[3]; Company = fields.[4]; Description = fields.[5];
Product = fields.[6]; ``Product Version`` = fields.[7];
``File Version`` = fields.[8]; ``Machine Type`` = fields.[9] }
} |> Array.ofSeq
)
let notSigned (includes: FileIncludes) =
includes
|> Seq.filter (fun f ->
f.EndsWith ".js" ||
sigCheckResult
|> Array.exists (fun i -> i.Path = f && i.Verified = "Unsigned"))
!! (buildDir @@ "/**/Microsoft.Azure.*.dll")
++ (buildDir @@ "func.exe")
++ (buildDir @@ "azurefunctions/functions.js")
++ (buildDir @@ "azurefunctions/http/request.js")
++ (buildDir @@ "azurefunctions/http/response.js")
|> notSigned
|> CreateZip buildDir toSignZipPath String.Empty 7 true
MoveFileTo (buildDir @@ "edge/x64/node.dll", buildDir @@ "node_x64.dll")
MoveFileTo (buildDir @@ "edge/x64/edge_nativeclr.node", buildDir @@ "edge_nativeclr_x64.dll")
MoveFileTo (buildDir @@ "edge/x86/node.dll", buildDir @@ "node_x86.dll")
MoveFileTo (buildDir @@ "edge/x86/edge_nativeclr.node", buildDir @@ "edge_nativeclr_x86.dll")
let thirdParty = [|
"ARMClient.Authentication.dll"
"ARMClient.Library.dll"
"Autofac.dll"
"Autofac.Integration.WebApi.dll"
"Colors.Net.dll"
"EdgeJs.dll"
"FluentCommandLineParser.dll"
"FSharp.Compiler.Service.dll"
"FSharp.Compiler.Service.MSBuild.v12.dll"
"Humanizer.dll"
"Ignite.SharpNetSH.dll"
"NCrontab.dll"
"Newtonsoft.Json.dll"
"RestSharp.dll"
"SendGrid.CSharp.HTTP.Client.dll"
"SendGrid.dll"
"SendGrid.SmtpApi.dll"
"System.IO.Abstractions.dll"
"Twilio.Api.dll"
"node_x64.dll"
"node_x86.dll"
"edge_nativeclr_x64.dll"
"edge_nativeclr_x86.dll"
|]
!! (buildDir @@ "/**/*.dll")
|> Seq.filter (fun f -> thirdParty |> Array.contains (f |> Path.GetFileName))
|> CreateZip buildDir toSignThridPartyPath String.Empty 7 true
)
let storageAccount = CloudStorageAccount.Parse connectionString
let blobClient = storageAccount.CreateCloudBlobClient ()
let queueClient = storageAccount.CreateCloudQueueClient ()
Target "UploadZipToSign" (fun _ ->
let container = blobClient.GetContainerReference "azure-functions-cli"
container.CreateIfNotExists () |> ignore
let blobRef = container.GetBlockBlobReference toSignZipName
blobRef.UploadFromStream <| File.OpenRead toSignZipPath
let blobRef = container.GetBlockBlobReference toSignThirdPartyName
blobRef.UploadFromStream <| File.OpenRead toSignThridPartyPath
)
Target "EnqueueSignMessage" (fun _ ->
let queue = queueClient.GetQueueReference "signing-jobs"
let message = CloudQueueMessage ("SignAuthenticode;azure-functions-cli;" + toSignZipName)
queue.AddMessage message
let message = CloudQueueMessage ("Sign3rdParty;azure-functions-cli;" + toSignThirdPartyName)
queue.AddMessage message
)
Target "WaitForSigning" (fun _ ->
let rec downloadFile fileName (startTime: DateTime) = async {
let container = blobClient.GetContainerReference "azure-functions-cli-signed"
container.CreateIfNotExists () |> ignore
let blob = container.GetBlockBlobReference fileName
if blob.Exists () then
blob.DownloadToFile (signedZipPath, FileMode.OpenOrCreate)
return Success signedZipPath
elif startTime.AddMinutes 10.0 < DateTime.UtcNow then
return Failure "Timeout"
else
do! Async.Sleep 5000
return! downloadFile fileName startTime
}
let signed = downloadFile toSignZipName DateTime.UtcNow |> Async.RunSynchronously
match signed with
| Success file ->
Unzip buildDir file
MoveFile (buildDir @@ "azurefunctions/") (buildDir @@ "functions.js")
MoveFile (buildDir @@ "azurefunctions/http/") (buildDir @@ "request.js")
MoveFile (buildDir @@ "azurefunctions/http/") (buildDir @@ "response.js")
| Failure e -> targetError e null |> ignore
let signed = downloadFile toSignThirdPartyName DateTime.UtcNow |> Async.RunSynchronously
match signed with
| Success file ->
Unzip buildDir file
MoveFileTo (buildDir @@ "node_x64.dll", buildDir @@ "edge/x64/node.dll")
MoveFileTo (buildDir @@ "edge_nativeclr_x64.dll", buildDir @@ "edge/x64/edge_nativeclr.node")
MoveFileTo (buildDir @@ "node_x86.dll", buildDir @@ "edge/x86/node.dll")
MoveFileTo (buildDir @@ "edge_nativeclr_x86.dll", buildDir @@ "edge/x86/edge_nativeclr.node")
| Failure e -> targetError e null |> ignore
)
Target "DownloadNugetExe" (fun _ ->
use webClient = new WebClient ()
webClient.DownloadFile (nugetUri, buildDir @@ "NuGet.exe")
)
Target "DownloadTools" (fun _ ->
if File.Exists sigCheckExe then
printfn "%s" "Skipping downloading sigcheck.exe since it's already there"
else
printfn "%s" "Downloading sigcheck.exe"
use webClient = new WebClient ()
(Uri ("https://functionsbay.blob.core.windows.net/public/tools/sigcheck64.exe"), sigCheckExe)
|> webClient.DownloadFile
)
Dependencies
"Clean"
==> "DownloadTools"
==> "RestorePackages"
==> "SetVersion"
==> "Compile"
==> "DownloadNugetExe"
==> "CompileTest"
==> "XUnitTest"
==> "GenerateZipToSign"
==> "UploadZipToSign"
==> "EnqueueSignMessage"
==> "WaitForSigning"
==> "Zip"
// start build
RunTargetOrDefault "Zip"