forked from ekonbenefits/dynamitey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.fsx
executable file
·197 lines (153 loc) · 5.87 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
#!/bin/sh
#if bin_sh
# Doing this because arguments can't be used with /usr/bin/env on linux, just mac
exec fsharpi --define:mono_posix --exec $0 $*
#endif
#if FSharp_MakeFile
(*
* Single File Crossplatform FSharp Makefile Bootstrapper
* Apache licensed - Copyright 2014 Jay Tuley <jay+code@tuley.name>
* v 2.0 https://gist.github.com/jbtule/11181987
*
* How to use:
* On Windows `fsi --exec build.fsx <buildtarget>
* *Note:* if you have trouble first run "%vs120comntools%\vsvars32.bat" or use the "Developer Command Prompt for VS201X"
* or install https://github.com/Iristyle/Posh-VsVars#posh-vsvars
*
* On Mac Or Linux `./build.fsx <buildtarget>`
* *Note:* But if you have trouble then use `sh build.fsx <buildtarget>`
*
*)
#I "packages/FAKE/tools"
#r "FakeLib.dll"
#r "System.Xml.Linq.dll"
open Fake
open System.Xml.Linq
open System.Xml.XPath
let sln = "./Dynamitey.sln"
let commonBuild target =
let buildMode = getBuildParamOrDefault "configuration" "Release"
let vsuffix = getBuildParamOrDefault "vsuffix" ""
let versionPrefix = "Version.props"
|> System.IO.File.ReadAllText
|> XDocument.Parse
|> (fun x -> x.XPathEvaluate("//VersionPrefix/text()"))
|> (fun x-> x :?> seq<obj>)
|> Seq.exactlyOne
|> sprintf "%A"
let vProp =
if System.Text.RegularExpressions.Regex.IsMatch(vsuffix, "^\d+$") then
"Version", versionPrefix + "." + vsuffix
else
"VersionSuffix", vsuffix
let setParams defaults =
{ defaults with
Verbosity = Some(Quiet)
Targets = [target]
Properties =
[
"Configuration", buildMode
vProp
]
}
build setParams sln
|> DoNothing
Target "Restore" (fun () ->
trace " --- Restore Packages --- "
//because nuget doesn't know how to find msbuild15 on linux
let restoreProj = fun args ->
directExec (fun info ->
info.FileName <- "msbuild"
info.Arguments <- "/t:restore " + args) |> ignore
sln |> restoreProj
)
Target "Clean" (fun () ->
trace " --- Cleaning stuff --- "
commonBuild "Clean"
)
Target "Build" (fun () ->
trace " --- Building the libs --- "
commonBuild "Build"
)
Target "Test" (fun () ->
trace " --- Test the libs --- "
let nunit3exe = "./packages/nunit.consolerunner/3.7.0/tools/nunit3-console.exe"
let buildMode = getBuildParamOrDefault "configuration" "Release"
let testDir = sprintf "./Tests/bin/%s/net462/" buildMode
let netExe, netAppVeyor,coreAppVeyor =
if buildServer = AppVeyor then
"nunit3-console","--result=myresults.xml;format=AppVeyor", "--logger=trx;LogFileName=testresults.trx"
else
nunit3exe,"--noresult",""
let s1 =
directExec (fun info ->
info.FileName <- netExe
info.Arguments <- sprintf "--labels=All %s --where=\"cat != Performance\" %s" netAppVeyor (testDir + "Tests.exe"))
let s2 =
directExec (fun info ->
info.FileName <- "dotnet"
info.Arguments <- sprintf "test Tests/Tests.csproj -f netcoreapp2.0 --no-build --no-restore --filter=TestCategory!=Performance %s --configuration=%s" coreAppVeyor buildMode)
let appveyor = environVarOrNone "APPVEYOR_JOB_ID"
match appveyor with
| Some(jobid) ->
use webClient = new System.Net.WebClient()
webClient.UploadFile(sprintf "https://ci.appveyor.com/api/testresults/mstest/%s" jobid,"./Tests/TestResults/testresults.trx") |> ignore
| None -> ()
if(not s1 || not s2) then
failwith "Tests failed"
)
"Restore"
==> "Build"
==> "Test"
RunTargetOrDefault "Test"
#else
open System
open System.IO
open System.Diagnostics
(* helper functions *)
#if mono_posix
#r "Mono.Posix.dll"
open Mono.Unix.Native
let applyExecutionPermissionUnix path =
let _,stat = Syscall.lstat(path)
Syscall.chmod(path, FilePermissions.S_IXUSR ||| stat.st_mode) |> ignore
#else
let applyExecutionPermissionUnix path = ()
#endif
let doesNotExist path =
path |> Path.GetFullPath |> File.Exists |> not
let execAt (workingDir:string) (exePath:string) (args:string seq) =
let processStart (psi:ProcessStartInfo) =
let ps = Process.Start(psi)
ps.WaitForExit ()
ps.ExitCode
let fullExePath = exePath |> Path.GetFullPath
applyExecutionPermissionUnix fullExePath
let exitCode = ProcessStartInfo(
fullExePath,
args |> String.concat " ",
WorkingDirectory = (workingDir |> Path.GetFullPath),
UseShellExecute = false)
|> processStart
if exitCode <> 0 then
exit exitCode
()
let exec = execAt Environment.CurrentDirectory
let downloadNugetTo path =
let fullPath = path |> Path.GetFullPath;
if doesNotExist fullPath then
printf "Downloading NuGet..."
use webClient = new System.Net.WebClient()
fullPath |> Path.GetDirectoryName |> Directory.CreateDirectory |> ignore
webClient.DownloadFile("https://dist.nuget.org/win-x86-commandline/latest/nuget.exe", path |> Path.GetFullPath)
printfn "Done."
let passedArgs = fsi.CommandLineArgs.[1..] |> Array.toList
(* execution script customize below *)
let makeFsx = fsi.CommandLineArgs.[0]
let nugetExe = ".nuget/NuGet.exe"
let fakeExe = "packages/FAKE/tools/FAKE.exe"
downloadNugetTo nugetExe
if doesNotExist fakeExe then
exec nugetExe ["install"; "fake"; "-OutputDirectory packages"; "-ExcludeVersion"]
exec fakeExe ([makeFsx; "-d:FSharp_MakeFile"] @ passedArgs)
#endif