-
Notifications
You must be signed in to change notification settings - Fork 585
/
build.fsx
1329 lines (1035 loc) · 47.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
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// First do this and ignore the result: dotnet build --configuration Release
// Then to build do: dotnet fake run build.fsx -e configuration=Release
// And to release do: dotnet fake run build.fsx -e configuration=Release -t Release
#r "paket:
source release/dotnetcore
source https://api.nuget.org/v3/index.json
nuget FSharp.Core
nuget Microsoft.Build 17.3.2
nuget Microsoft.Build.Framework 17.3.2
nuget Microsoft.Build.Tasks.Core 17.3.2
nuget Microsoft.Build.Utilities.Core 17.3.2
nuget System.AppContext prerelease
nuget Paket.Core prerelease
nuget Fake.Api.GitHub prerelease
nuget Fake.BuildServer.AppVeyor prerelease
nuget Fake.BuildServer.TeamCity prerelease
nuget Fake.BuildServer.Travis prerelease
nuget Fake.BuildServer.TeamFoundation prerelease
nuget Fake.BuildServer.GitLab prerelease
nuget Fake.BuildServer.GitHubActions prerelease
nuget Fake.Core.Target prerelease
nuget Fake.Core.SemVer prerelease
nuget Fake.Core.Vault prerelease
nuget Fake.IO.FileSystem prerelease
nuget Fake.IO.Zip prerelease
nuget Fake.Core.ReleaseNotes prerelease
nuget Fake.DotNet.AssemblyInfoFile prerelease
nuget Fake.DotNet.MSBuild prerelease
nuget Fake.DotNet.Cli prerelease
nuget Fake.DotNet.NuGet prerelease
nuget Fake.DotNet.Paket prerelease
nuget Fake.DotNet.Testing.MSpec prerelease
nuget Fake.DotNet.Testing.XUnit2 prerelease
nuget Fake.DotNet.Testing.NUnit prerelease
nuget Fake.Windows.Chocolatey prerelease
nuget Fake.JavaScript.Npm prerelease
nuget Fake.Tools.Git prerelease
nuget Mono.Cecil prerelease
nuget System.Reactive.Compatibility
nuget Suave
nuget Newtonsoft.Json
nuget System.Net.Http
nuget Octokit
nuget Microsoft.Deployment.DotNet.Releases //"
open System.Reflection
open System
open System.IO
open System.IO.Compression
open System.Text
open Fake.Api
open Fake.Core
open Fake.BuildServer
open Fake.Tools
open Fake.IO
open Fake.IO.FileSystemOperators
open Fake.IO.Globbing.Operators
open Fake.Windows
open Fake.DotNet
open Fake.DotNet.Testing
open Fake.Core.TargetOperators
open System.Net.Http
open Microsoft.Deployment.DotNet.Releases
open Fake.JavaScript
open Octokit
open Octokit.Internal
// ****************************************************************************************************
// ------------------------------------------- Definitions -------------------------------------------
// ****************************************************************************************************
// Set this to true if you have lots of breaking changes, for small breaking changes use #if BOOTSTRAP,
// setting this flag will not be accepted
let disableBootstrap = false
// properties
let release = ReleaseNotes.load "RELEASE_NOTES.md"
let docsDir = "./docs"
let releaseDir = "./release"
let nugetDncDir = releaseDir </> "dotnetcore"
let collectedArtifactsDir = releaseDir </> "artifacts"
let chocoReleaseDir = nugetDncDir </> "chocolatey"
let root = __SOURCE_DIRECTORY__
let srcDir = root </> "src"
let appDir = srcDir </> "app"
let templateDir = srcDir </> "template"
// NuGet
let nugetExe =
Directory.GetCurrentDirectory()
</> "packages"
</> "build"
</> "NuGet.CommandLine"
</> "tools"
</> "NuGet.exe"
// Secrets and Vault
let mutable secrets = []
let vault =
match Vault.fromFakeEnvironmentOrNone () with
| Some v -> v
| None -> TeamFoundation.variables
let getVarOrDefaultFromVault name def =
match vault.TryGet name with
| Some v -> v
| None -> Environment.environVarOrDefault name def
let releaseSecret replacement name =
let secret =
lazy
let env =
match getVarOrDefaultFromVault name "default_unset" with
| "default_unset" -> failwithf "variable '%s' is not set" name
| s -> s
if BuildServer.buildServer <> BuildServer.TeamFoundation then
// on TFS/VSTS the build will take care of this.
TraceSecrets.register replacement env
env
secrets <- secret :: secrets
secret
// More properties
let githubReleaseUser = getVarOrDefaultFromVault "RELEASE_USER_GITHUB" "fsprojects"
let gitName = getVarOrDefaultFromVault "REPOSITORY_NAME_GITHUB" "FAKE"
let nugetSource =
getVarOrDefaultFromVault "NUGET_SOURCE" "https://www.nuget.org/api/v2/package"
let chocoSource =
getVarOrDefaultFromVault "CHOCO_SOURCE" "https://push.chocolatey.org/"
let artifactsDir = getVarOrDefaultFromVault "ARTIFACTS_DIRECTORY" ""
let docsDomain =
match BuildServer.isLocalBuild with
| true -> "http://127.0.0.1:8083/"
| false -> getVarOrDefaultFromVault "DOCS_DOMAIN" "fake.build"
let fromArtifacts = not <| String.isNullOrEmpty artifactsDir
let apiKey = releaseSecret "<nugetkey>" "NUGET_KEY"
let chocoKey = releaseSecret "<chocokey>" "CHOCOLATEY_API_KEY"
let githubToken = releaseSecret "<githubtoken>" "GITHUB_TOKEN"
do Environment.setEnvironVar "COREHOST_TRACE" "0"
BuildServer.install [ GitHubActions.Installer ]
// Parsing version. Base version come from RELEASE_NOTES;
// When building on a CI - GitHub actions, nothing will be done, version obtained from RELEASE_NOTES will be used
// However, on local, we will search for local builds on NuGet cache and get the latest local build version and
// increment it. This will be the version metadata in which will be concatenated with version from RELEASE_NOTES.
// For example, if on machine, latest local build has version of fake.core.context.5.21.0-alpha005.local-2,
// then local version used will be fake.core.context.5.21.0-alpha005.local-3
let version =
let segToString =
function
| PreReleaseSegment.AlphaNumeric n -> n
| PreReleaseSegment.Numeric n -> string n
let source, buildMeta =
match BuildServer.buildServer with
| BuildServer.GitHubActions -> [ yield PreReleaseSegment.AlphaNumeric "" ], ""
| _ ->
// from paket, increase versions even locally, this forces integration tests to always use latest packages.
let GlobalPackagesFolderEnvironmentKey = "NUGET_PACKAGES"
let getEnVar variable =
let enVar = System.Environment.GetEnvironmentVariable variable
if System.String.IsNullOrEmpty enVar then
None
else
Some enVar
let getEnvDir specialPath =
let dir = System.Environment.GetFolderPath specialPath
if System.String.IsNullOrEmpty dir then None else Some dir
let LocalRootForTempData =
getEnvDir System.Environment.SpecialFolder.UserProfile
|> Option.orElse (getEnvDir System.Environment.SpecialFolder.LocalApplicationData)
|> Option.defaultWith (fun _ ->
let fallback = Path.GetFullPath ".paket"
if not (Directory.Exists fallback) then
Directory.CreateDirectory fallback |> ignore
fallback)
let UserNuGetPackagesFolder =
getEnVar GlobalPackagesFolderEnvironmentKey
|> Option.map (fun path -> path.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar))
|> Option.defaultWith (fun _ -> Path.Combine(LocalRootForTempData, ".nuget", "packages"))
let currentVer =
Directory.EnumerateDirectories(
Path.Combine(UserNuGetPackagesFolder, "fake.core.context"),
release.NugetVersion + "*local.*"
)
|> Seq.choose (fun dir ->
let n = Path.GetFileName dir
let v = n.Split("local.").[1]
match System.Numerics.BigInteger.TryParse(v) with
| true, v -> Some v
| _ ->
eprintfn "Could not parse '%s' to a bigint to retrieve the latest version (from '%s')" v dir
None)
|> Seq.append [ 0I ]
|> Seq.max
let d = System.DateTime.Now
let newLocalVersionNumber = currentVer + 1I
[ PreReleaseSegment.AlphaNumeric("local." + newLocalVersionNumber.ToString()) ], d.ToString("yyyy-MM-dd-HH-mm")
let semVer = SemVer.parse release.NugetVersion
let prerelease =
match semVer.PreRelease with
| None ->
let toAdd = String.Join(".", source |> Seq.map segToString)
match String.IsNullOrWhiteSpace toAdd with
| true -> None
| false ->
Some
{ Name = ""
Values = source
Origin = toAdd }
| Some p ->
let toAdd = String.Join(".", source |> Seq.map segToString)
let toAdd = if String.IsNullOrEmpty toAdd then toAdd else "." + toAdd
Some
{ p with
Values = p.Values @ source
Origin = p.Origin + toAdd }
let fromRepository =
match prerelease with
| Some _ ->
{ semVer with
PreRelease = prerelease
Original = None
BuildMetaData = buildMeta }
| None -> semVer
match Environment.environVarOrNone "FAKE_VERSION" with
| Some ver -> SemVer.parse ver
| None -> fromRepository
let simpleVersion = version.AsString
let nugetVersion =
match String.IsNullOrEmpty version.BuildMetaData with
| true -> version.AsString
| false -> sprintf "%s+%s" version.AsString version.BuildMetaData
let chocoVersion =
// Replace "." with "-" in the prerelease-string
let build =
if version.Build > 0I then
("." + (let bi = version.Build in bi.ToString("D")))
else
""
let pre =
match version.PreRelease with
| Some preRelease -> ("-" + preRelease.Origin.Replace(".", "-"))
| None -> ""
let result =
sprintf "%d.%d.%d%s%s" version.Major version.Minor version.Patch build pre
if pre.Length > 20 then
let msg =
sprintf "Version '%s' is too long for chocolatey (Prerelease string is max 20 chars)" result
Trace.traceError msg
failwithf "%s" msg
result
Trace.tracefn "FAKE build version: %s" simpleVersion
Trace.tracefn "FAKE NuGet build version: %s" nugetVersion
Trace.tracefn "FAKE Chocolatey build version: %s" chocoVersion
// DotNet host properties
let dotnetSdk = lazy DotNet.install DotNet.Versions.FromGlobalJson
/// <summary>
/// DotNet host with working directory set
/// </summary>
///
/// <param name="wd">The working directory to set for DotNet host</param>
let inline dotnetWorkingDir wd =
DotNet.Options.lift dotnetSdk.Value
>> DotNet.Options.withWorkingDirectory wd
>> DotNet.Options.withTimeout (Some(System.TimeSpan.FromMinutes 20.))
/// <summary>
/// DotNet host with default values and given arguments
/// </summary>
///
/// <param name="arg">DotNet override arguments</param>
let inline dotnetSimple arg = DotNet.Options.lift dotnetSdk.Value arg
/// <summary>
/// Copy given artifact file or directory to artifact directory for build CI consumption
/// </summary>
///
/// <param name="artifact">The artifact file or directory to publish</param>
let collectArtifact artifact =
Directory.ensure collectedArtifactsDir
Shell.copyFile collectedArtifactsDir artifact
/// <summary>
/// Publish the given artifact file or directory on the build server
/// </summary>
///
/// <param name="artifact">The artifact file or directory to publish</param>
let publish artifact =
if not (File.Exists artifact) && not (Directory.Exists artifact) then
failwithf "The path '%s' is not a file and not a directory so the publish call failed!" artifact
collectArtifact artifact
Trace.publish ImportData.BuildArtifact artifact
/// <summary>
/// Clean integration test directories from compiled files/assemblies
/// </summary>
let cleanForTests () =
let run workingDir fileName args =
printfn "CWD: %s" workingDir
let fileName, args =
if Environment.isUnix then
fileName, args
else
"cmd", ("/C " + fileName + " " + args)
let processResult =
CreateProcess.fromRawCommandLine fileName args
|> CreateProcess.withWorkingDirectory workingDir
|> CreateProcess.withTimeout System.TimeSpan.MaxValue
|> Proc.run
if processResult.ExitCode <> 0 then
failwith (sprintf "'%s> %s %s' task failed" workingDir fileName args)
let rmdir dir =
if Environment.isUnix then
Shell.rm_rf dir
// Use this in Windows to prevent conflicts with paths too long
else
run "." "cmd" ("/C rmdir /s /q " + Path.GetFullPath dir)
// Clean test directories
!! "integrationtests/*/temp" |> Seq.iter rmdir
/// <summary>
/// Restores DotNet tools in FAKE repository
/// </summary>
let restoreTools =
let alreadyRestored = ref false
(fun () ->
if not alreadyRestored.Value then
DotNet.exec dotnetSimple "tool" "restore" |> ignore<ProcessResult>
alreadyRestored.Value <- true)
/// <summary>
/// Call Paket with the given working directory and arguments
/// </summary>
///
/// <param name="wd">Working directory to execute Paket in</param>
/// <param name="args">Paket arguments</param>
let callPaket wd args =
restoreTools ()
let res = DotNet.exec (dotnetWorkingDir wd) "paket" args
if not res.OK then
failwithf "paket failed to start: %A" res
/// <summary>
/// Calls Expecto tool to run tests in the given working directory and DLL.
/// </summary>
///
/// <param name="workDir">Working directory to execute Expecto in</param>
/// <param name="dllPath">Test assembly to run tests from</param>
/// <param name="resultsXml">Expecto test results XML file</param>
let runExpecto workDir dllPath resultsXml =
let processResult =
DotNet.exec (dotnetWorkingDir workDir) (sprintf "%s" dllPath) (sprintf "--nunit-summary %s" resultsXml)
if processResult.ExitCode <> 0 then
failwithf "Tests in %s failed." (Path.GetFileName dllPath)
Trace.publish (ImportData.Nunit NunitDataVersion.Nunit) (workDir </> resultsXml)
/// <summary>
/// Get Chocolaty executable
/// </summary>
let getChocoWrapper () =
let altToolPath = Path.GetFullPath "temp/choco.sh"
if not Environment.isWindows then
Directory.ensure "temp"
File.WriteAllText(
altToolPath,
"""#!/bin/bash
docker run --rm -v $PWD:$PWD -w $PWD linuturk/mono-choco $@
"""
)
let result = Shell.Exec("chmod", sprintf "+x %s" altToolPath)
if result <> 0 then
failwithf "'chmod +x %s' failed on unix" altToolPath
altToolPath
//TODO:: see if we need to update the runtimes to newer versions of OSs
let runtimes = [ "win7-x86"; "win7-x64"; "osx.10.11-x64"; "linux-x64" ]
/// <summary>
/// Publishes the build artifacts for the given runtime
/// </summary>
///
/// <param name="runtimeName">The runtime to publish for</param>
let publishRuntime runtimeName =
let runtimeDir = sprintf "%s/Fake.netcore/%s" nugetDncDir runtimeName
let zipFile =
sprintf "%s/Fake.netcore/fake-dotnetcore-%s.zip" nugetDncDir runtimeName
!!(sprintf "%s/**" runtimeDir) |> Zip.zip runtimeDir zipFile
publish zipFile
/// <summary>
/// Pushes the given NuGet package to NuGet registry
/// </summary>
///
/// <param name="tries">The number of re-tries</param>
/// <param name="nugetPackage">The NuGet package to push</param>
let rec nugetPush tries nugetPackage =
let ignore_conflict = Environment.environVar "IGNORE_CONFLICT" = "true"
try
if not <| String.IsNullOrEmpty apiKey.Value then
let quoteString str = sprintf "\"%s\"" str
let args =
sprintf
"push %s %s -Source %s %s"
(quoteString nugetPackage)
(quoteString apiKey.Value)
(quoteString nugetSource)
(if ignore_conflict then "-SkipDuplicate" else "")
let errors = System.Collections.Generic.List<string>()
let results = System.Collections.Generic.List<string>()
let errorF msg =
Trace.traceFAKE "%s" msg
errors.Add msg
let messageF msg =
Trace.tracefn "%s" msg
results.Add msg
let processResult =
CreateProcess.fromRawCommandLine nugetExe args
|> CreateProcess.withTimeout (System.TimeSpan.FromMinutes 10.)
|> CreateProcess.redirectOutput
|> CreateProcess.withOutputEventsNotNull errorF messageF
|> Proc.run
if processResult.ExitCode <> 0 then
if
not ignore_conflict
|| not (errors |> Seq.exists (fun err -> err.Contains "409"))
then
let msgs =
errors |> Seq.map (fun c -> "(Err) " + c)
|> Seq.append results |> Seq.map (fun c -> c)
let msg = String.Join("\n", msgs)
failwithf "failed to push package %s (code %d): \n%s" nugetPackage processResult.ExitCode msg
else
Trace.traceFAKE "ignore conflict error because IGNORE_CONFLICT=true!"
else
Trace.traceFAKE "could not push '%s', because api key was not set" nugetPackage
with exn when tries > 1 ->
Trace.traceFAKE "Error while pushing NuGet package: %s" exn.Message
nugetPush (tries - 1) nugetPackage
// ****************************************************************************************************
// --------------------------------------------- Targets ---------------------------------------------
// ****************************************************************************************************
Target.initEnvironment ()
Target.create "WorkaroundPaketNuspecBug" (fun _ ->
// Workaround https://github.com/fsprojects/Paket/issues/2830
// https://github.com/fsprojects/Paket/issues/2689
// Basically paket fails if there is already an existing nuspec in obj/ dir because then MSBuild will call paket with multiple nuspec file arguments separated by ';'
!! "src/*/*/obj/**/*.nuspec"
-- (sprintf "src/*/*/obj/**/*%s.nuspec" nugetVersion)
|> File.deleteAll)
Target.create "Clean" (fun _ ->
!! "src/*/*/bin" |> Shell.cleanDirs
let fakeRuntimeVersion =
typeof<Fake.Core.Context.FakeExecutionContext>.Assembly.GetName().Version
printfn "fake runtime %O" fakeRuntimeVersion
if fakeRuntimeVersion < new System.Version(5, 10, 0) then
printfn "deleting obj directories because of https://github.com/fsprojects/Paket/issues/3404"
!! "src/*/*/obj" |> Shell.cleanDirs
// Allow paket to do a full-restore (to improve performance)
Shell.rm ("paket-files" </> "paket.restore.cached")
callPaket "." "restore"
Shell.cleanDirs
[ nugetDncDir
collectedArtifactsDir ]
// Clean Data for tests
cleanForTests ())
Target.create "CheckReleaseSecrets" (fun _ ->
for secret in secrets do
secret.Force() |> ignore)
Target.create "CheckFormatting" (fun _ ->
let dotnetOptions = (fun (buildOptions:DotNet.Options) -> { buildOptions with RedirectOutput = false})
let result =
DotNet.exec id "fantomas" "src/app/ src/template/ src/test/ --recurse --check"
if result.ExitCode = 0 then
Trace.log "No files need formatting"
elif result.ExitCode = 99 then
failwith "Some files need formatting, please run \"dotnet fantomas src/app/ src/template/ src/test/ --recurse\" to resolve this."
else
failwith "Errors while formatting"
)
// ----------------------------------------------------------------------------------------------------
// Documentation targets.
Target.create "GenerateDocs" (fun _ ->
let source = "./docs"
Shell.cleanDir ".fsdocs"
Directory.ensure "output"
let projInfo =
seq {
("root", docsDomain)
("fsdocs-logo-src", docsDomain @@ "content/img/logo.svg")
("fsdocs-fake-version", simpleVersion)
}
File.writeString false "./output/.nojekyll" ""
File.writeString false "./output/CNAME" docsDomain
Shell.copy (source @@ "guide") [ "RELEASE_NOTES.md" ]
try
Npm.install (fun o -> { o with WorkingDirectory = "./docs" })
Npm.run "build" (fun o -> { o with WorkingDirectory = "./docs" })
Shell.copy "./output" [source </> "robots.txt"]
// renaming node_modules directory so that fsdocs skip it when generating site.
Directory.Move("./docs/node_modules", "./docs/.node_modules")
let command = sprintf "build --clean --input ./docs --saveimages --properties Configuration=release --parameters fsdocs-logo-src %s fsdocs-fake-version %s" (docsDomain @@ "content/img/logo.svg") simpleVersion
DotNet.exec id "fsdocs" command |> ignore
// Fsdocs.build (fun p -> { p with
// Input = Some(source)
// SaveImages = Some(true)
// Clean = Some(true)
// Parameters = Some projInfo
// Properties = Some "Configuration=debug"
// //Strict = Some(true)
// })
finally
// clean up
Shell.rm (source </> "guide/RELEASE_NOTES.md")
// renaming node_modules directory back after fsdocs generated site.
Directory.Move("./docs/.node_modules", "./docs/node_modules")
// validate site generation and ensure all components are generated successfully.
if DirectoryInfo.ofPath("./output/guide").GetFiles().Length = 0 then failwith "site generation failed due to missing guide directory"
if DirectoryInfo.ofPath("./output/reference").GetFiles().Length = 0 then failwith "site generation failed due to missing reference directory"
if DirectoryInfo.ofPath("./output/articles").GetFiles().Length = 0 then failwith "site generation failed due to missing articles directory"
if not (File.exists("./output/data.json")) then failwith "site generation failed due to missing data.json file"
if not (File.exists("./output/guide/RELEASE_NOTES.html")) then failwith "site generation failed due to missing RELEASE_NOTES.html file"
if not (File.exists("./output/guide.html")) then failwith "site generation failed due to missing guide.html file"
if not (File.exists("./output/index.html")) then failwith "site generation failed due to missing index.html file"
// prepare artifact
Directory.ensure "temp"
!!("output" </> "**/*")
|> Zip.zip docsDir "temp/docs.zip"
publish "temp/docs.zip")
Target.create "HostDocs" (fun _ ->
let source = "./docs"
try
Npm.install (fun o -> { o with WorkingDirectory = "./docs" })
Npm.run "build" (fun o -> { o with WorkingDirectory = "./docs" })
Shell.copy (source @@ "guide") [ "RELEASE_NOTES.md" ]
Shell.copy "./output" [source </> "robots.txt"]
// renaming node_modules directory so that fsdocs skip it when generating site.
Directory.Move("./docs/node_modules", "./docs/.node_modules")
let command = sprintf "watch --input ./docs --saveimages --properties Configuration=release --parameters fsdocs-logo-src %s fsdocs-fake-version %s" (docsDomain @@ "content/img/logo.svg") simpleVersion
DotNet.exec id "fsdocs" command |> ignore
// Fsdocs.watch id
finally
// clean up
Shell.rm (source </> "guide/RELEASE_NOTES.md")
// renaming node_modules directory back after fsdocs generated site.
Directory.Move("./docs/.node_modules", "./docs/node_modules")
)
// ----------------------------------------------------------------------------------------------------
// Test targets.
Target.create "DotNetCoreIntegrationTests" (fun _ ->
cleanForTests ()
runExpecto
root
"src/test/Fake.Core.IntegrationTests/bin/Release/net6.0/Fake.Core.IntegrationTests.dll"
"Fake_Core_IntegrationTests.TestResults.xml")
Target.create "TemplateIntegrationTests" (fun _ ->
let targetDir = srcDir </> "test" </> "Fake.DotNet.Cli.IntegrationTests"
runExpecto
targetDir
"bin/Release/net6.0/Fake.DotNet.Cli.IntegrationTests.dll"
"Fake_DotNet_Cli_IntegrationTests.TestResults.xml"
Shell.rm_rf (root </> "test"))
Target.create "DotNetCoreUnitTests" (fun _ ->
// dotnet run -p src/test/Fake.Core.UnitTests/Fake.Core.UnitTests.fsproj
runExpecto
root
"src/test/Fake.Core.UnitTests/bin/Release/net6.0/Fake.Core.UnitTests.dll"
"Fake_Core_UnitTests.TestResults.xml"
// dotnet run --project src/test/Fake.Core.CommandLine.UnitTests/Fake.Core.CommandLine.UnitTests.fsproj
runExpecto
root
"src/test/Fake.Core.CommandLine.UnitTests/bin/Release/net6.0/Fake.Core.CommandLine.UnitTests.dll"
"Fake_Core_CommandLine_UnitTests.TestResults.xml")
// ----------------------------------------------------------------------------------------------------
// Bootstrap Fake targets; These targets will be used as a sort of a dog-food for FAKE. We will use the
// built FAKE runner and call it will targets to validate it.
Target.create "BootstrapFake_PrintColors" (fun _ ->
let color (color: ConsoleColor) (code: unit -> _) =
let before = Console.ForegroundColor
try
Console.ForegroundColor <- color
code ()
finally
Console.ForegroundColor <- before
color ConsoleColor.Magenta (fun _ -> printfn "TestMagenta"))
Target.create "BootstrapFake_FailFast" (fun _ -> failwith "Bootstrap FAKE Fail Fast")
Target.create "BootstrapFake" (fun _ ->
let buildScript = "build.fsx"
let testScript = "testbuild.fsx"
let testScriptLock = "testbuild.fsx.lock"
// Check if we can build ourself with the new binaries.
let test timeout clearCache script =
let clear () =
// Will make sure the test call actually compiles the script.
// Note: We cannot just clean .fake here as it might be locked by the currently executing code :)
[ ".fake/testbuild.fsx/packages"
".fake/testbuild.fsx/paket.depedencies.sha1"
".fake/testbuild.fsx/paket.lock"
"testbuild.fsx.lock" ]
|> List.iter Shell.rm_rf
!! ".fake/testbuild.fsx/testbuild_*" |> Seq.iter Shell.rm_rf
let executeTarget target =
if clearCache then
clear ()
let fileName =
if Environment.isUnix then
nugetDncDir </> "Fake.netcore/current/fake"
else
nugetDncDir </> "Fake.netcore/current/fake.exe"
let processResult =
CreateProcess.fromRawCommandLine fileName (sprintf "run --fsiargs \"--define:BOOTSTRAP\" %s --target %s" script target)
|> CreateProcess.withWorkingDirectory "."
|> CreateProcess.setEnvironmentVariable "FAKE_DETAILED_ERRORS" "true"
|> CreateProcess.withTimeout timeout
|> Proc.run
processResult.ExitCode
let result = executeTarget "BootstrapFake_PrintColors"
if result <> 0 then
failwithf "Bootstrapping failed for target 'BootstrapFake_PrintColors' (because of exit code %d)" result
let result = executeTarget "BootstrapFake_FailFast"
if result = 0 then
failwithf "Bootstrapping failed for target 'BootstrapFake_FailFast' (because of exit code %d)" result
File.ReadAllText buildScript |> fun text -> File.WriteAllText(testScript, text)
try
// Will compile the script.
test (System.TimeSpan.FromMinutes 15.0) true testScript
// Will use the compiled/cached version.
test (System.TimeSpan.FromMinutes 3.0) false testScript
finally
ignore ""
File.Delete(testScript)
File.Delete(testScriptLock))
// ----------------------------------------------------------------------------------------------------
// Publishing targets; For each OS runtime we will publish FAKE as well as a portable format.
Target.create "_DotNetPublish_portable" (fun _ ->
let nugetDir = System.IO.Path.GetFullPath nugetDncDir
// Publish portable as well (see https://docs.microsoft.com/en-us/dotnet/articles/core/app-types)
let netcoreFsproj = appDir </> "Fake.netcore/Fake.netcore.fsproj"
let outDir = nugetDir @@ "Fake.netcore" @@ "portable"
DotNet.publish
(fun c ->
{ c with
Framework = Some "net6.0"
OutputPath = Some outDir }
|> dotnetSimple)
netcoreFsproj
publishRuntime "portable")
// Create publishing target for each runtime
let info = lazy DotNet.info dotnetSimple
runtimes
|> List.map Some
|> (fun rs -> None :: rs)
|> Seq.iter (fun runtime ->
let runtimeName, runtime =
match runtime with
| Some r -> r, lazy r
| None -> "current", lazy info.Value.RID
let targetName = sprintf "_DotNetPublish_%s" runtimeName
Target.create targetName (fun _ ->
!!(appDir </> "Fake.netcore/Fake.netcore.fsproj")
|> Seq.iter (fun proj ->
let nugetDir = System.IO.Path.GetFullPath nugetDncDir
let projName = Path.GetFileName(Path.GetDirectoryName proj)
let outDir = nugetDir @@ projName @@ runtimeName
DotNet.publish
(fun c ->
{ c with
Runtime = Some runtime.Value
Configuration = DotNet.Release
OutputPath = Some outDir }
|> dotnetSimple)
proj
let source = outDir </> "dotnet"
if File.Exists source then
failwithf "Workaround no longer required?" //TODO: If this is not triggered delete this block
Trace.traceFAKE "Workaround https://github.com/dotnet/cli/issues/6465"
let target = outDir </> "fake"
if File.Exists target then
File.Delete target
File.Move(source, target)
// Create zip
if runtimeName <> "current" then
publishRuntime runtimeName)))
// ----------------------------------------------------------------------------------------------------
// Package creation targets; Create NuGet, Debian, and Chocolatey packages for FAKE
Target.create "CacheDotNetReleases" (fun _ ->
let sdkVersionReleases =
ProductCollection.GetAsync()
|> Async.AwaitTask
|> Async.RunSynchronously
|> List.ofSeq
|> List.find (fun product -> product.ProductVersion.Equals("6.0"))
let client = new HttpClient()
try
let response =
sdkVersionReleases.ReleasesJson
|> client.GetAsync
|> Async.AwaitTask
|> Async.RunSynchronously
response.Content.ReadAsStringAsync()
|> Async.AwaitTask
|> Async.RunSynchronously
|> Fake.IO.File.writeString false "src/app/Fake.Runtime/cachedDotnetSdkReleases.json"
with e ->
failwith "Could not update DotNet releases file.")
Target.create "DotNetCreateNuGetPackage" (fun _ ->
let nugetDir = System.IO.Path.GetFullPath nugetDncDir
// This lines actually ensures we get the correct version checked in
// instead of the one previously bundled with `fake` or `paket`
callPaket "." "restore" // first make paket restore its target file if it feels like it.
Git.CommandHelper.gitCommand "" "checkout .paket/Paket.Restore.targets" // now restore ours
restoreTools ()
// dotnet pack
DotNet.pack
(fun c ->
{ c with
Configuration = DotNet.Release
OutputPath = Some nugetDir
Common = c.Common
MSBuildParams =
{ c.MSBuildParams with
Properties =
[ ("Version", nugetVersion)
("PackageReleaseNotes", release.Notes |> String.toLines) ] } }
|> dotnetSimple)
"Fake.sln"
// build zip package
Directory.ensure (nugetDncDir </> "Fake.netcore")
let zipFile = nugetDncDir </> "Fake.netcore/fake-dotnetcore-packages.zip"
!!(nugetDncDir </> "*.nupkg") -- (nugetDncDir </> "*.symbols.nupkg")
|> Zip.zip nugetDncDir zipFile
publish zipFile
Directory.ensure "temp"
let testZip = "temp/tests.zip"
!! "src/test/*/bin/Release/net6.0/**" |> Zip.zip "src/test" testZip
publish testZip)
Target.create "DotNetCreateChocolateyPackage" (fun _ ->
let altToolPath = getChocoWrapper ()
let changeToolPath (p: Choco.ChocoPackParams) =
if Environment.isWindows then
p
else
{ p with ToolPath = altToolPath }
Directory.ensure chocoReleaseDir
Choco.packFromTemplate
(fun p ->
{ p with
PackageId = "fake"
ReleaseNotes = release.Notes |> String.toLines
InstallerType = Choco.ChocolateyInstallerType.SelfContained
Version = chocoVersion
Files =
[ System.IO.Path.GetFullPath(nugetDncDir </> @"Fake.netcore\win7-x86") + @"\**", Some "bin", None
(System.IO.Path.GetFullPath @"src\VERIFICATION.txt"), Some "VERIFICATION.txt", None
(System.IO.Path.GetFullPath @"License.txt"), Some "LICENSE.txt", None ]
OutputDir = chocoReleaseDir }
|> changeToolPath)
"src/Fake-choco-template.nuspec"
let name = sprintf "%s.%s" "fake" chocoVersion
let chocoPackage = sprintf "%s/%s.nupkg" chocoReleaseDir name
let chocoTargetPackage = sprintf "%s/chocolatey-%s.nupkg" chocoReleaseDir name
File.Copy(chocoPackage, chocoTargetPackage, true)
publish chocoTargetPackage)
Target.create "DotNetCreateDebianPackage" (fun _ ->
let runtime = "linux-x64"
let targetFramework = "net6.0"
let args =
[ sprintf "--runtime %s" runtime
sprintf "--framework %s" targetFramework
sprintf "--configuration %s" "Release"
sprintf "--output %s" (Path.GetFullPath nugetDncDir)
"--no-restore" ]
|> String.concat " "
Environment.setEnvironVar "PackageVersion" simpleVersion
Environment.setEnvironVar "Version" simpleVersion
Environment.setEnvironVar "IsDebianPackaging" "true"
let result =
DotNet.exec (fun opt -> { opt with WorkingDirectory = "src/app/fake-cli/" } |> dotnetSimple) "deb" args
if not result.OK then
failwith "Debian package creation failed"
let fileName = sprintf "fake-cli.%s.%s.deb" simpleVersion runtime
let target = sprintf "%s/%s" nugetDncDir fileName
publish target)
// ----------------------------------------------------------------------------------------------------
// Releasing targets; Publishing NuGet and Chocolatey packages and other things when we do a release
Target.create "DotNetPushChocolateyPackage" (fun _ ->
let name = sprintf "%s.%s.nupkg" "fake" chocoVersion
let path = sprintf "%s/%s" chocoReleaseDir name
if not Environment.isWindows && not (File.exists path) && fromArtifacts then
Directory.ensure chocoReleaseDir
Shell.copyFile path (artifactsDir </> sprintf "chocolatey-%s" name)
let altToolPath = getChocoWrapper ()
let changeToolPath (p: Choco.ChocoPushParams) =
if Environment.isWindows then
p
else
{ p with ToolPath = altToolPath }
path
|> Choco.push (fun p ->
{ p with
Source = chocoSource
ApiKey = chocoKey.Value }
|> changeToolPath))
Target.create "DotNetPushToNuGet" (fun _ ->
!!(appDir </> "*/*.fsproj") -- (appDir </> "Fake.netcore/*.fsproj")
++ (templateDir </> "*/*.fsproj")
|> Seq.iter (fun proj ->
let projName = Path.GetFileName(Path.GetDirectoryName proj)
!!(sprintf "%s/%s.*.nupkg" nugetDncDir projName)
-- (sprintf "%s/%s.*.symbols.nupkg" nugetDncDir projName)
|> Seq.iter (nugetPush 4)))
Target.create "ReleaseDocs" (fun _ ->
Shell.cleanDir "gh-pages"
let auth = sprintf "%s:x-oauth-basic@" githubToken.Value
let url = sprintf "https://%sgithub.com/%s/%s.git" auth githubReleaseUser gitName
Git.Repository.cloneSingleBranch "" url "gh-pages" "gh-pages"