-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.fsx
519 lines (426 loc) · 15.3 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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
// include Fake lib
#r @"packages/build/FAKE/tools/FakeLib.dll"
#load "scripts/Butler.fs"
open Fake
open System.Net
// Properties
let mode = getBuildParamOrDefault "mode" "Release"
let parentDir = "../"
// Build directories
let buildDirBase = "./bin/"
let buildDir = buildDirBase + mode + "/"
let appName = "turnt_ninja"
let appPath = buildDir + appName + ".exe"
// Substructio properties
let substructioRepo = @"https://github.com/opcon/Substructio"
let substructioBranch = "develop"
let substructioFolder = "Substructio"
let substructioDir = parentDir + substructioFolder + "/"
let substructioBuildDir = substructioDir + buildDirBase + mode + "/"
let contentDirDeployName = "Content"
let licenseDirDeployName = "Licenses"
let dllDirDeployName = "Dependencies"
// KickStart properties
let kickstartArchive = @"https://my.mixtape.moe/boqboe.zip"
let kickstartArchiveNoSSL = @"http://my.mixtape.moe/boqboe.zip"
let kickstartArchivePath = "./kickstart.zip"
// More directories
let tempDirBase = "./tmp/"
let deployDir = "./deploy/"
let squirrelDeployDir = deployDir + "squirrel/"
// Get directory postfix
let postFix = match mode.ToLower() with
| "release" -> ""
| _ -> "-" + mode.ToLower()
let (|Prefix|_|) (p:string) (s:string) =
if s.StartsWith(p) then
Some(s.Substring(p.Length))
else
None
let isTagged (repoDir:string) =
let _,msg,error = Git.CommandHelper.runGitCommand repoDir "describe --abbrev=0 --exact-match"
let success =
match error with
| Prefix "fatal: " rest ->
trace rest
false
| "" -> true
| _ -> true
let tag =
match success with
| false -> ""
| true -> msg |> Seq.head
(tag, success)
let versionString =
lazy
let ver = VersionHelper.GetAssemblyVersion appPath
let vs1 = sprintf "%i.%i.%i%s" ver.Major ver.Minor ver.Build postFix
let t,s = isTagged "./"
let vs =
match s with
| true ->
let split = StringHelper.split('-') t
match split.Length with
| 1 -> vs1
| _ -> (sprintf "%s-%s" vs1 (List.last split))
| false -> vs1
vs
let alphaBuild =
lazy
((StringHelper.split('-') versionString.Value).Length > 1)
let deployName =
lazy
sprintf "%s-%s" appName versionString.Value
// Get temp directory name
let tempDirName = lazy
tempDirBase + appName + "/"
let deployKickstartName = lazy
deployName.Value + "-kickstart"
let deployZipName = lazy
deployName.Value + ".zip"
let deployZipPath = lazy
deployDir + deployZipName.Value
let deployKickstartPath = lazy
deployDir + deployKickstartName.Value + ".zip"
let tempKickstartPath = lazy
tempDirBase + deployKickstartName.Value + "/"
let macAppName = "Turnt Ninja"
let macAppFolder = macAppName + ".app"
let macAppDeployName = lazy
macAppFolder + "-" + versionString.Value + ".zip"
let macAppDeployPath = lazy
deployDir + macAppDeployName.Value
let tempMacAppPath = lazy
tempDirBase + "mac/" + macAppFolder + "/"
let tempMacAppContents = lazy
tempMacAppPath.Value + "Contents/"
let tempMacAppResources = lazy
tempMacAppContents.Value + "Resources/"
let tempMacAppMacOS = lazy
tempMacAppContents.Value + "MacOS/"
let macIconOrigPath = lazy
tempMacAppMacOS.Value + "Content/Images/icon.icns"
// Info.plist mac file
let macInfoFile = """<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>turntninja</string>
<key>CFBundleIconFile</key>
<string>icon.icns</string>
<key>CFBundleIdentifier</key>
<string>org.ptrk.turntninja</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>Turnt Ninja</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>LSMinimumSystemVersion</key>
<string>10.7.0</string>
<key>LSUIElement</key>
<false/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSHumanReadableCopyright</key>
<string>� 2017 PTRK</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>"""
// Itch.io Linux toml
let itchLinuxConfig = @"[[actions]]
name = ""Play""
path = ""turntninja"""
let itchMacConfig = @"[[actions]]
name = ""Play""
path = ""Turnt Ninja.app"""
let itchWindowsConfig = @"[[actions]]
name = ""Play""
path = ""turnt_ninja.exe""
[[prereqs]]
name = ""vcredist-2010-x86""
[[prereqs]]
name = ""vcredist-2010-x64"""
let itchPushTarget = "opcon/turnt-ninja"
let itchChannelSuffix =
match Git.Information.getBranchName "./" with
| "develop" -> "-ci"
| _ -> ""
// Tool names
let squirrelToolName = "Squirrel.exe"
let ILMergeToolName = "ILRepack.exe"
// MSBuild location for VS2017 RC (Community)
let msbuild2017Location = @"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin"
let ZipFolderWithWorkingDir (workingDir:string) (folderPath:string) (zipPath:string) =
let dInfo = new System.IO.DirectoryInfo(folderPath)
Zip workingDir zipPath [ for f in dInfo.EnumerateFiles("*", System.IO.SearchOption.AllDirectories) do yield f.FullName]
let ZipFolder (folderPath:string) (zipPath:string) = ZipFolderWithWorkingDir folderPath folderPath zipPath
let pushAppVeyorArtifact (appVeyorFileName:string) (localPath:string) =
AppVeyor.PushArtifact (fun p ->
{p with
FileName = appVeyorFileName
Path = localPath
})
// Targets
Target "Clean" (fun _ ->
try
CleanDir buildDir
with
| _ -> ()
)
Target "CleanSubstructio" (fun _ ->
CleanDir substructioBuildDir
)
Target "CleanAll" (fun _ ->
try
CleanDir buildDirBase
with
| _ -> ()
)
Target "CheckSubstructioExists" (fun _ ->
if not (directoryExists substructioDir) then
trace "Substructio does not exist, cloning Substructio"
Git.Repository.cloneSingleBranch parentDir substructioRepo substructioBranch substructioFolder
else
trace "Substructio folder already exists"
)
Target "RestoreSubstructioPackages" (fun _ ->
Paket.Restore (fun p ->
{ p with
WorkingDir = substructioDir})
)
Target "BuildSubstructio" (fun _ ->
"Building Substructio, in " + mode + " configuration" |> trace
!! (substructioDir + "src/**/*.csproj")
|>
match mode.ToLower() with
| "release" -> MSBuildRelease "" "Build"
| _ -> MSBuildDebug "" "Build"
|> Log "AppBuild-Output:"
)
Target "Build" (fun _ ->
"Building Turnt Ninja in " + mode + " configuration" |> trace
!! "src/**/*.csproj"
|>
match mode.ToLower() with
| "release" -> MSBuildRelease buildDir "Build"
| _ -> MSBuildDebug buildDir "Build"
|> Log "AppBuild-Output: "
)
Target "CleanTemp" (fun _ ->
CleanDir tempDirBase
)
Target "CleanDeploy" (fun _ ->
CleanDir deployDir
)
Target "CopyToTemp" (fun _ ->
ensureDirectory deployDir
ensureDirectory tempDirBase
let mainFiles = !! (sprintf "%s*.dll" buildDir) ++ (sprintf "%s*.config" buildDir) ++ (sprintf "%s*.exe" buildDir) -- (sprintf "%s*vshost*" buildDir)
CopyFiles tempDirName.Value mainFiles
CopyDir (tempDirName.Value + contentDirDeployName) "src/TurntNinja/Content/" (fun x -> true)
CopyDir (tempDirName.Value + licenseDirDeployName) "docs/licenses" (fun x-> true)
let filesToMove = !! (sprintf "%s*.dll" tempDirName.Value) ++ (sprintf "%s*.dll.config" tempDirName.Value)
Copy (tempDirName.Value + dllDirDeployName) filesToMove
DeleteFiles filesToMove
)
Target "DownloadKickstart" (fun _ ->
ensureDirectory (tempKickstartPath.Value)
trace ("Downloading kickstart from " + kickstartArchive)
// Download mono kickstart
let wc = new WebClient()
try
wc.DownloadFile(kickstartArchive, kickstartArchivePath)
with
| _ -> (trace ("Download failed, using non-ssl url " + kickstartArchiveNoSSL)
wc.DownloadFile(kickstartArchiveNoSSL, kickstartArchivePath))
)
Target "DeployZip" (fun _ ->
let dInfo = new System.IO.DirectoryInfo(tempDirName.Value)
Zip tempDirName.Value deployZipPath.Value [ for f in dInfo.EnumerateFiles("*", System.IO.SearchOption.AllDirectories) do yield f.FullName]
//ArchiveHelper.Tar.GZip.CompressWithDefaults (directoryInfo artifactTempDir) (fileInfo (deployDir + deployName + ".tar.gz")) (dInfo.EnumerateFiles("*", System.IO.SearchOption.AllDirectories))
)
Target "DeploySquirrel" (fun _ ->
ensureDirectory squirrelDeployDir
let info = System.Diagnostics.FileVersionInfo.GetVersionInfo appPath
let packagePath = sprintf "%s%s.%s%s.nupkg" deployDir appName info.FileVersion postFix
// Pack nuget package
NuGet (fun p ->
{p with
Authors = ["Patrick Yates"]
Description = "A music game"
Project = "Turnt Ninja"
Version = info.FileVersion + postFix
ReleaseNotes = "https://github.com/opcon/turnt-ninja"
Files = [
("**/*.*", Some @"lib/net45", None)
]
OutputPath = deployDir
WorkingDir = tempDirName.Value
})
"src/TurntNinja/TurntNinja.nuspec"
let squirrelPath = findToolInSubPath squirrelToolName ""
// Create squirrel package
Squirrel.SquirrelPack (fun p ->
{p with
ReleaseDir = squirrelDeployDir
ToolPath = squirrelPath
})
packagePath
)
Target "DeployKickstart" (fun _ ->
trace "Copying build files to kickstart folder"
CopyDir (tempKickstartPath.Value + appName) tempDirName.Value (fun x -> true)
trace "Unzipping kickstart over top"
Unzip (tempKickstartPath.Value + appName) kickstartArchivePath
trace "Zipping it all up"
ZipFolder tempKickstartPath.Value deployKickstartPath.Value
)
Target "DeployMacApp" (fun _ ->
ensureDirectory tempMacAppContents.Value
ensureDirectory tempMacAppMacOS.Value
ensureDirectory tempMacAppResources.Value
trace "Copying kickstart folder to mac app folder"
CopyDir tempMacAppMacOS.Value (tempKickstartPath.Value + appName) (fun x -> true)
trace "Copying icon to mac app folder"
CopyFile tempMacAppResources.Value macIconOrigPath.Value
trace "Writing Info.plist file"
WriteStringToFile false (tempMacAppContents.Value + "Info.plist") macInfoFile
trace "Zipping it all up"
ZipFolderWithWorkingDir (tempDirBase + "mac/") tempMacAppPath.Value macAppDeployPath.Value
)
Target "Deploy" (fun _ -> ())
Target "DeployAll" (fun _ -> ())
Target "PushArtifacts" (fun _ ->
match buildServer with
| BuildServer.AppVeyor ->
pushAppVeyorArtifact (deployName.Value + "-appveyor.zip") deployZipPath.Value
pushAppVeyorArtifact macAppDeployName.Value macAppDeployPath.Value
pushAppVeyorArtifact (deployKickstartName.Value + ".zip") deployKickstartPath.Value
| _ -> ()
)
Target "SetupMSBuildPath" (fun _ ->
if (directoryExists msbuild2017Location) then
trace (sprintf "Found 2017 MSBuild directory at %s, setting MSBuild build parameter to this location" msbuild2017Location)
setBuildParam "MSBuild" msbuild2017Location
)
Target "Default" (fun _ ->
()
)
Target "DownloadButler" (fun _ ->
Butler.DownloadButler "./"
)
let pushWin (channel:string) =
WriteStringToFile false (tempDirName.Value + "/.itch.toml") itchWindowsConfig
Butler.PushBuild "./" tempDirName.Value itchPushTarget channel versionString.Value true |> string |> trace
let pushLinux (channel:string) =
WriteStringToFile false (tempKickstartPath.Value + appName + "/.itch.toml") itchLinuxConfig
Butler.PushBuild "./" (tempKickstartPath.Value + appName) itchPushTarget channel versionString.Value true |> string |> trace
let pushMac (channel:string) =
WriteStringToFile false (tempDirBase + "mac/" + ".itch.toml") itchMacConfig
Butler.PushBuild "./" (tempDirBase + "mac") itchPushTarget channel versionString.Value true |> string |> trace
Target "PushItchCI" (fun _ ->
match mode.ToLower() with
| "release" ->
match (Git.Information.getBranchName "./").ToLower() with
| "master" | "develop" ->
let t,s = isTagged "./"
()
match s with
| true ->
match buildServer with
| BuildServer.AppVeyor ->
pushWin ("win" + itchChannelSuffix)
| BuildServer.Travis ->
match EnvironmentHelper.isMacOS with
| true ->
pushMac ("mac" + itchChannelSuffix)
| false ->
pushLinux ("linux" + itchChannelSuffix)
| BuildServer.LocalBuild ->
pushWin ("win" + itchChannelSuffix)
pushLinux ("linux" + itchChannelSuffix)
pushMac ("mac" + itchChannelSuffix)
| _ -> ()
| false -> ()
| _ -> ()
| _ -> ()
)
Target "PrintVersion" (fun _ ->
trace versionString.Value
)
Target "StampAssembly" (fun _ ->
let t,s = isTagged "./"
let stamp1 = sprintf "Head:%s Sha:%s" (Git.Information.getBranchName "./") (Git.Information.getCurrentHash())
let stamp =
match s with
| true ->
(sprintf "Tag:%s %s" t stamp1)
| false -> stamp1
AssemblyInfoFile.UpdateAttributes ("src/TurntNinja/Properties/AssemblyInfo.cs") [AssemblyInfoFile.Attribute.InformationalVersion stamp]
)
Target "PushArtifactsAndItchBuilds" (fun _ ->
()
)
// Dependencies
"StampAssembly"
==> "Build"
"Clean"
==> "Build"
==> "Default"
"SetupMSBuildPath"
==> "Build"
"CleanSubstructio"
==> "RestoreSubstructioPackages"
==> "BuildSubstructio"
"BuildSubstructio"
==> "Build"
"CheckSubstructioExists"
==> "CleanSubstructio"
"CleanTemp"
==> "CopyToTemp"
"CopyToTemp"
==> "DeployZip"
==> "Deploy"
==> "DeployAll"
"DeployZip"
==> "DeploySquirrel"
"CopyToTemp"
==> "DeployKickstart"
"DeployKickstart"
==> "DeployMacApp"
"DeployAll"
==> "PushArtifacts"
"DeployKickstart"
==> "DeployAll"
"DeployMacApp"
==> "DeployAll"
"DeployAll"
==> "PushItchCI"
"DownloadButler"
=?> ("PushItchCI", not (fileExists ("./" + Butler.butlerFileName)))
"PushItchCI"
==> "PushArtifactsAndItchBuilds"
"PushArtifacts"
==> "PushArtifactsAndItchBuilds"
// CopyToTemp conditional target to ensure that we are built
"Build"
=?> ("CopyToTemp", not (fileExists appPath))
// Conditional target for downloading the kickstart archive
"DownloadKickstart"
=?> ("DeployKickstart", not (fileExists kickstartArchivePath))
// start build
RunTargetOrDefault "Default"