11// include Fake libs
2- #r " ../packages/FAKE/tools/FakeLib.dll"
2+ #r " ../packages/build/FAKE/tools/FakeLib.dll"
3+ #r " System.Xml.Linq"
34#load " ./TaskDefinitionHelper.fsx"
45#load " ./AppVeyorEx.fsx"
56
67open System
8+ open System.Xml .Linq
79open Fake
10+ open Fake.AssemblyInfoFile
811open Fake.ReleaseNotesHelper
9- open Fake.Testing .NUnit3
12+ open Fake.Testing .Expecto
1013open BlackFox
1114
1215let configuration = environVarOrDefault " configuration" " Release"
@@ -16,9 +19,8 @@ let from s = { BaseDirectory = s; Includes = []; Excludes = [] }
1619let rootDir = System.IO.Path.GetFullPath(__ SOURCE_ DIRECTORY__ </> " .." )
1720let srcDir = rootDir </> " src"
1821let artifactsDir = rootDir </> " artifacts"
19- let binDir = artifactsDir </> " bin"
2022let librarySrcDir = srcDir </> " BlackFox.MasterOfFoo"
21- let libraryBinDir = binDir </> " BlackFox.MasterOfFoo" </> configuration
23+ let libraryBinDir = artifactsDir </> " BlackFox.MasterOfFoo" </> configuration
2224let projects = from srcDir ++ " **/*.*proj"
2325
2426/// The profile where the project is posted
@@ -31,63 +33,130 @@ let gitName = "MasterOfFoo"
3133/// The url for the raw files hosted
3234let gitRaw = environVarOrDefault " gitRaw" ( " https://raw.github.com/" + gitOwner)
3335
36+ let inline versionPartOrZero x = if x < 0 then 0 else x
37+
3438let release =
3539 let fromFile = LoadReleaseNotes ( rootDir </> " Release Notes.md" )
3640 if buildServer = AppVeyor then
3741 let appVeyorBuildVersion = int appVeyorBuildVersion
3842 let nugetVer = sprintf " %s -appveyor%04i " fromFile.NugetVersion appVeyorBuildVersion
3943 let asmVer = System.Version.Parse( fromFile.AssemblyVersion)
40- let asmVer = System.Version( asmVer.Major, asmVer.Minor, asmVer.Build, appVeyorBuildVersion)
44+ let asmVer =
45+ System.Version(
46+ versionPartOrZero asmVer.Major,
47+ versionPartOrZero asmVer.Minor,
48+ versionPartOrZero asmVer.Build,
49+ versionPartOrZero appVeyorBuildVersion)
4150 ReleaseNotes.New( asmVer.ToString(), nugetVer, fromFile.Date, fromFile.Notes)
4251 else
4352 fromFile
4453
54+ let mutable dotnetExePath = " dotnet"
55+
56+ Task " InstallDotNetCore" [] ( fun _ ->
57+ dotnetExePath <- DotNetCli.InstallDotNetSDK ( DotNetCli.GetDotNetSDKVersionFromGlobalJson())
58+ )
59+
4560AppVeyorEx.updateBuild ( fun info -> { info with Version = Some release.AssemblyVersion })
4661
62+ let writeVersionProps () =
63+ let doc =
64+ XDocument(
65+ XElement( XName.Get( " Project" ),
66+ XElement( XName.Get( " PropertyGroup" ),
67+ XElement( XName.Get " Version" , release.NugetVersion),
68+ XElement( XName.Get " PackageReleaseNotes" , toLines release.Notes))))
69+ let path = artifactsDir </> " Version.props"
70+ System.IO.File.WriteAllText( path, doc.ToString())
71+
4772Task " Init" [] <| fun _ ->
4873 CreateDir artifactsDir
74+ writeVersionProps ()
75+ CreateFSharpAssemblyInfo ( artifactsDir </> " Version.fs" ) [ Attribute.Version release.AssemblyVersion]
4976
50- // Targets
5177Task " Clean" [ " Init" ] <| fun _ ->
52- CleanDirs [ artifactsDir]
53-
54- Task " Build" [ " Init" ; " ?Clean" ] <| fun _ ->
55- MSBuild null " Build" [ " Configuration" , configuration] projects
56- |> ignore
57-
58- Task " RunTests" [ " Build" ] <| fun _ ->
78+ let objDirs = projects |> Seq.map( fun p -> System.IO.Path.GetDirectoryName( p) </> " obj" ) |> List.ofSeq
79+ CleanDirs ( artifactsDir :: objDirs)
80+
81+ Task " Build" [ " InstallDotNetCore" ; " Init" ; " ?Clean" ] <| fun _ ->
82+ DotNetCli.Build
83+ ( fun p ->
84+ { p with
85+ WorkingDir = srcDir
86+ Configuration = configuration
87+ ToolPath = dotnetExePath })
88+
89+ module ExpectoDotNetCli =
90+ open System.Diagnostics
91+
92+ let Expecto ( setParams : ExpectoParams -> ExpectoParams ) ( assemblies : string seq ) =
93+ let args = setParams ExpectoParams.DefaultParams
94+ use __ = assemblies |> separated " , " |> traceStartTaskUsing " Expecto"
95+ let runAssembly testAssembly =
96+ let argsString = sprintf " \" %s \" %s " testAssembly ( string args)
97+ let processTimeout = TimeSpan.MaxValue // Don't set a process timeout. The timeout is per test.
98+ let workingDir =
99+ if isNotNullOrEmpty args.WorkingDirectory
100+ then args.WorkingDirectory else DirectoryName testAssembly
101+ let exitCode =
102+ let info = ProcessStartInfo( dotnetExePath)
103+ info.WorkingDirectory <- workingDir
104+ info.Arguments <- argsString
105+ info.UseShellExecute <- false
106+ // Pass environment variables to the expecto console process in order to let it detect it's running on TeamCity
107+ // (it checks TEAMCITY_PROJECT_NAME <> null specifically).
108+ for name, value in environVars EnvironmentVariableTarget.Process do
109+ info.EnvironmentVariables.[ string name] <- string value
110+ use proc = Process.Start( info)
111+ proc.WaitForExit() // Don't set a process timeout. The timeout is per test.
112+ proc.ExitCode
113+ testAssembly, exitCode
114+ let res =
115+ assemblies
116+ |> Seq.map runAssembly
117+ |> Seq.filter( snd >> (<>) 0 )
118+ |> Seq.toList
119+ match res with
120+ | [] -> ()
121+ | failedAssemblies ->
122+ failedAssemblies
123+ |> List.map ( fun ( testAssembly , exitCode ) -> sprintf " Expecto test of assembly '%s ' failed. Process finished with exit code %d ." testAssembly exitCode)
124+ |> String.concat System.Environment.NewLine
125+ |> FailedTestsException |> raise
126+
127+ Task " RunTests" [ " Build" ] <| fun _ ->
59128 let nunitPath = rootDir </> @" packages" </> " NUnit.ConsoleRunner" </> " tools" </> " nunit3-console.exe"
60129 let testAssemblies = artifactsDir </> " bin" </> " *.Tests" </> configuration </> " *.Tests.dll"
61130 let testResults = artifactsDir </> " TestResults.xml"
62131
63- !! testAssemblies
64- |> NUnit3 ( fun p ->
65- { p with
66- ToolPath = nunitPath
67- TimeOut = TimeSpan.FromMinutes 20.
68- DisposeRunners = true
69- ResultSpecs = [ testResults] })
132+ [ artifactsDir </> " BlackFox.MasterOfFoo.Tests" </> configuration </> " netcoreapp2.0" </> " BlackFox.MasterOfFoo.Tests.dll" ]
133+ |> ExpectoDotNetCli.Expecto ( fun p ->
134+ { p with
135+ FailOnFocusedTests = true
136+ })
70137
71- AppVeyor.UploadTestResultsFile AppVeyor.NUnit3 testResults
138+ let nupkgDir = artifactsDir </> " BlackFox.MasterOfFoo " </> configuration
72139
73140Task " NuGet" [ " Build" ] <| fun _ ->
74- Paket.Pack <| fun p ->
75- { p with
76- OutputPath = artifactsDir
77- Version = release.NugetVersion
78- ReleaseNotes = toLines release.Notes
79- WorkingDir = librarySrcDir
80- BuildConfig = configuration
81- BuildPlatform = " AnyCPU" }
82- AppVeyor.PushArtifacts ( from artifactsDir ++ " *.nupkg" )
141+ DotNetCli.Pack
142+ ( fun p ->
143+ { p with
144+ WorkingDir = librarySrcDir
145+ Configuration = configuration
146+ ToolPath = dotnetExePath })
147+ let nupkg =
148+ nupkgDir
149+ </> ( sprintf " BlackFox.MasterOfFoo.%s .nupkg" release.NugetVersion)
150+
151+ AppVeyor.PushArtifacts [ nupkg]
83152
84153Task " PublishNuget" [ " NuGet" ] <| fun _ ->
85154 let key =
86155 match environVarOrNone " nuget-key" with
87156 | Some( key) -> key
88157 | None -> getUserPassword " NuGet key: "
89158
90- Paket.Push <| fun p -> { p with WorkingDir = artifactsDir ; ApiKey = key }
159+ Paket.Push <| fun p -> { p with WorkingDir = nupkgDir ; ApiKey = key }
91160
92161let zipFile = artifactsDir </> ( sprintf " BlackFox.MasterOfFoo-%s .zip" release.NugetVersion)
93162
@@ -99,7 +168,7 @@ Task "Zip" ["Build"] <| fun _ ->
99168 |> Zip libraryBinDir zipFile
100169 AppVeyor.PushArtifacts [ zipFile]
101170
102- #load " ../paket-files/fsharp/FAKE/modules/Octokit/Octokit.fsx"
171+ #load " ../paket-files/build/ fsharp/FAKE/modules/Octokit/Octokit.fsx"
103172
104173Task " GitHubRelease" [ " Zip" ] <| fun _ ->
105174 let user =
0 commit comments