forked from kentcb/KBCsv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.fsx
83 lines (73 loc) · 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
#I "Src/packages/FAKE/tools"
#r "FakeLib.dll"
open Fake
open Fake.AssemblyInfoFile
// properties
let projectName = "KBCsv"
let semanticVersion = "5.0.0"
let version = (>=>) @"(?<major>\d*)\.(?<minor>\d*)\.(?<build>\d*).*?" "${major}.${minor}.${build}.0" semanticVersion
let configuration = getBuildParamOrDefault "configuration" "Release"
let srcDir = "Src/"
let nugetSource = "https://www.nuget.org/api/v2/package"
let solutionPath = srcDir @@ projectName + ".sln"
Target "Restore" (fun _ ->
DotNetCli.Restore (fun p ->
{ p with
Project = solutionPath
})
)
Target "Build" (fun _ ->
// generate the shared assembly info
CreateCSharpAssemblyInfoWithConfig (srcDir @@ "AssemblyInfoCommon.cs")
[
Attribute.Version version
Attribute.FileVersion version
Attribute.Configuration configuration
Attribute.Company "Kent Boogaart"
Attribute.Product projectName
Attribute.Copyright "© Copyright. Kent Boogaart."
Attribute.Trademark ""
Attribute.Culture ""
Attribute.StringAttribute("NeutralResourcesLanguage", "en-US", "System.Resources")
Attribute.StringAttribute("AssemblyInformationalVersion", semanticVersion, "System.Reflection")
]
(AssemblyInfoFileConfig(false))
DotNetCli.Build (fun p ->
{ p with
Project = solutionPath
Configuration = configuration
AdditionalArgs =
[
"/property:Version=" + semanticVersion
]
})
)
Target "Test" (fun _ ->
let unitTestProjectDirs = [
srcDir @@ projectName + ".UnitTests"
srcDir @@ projectName + ".Extensions.UnitTests"
srcDir @@ projectName + ".Extensions.Data.UnitTests"
]
unitTestProjectDirs
|> Seq.map (fun unitTestProjectDir -> Shell.Exec("dotnet", "xunit -configuration " + configuration, unitTestProjectDir))
|> Seq.iter (fun result -> if result <> 0 then failwithf "Tests failed with exit code %d" result)
)
Target "Push" (fun _ ->
let packagePaths = [
srcDir @@ projectName @@ "bin" @@ configuration @@ projectName + "." + semanticVersion + ".nupkg"
srcDir @@ projectName + ".Extensions" @@ "bin" @@ configuration @@ projectName + ".Extensions." + semanticVersion + ".nupkg"
srcDir @@ projectName + ".Extensions.Data" @@ "bin" @@ configuration @@ projectName + ".Extensions.Data." + semanticVersion + ".nupkg"
]
packagePaths
|> Seq.map (fun packagePath -> Shell.Exec("dotnet", "nuget push " + packagePath + " --source " + nugetSource))
|> Seq.iter (fun result -> if result <> 0 then failwithf "Push failed with exit code %d" result)
)
Target "All"
DoNothing
// build order. Pass "-ev push true" to build script to push to NuGet
"Restore"
==> "Build"
==> "Test"
=?> ("Push", getEnvironmentVarAsBool "push")
==> "All"
RunTargetOrDefault "All"