forked from Dzoukr/Dapper.FSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.fsx
64 lines (53 loc) · 2.1 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
#r "paket: groupref Build //"
#load ".fake/build.fsx/intellisense.fsx"
open System.IO
open Fake.IO
open Fake.Core
open Fake.DotNet
open Fake.IO.FileSystemOperators
open Fake.Core.TargetOperators
module Tools =
let private findTool tool winTool =
let tool = if Environment.isUnix then tool else winTool
match ProcessUtils.tryFindFileOnPath tool with
| Some t -> t
| _ ->
let errorMsg =
tool + " was not found in path. " +
"Please install it and make sure it's available from your path. "
failwith errorMsg
let private runTool (cmd:string) args workingDir =
let arguments = args |> String.split ' ' |> Arguments.OfArgs
Command.RawCommand (cmd, arguments)
|> CreateProcess.fromCommand
|> CreateProcess.withWorkingDirectory workingDir
|> CreateProcess.ensureExitCode
|> Proc.run
|> ignore
let dotnet cmd workingDir =
let result =
DotNet.exec (DotNet.Options.withWorkingDirectory workingDir) cmd ""
if result.ExitCode <> 0 then failwithf "'dotnet %s' failed in %s" cmd workingDir
// Targets
let clean proj = [ proj </> "bin"; proj </> "obj" ] |> Shell.cleanDirs
let createNuget proj =
clean proj
Tools.dotnet "restore --no-cache" proj
Tools.dotnet "pack -c Release" proj
let publishNuget proj =
createNuget proj
let nugetKey =
match Environment.environVarOrNone "NUGET_KEY" with
| Some nugetKey -> nugetKey
| None -> failwith "The Nuget API key must be set in a NUGET_KEY environmental variable"
let nupkg =
Directory.GetFiles(proj </> "bin" </> "Release")
|> Seq.head
|> Path.GetFullPath
Tools.dotnet (sprintf "nuget push %s -s nuget.org -k %s" nupkg nugetKey) proj
Target.create "Pack" (fun _ -> "src" </> "Dapper.FSharp" |> createNuget)
Target.create "Publish" (fun _ -> "src" </> "Dapper.FSharp" |> publishNuget)
Target.create "Test" (fun _ -> Tools.dotnet "run" ("tests" </> "Dapper.FSharp.Tests"))
"Test" ==> "Pack"
"Test" ==> "Publish"
Target.runOrDefaultWithArguments "Test"