This repository has been archived by the owner on Jul 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuildHelpers.fsx
116 lines (89 loc) · 4.19 KB
/
buildHelpers.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
#r "./packages/FAKE/tools/FakeLib.dll"
open System
open System.IO
open Fake
open Fake.OctoTools
open Fake.Testing.XUnit2
let private splitOnSemiColon (paramValue: string) = paramValue.Split([|";"|], StringSplitOptions.RemoveEmptyEntries)
let getRequiredBuildParam = fun paramName ->
if not (hasBuildParam paramName) then failwithf "Parameter '%s' must be specified to run current target" paramName
getBuildParam paramName
let getBuildParamArray paramName = getBuildParam paramName |> splitOnSemiColon
let getRequiredBuildParamArray paramName = getRequiredBuildParam paramName |> splitOnSemiColon
let SetAssemblyVersion() =
let version = getRequiredBuildParam "version"
let semver = getRequiredBuildParam "semver"
BulkReplaceAssemblyInfoVersions "./src" (fun f ->
{f with
AssemblyVersion = version
AssemblyInformationalVersion = semver})
module Nuget =
let private Publish = fun package ->
let nugetApiKey = getRequiredBuildParam "nugetApiKey"
let result = ExecProcess (fun info ->
info.FileName <- ".nuget/nuget.exe"
info.Arguments <- sprintf "push \"%s\" %s" package nugetApiKey) (TimeSpan.FromMinutes 5.0)
if result <> 0 then failwithf "nuget.exe returned with a non-zero exit code"
let private CreatePackage = fun projectName deployDirectory ->
let csprojFile = "src/" + projectName + "/" + projectName + ".csproj"
let version = getRequiredBuildParam "packageversion"
let result = ExecProcess (fun info ->
info.FileName <- ".nuget/nuget.exe"
info.Arguments <- sprintf "pack \"%s\" -OutputDirectory \"%s\" -Version %s -IncludeReferencedProjects -Properties Configuration=Release -Properties Platform=AnyCPU" csprojFile deployDirectory version) (TimeSpan.FromMinutes 5.0)
if result <> 0 then failwithf "nuget.exe returned with a non-zero exit code"
let CreatePackages = fun projectNames deployDirectory ->
projectNames |> Seq.iter(fun (projectName) ->
CreatePackage projectName deployDirectory
)
let PublishPackages = fun sourceDir ->
!! (sourceDir + "*.nupkg")
|> Seq.iter Publish
module Build =
type BuildParams =
{
Configuration : string
BuildDirectory : string
ProjectReferences : FileIncludes
Version : string
}
let BuildDefaults() =
{ Configuration = "Release"
BuildDirectory = null
ProjectReferences = !!"./*.csproj"
Version = (getRequiredBuildParam "version") }
let CleanProject = fun projectName ->
let binDirectory = "src/" + projectName + "/bin/"
let objDirectory = "src/" + projectName + "/obj/"
DeleteDirs[binDirectory;objDirectory]
let Build = fun setParams ->
let parameters = BuildDefaults() |> setParams
let buildParameters defaults =
[
"Configuration", parameters.Configuration
"Platform", "AnyCPU"
]
MSBuildWithProjectProperties parameters.BuildDirectory "Build" buildParameters parameters.ProjectReferences |> ignore
module Test =
type TestParams =
{
TestDirectory : string
ToolPath : string
ProjectReferences : FileIncludes
TestAssemblyPattern : string
}
let TestDefaults() =
{ TestDirectory = null
ToolPath = "./packages/xunit.runner.console/tools/xunit.console.exe"
ProjectReferences = !!"*Tests/*.csproj"
TestAssemblyPattern = "/*Tests.dll" }
let RunTests = fun setParams->
let parameters = TestDefaults() |> setParams
Build.Build (fun p ->
{ p with
BuildDirectory = parameters.TestDirectory
ProjectReferences = parameters.ProjectReferences })
let testAssemblies = !! (parameters.TestDirectory + parameters.TestAssemblyPattern)
if not (Seq.isEmpty testAssemblies) then
testAssemblies |> xUnit2 (fun p ->
{p with
ToolPath = parameters.ToolPath })