-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.fsx
77 lines (63 loc) · 2.18 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
#r "paket:
nuget Fake.BuildServer.TeamCity
nuget Fake.Core.Target
nuget Fake.Core.UserInput
nuget Fake.DotNet.Cli //"
#load "./.fake/build.fsx/intellisense.fsx"
open Fake.Core
open Fake.DotNet
open Fake.BuildServer
open Fake.DotNet.NuGet.NuGet
let packageProject = "Acadian.FSharp"
BuildServer.install [TeamCity.Installer]
let buildVersion = lazy (
if BuildServer.isLocalBuild then
let input = UserInput.getUserInput "Package Version: "
if input |> SemVer.isValid |> not then
failwithf "%s is not a valid Semantic Version" input
input
else BuildServer.buildVersion
)
let nugetApiKey = lazy (
match BuildServer.buildServer with
| TeamCity ->
TeamCity.BuildParameters.Configuration
|> Map.tryFind "NugetPublishApiKey"
|> Option.defaultWith (fun () ->
failwith "Nuget.org API key not found. Please set Config Param 'NugetPublishApiKey' in TeamCity."
)
| _ ->
Environment.environVarOrFail "NugetPublishApiKey"
)
let setVersion (a: MSBuild.CliArguments) =
let props = ["PackageVersion";"Version";"FileVersion"]
{ a with Properties = props |> List.map (fun p -> p, buildVersion.Value) }
let failOnNonZero failMessage exitCode =
if exitCode <> 0 then failwith failMessage
Target.create "Build" (fun _ ->
DotNet.build (fun args -> { args with Configuration = DotNet.Release }) ""
)
Target.create "Test" (fun _ ->
DotNet.test (fun args -> { args with Configuration = DotNet.Release }) ""
)
Target.create "Pack" (fun _ ->
DotNet.pack (fun args ->
{ args with
Configuration = DotNet.Release
OutputPath = Some "nupkgs"
MSBuildParams = args.MSBuildParams |> setVersion
}
) packageProject
)
Target.create "Publish" (fun _ ->
let path = sprintf "nupkgs/%s.%s.nupkg" packageProject buildVersion.Value
let pushParams (p: NuGetPushParams) =
{ p with Source = Some "https://api.nuget.org/v3/index.json"; ApiKey = Some nugetApiKey.Value }
DotNet.nugetPush (fun o -> { o with PushParams = o.PushParams |> pushParams }) path
)
open Fake.Core.TargetOperators
"Build"
==> "Test"
==> "Pack"
==> "Publish"
Target.runOrDefault "Build"