-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.fsx
136 lines (113 loc) · 4.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
#load "tools/Cake.Bridge.0.0.4-alpha/content/cake.fsx"
//////////////////////////////////////////////////////////////////////
// NAMESPACE IMPORTS
//////////////////////////////////////////////////////////////////////
open Cake.Common
open Cake.Common.Diagnostics
open Cake.Common.IO
open Cake.Common.Tools.DotNetCore
open Cake.Common.Tools.DotNetCore.Build
open Cake.Common.Tools.DotNetCore.Pack
open Cake.Core
open Cake.Core.IO
open System
open CakeAdapter.CakeModule
// Execute script with: fsi build.fsx
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
let target = context.Argument("target", "Default")
let configuration = context.Argument("configuration", "Release")
//////////////////////////////////////////////////////////////////////
// GLOBALS
//////////////////////////////////////////////////////////////////////
let directoryPath = !> (context.Directory "./nuget")
let nugetRoot = context.MakeAbsolute directoryPath
type ProjectInfo =
{
AssemblyVersion : string
FileVersion : string
SemVersion : string
Solution : FilePath
}
let mutable projectInfo = None
let argumentCustomizer = Func<ProcessArgumentBuilder,ProcessArgumentBuilder> (fun args ->
let p = projectInfo.Value
args
.Append("/p:Version={0}" , p.SemVersion )
.Append("/p:AssemblyVersion={0}", p.AssemblyVersion )
.Append("/p:FileVersion={0}" , p.FileVersion ))
//////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
//////////////////////////////////////////////////////////////////////
setup (fun context ->
context.Information "Setting up..."
let solution =
match context.GetFiles "./src/*.sln" |> Seq.tryHead with
| Some solution -> solution
| None -> failwith "Failed to find solution"
let releaseNotes = context.ParseReleaseNotes(!> "./ReleaseNotes.md")
let assemblyVersion = string releaseNotes.Version
let fileVersion = assemblyVersion
let semVersion = assemblyVersion + "-alpha"
projectInfo <- Some {
AssemblyVersion = assemblyVersion
FileVersion = fileVersion
SemVersion = semVersion
Solution = solution
}
context.Information("Executing build {0}...", semVersion)
)
tearDown (fun context ->
context.Information "Tearing down..."
)
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
let clean =
task "Clean"
|> does (fun () ->
context.CleanDirectories("./src/**/bin/" + configuration)
context.CleanDirectories("./src/**/obj/" + configuration)
context.CleanDirectory nugetRoot
)
let restore =
task "Restore"
|> isDependentOn clean
|> does (fun () ->
context.DotNetCoreRestore projectInfo.Value.Solution.FullPath
)
let build =
task "Build"
|> isDependentOn restore
|> does (fun () ->
context.DotNetCoreBuild(
projectInfo.Value.Solution.FullPath ,
DotNetCoreBuildSettings(
Configuration = configuration ,
ArgumentCustomization = argumentCustomizer))
)
let pack =
task "Pack"
|> isDependentOn build
|> does (fun () ->
if context.DirectoryExists nugetRoot |> not then context.CreateDirectory nugetRoot
let projectFiles =
context.GetFiles "./src/**/*.fsproj"
|> Seq.filter (fun file -> file.FullPath.EndsWith "Tests" |> not)
|> Seq.toArray
for project in projectFiles do
context.DotNetCorePack(
project.FullPath ,
DotNetCorePackSettings(
Configuration = configuration ,
OutputDirectory = nugetRoot ,
NoBuild = true ,
ArgumentCustomization = argumentCustomizer))
)
task "Default"
|> isDependentOn pack
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
runTarget target