-
Notifications
You must be signed in to change notification settings - Fork 31
/
build.fsx
223 lines (187 loc) · 7.54 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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
open Fake.DotNet
// --------------------------------------------------------------------------------------
// FAKE build script
// --------------------------------------------------------------------------------------
#r "paket:
source https://api.nuget.org/v3/index.json
nuget Fake.Core
nuget Fake.Core.Target
nuget Fake.Core.Environment
nuget Fake.Core.UserInput
nuget Fake.DotNet.Cli
nuget Fake.IO.FileSystem
nuget Fake.Core.ReleaseNotes //"
#load "./.fake/build.fsx/intellisense.fsx"
open Fake
open Fake.IO
open Fake.DotNet
open Fake.IO.Globbing.Operators
open Fake.Core.TargetOperators
open System
open System.Text
// --------------------------------------------------------------------------------------
// Build variables
// --------------------------------------------------------------------------------------
//let configuration = environVarOrDefault "CONFIGURATION" "Release"
let configuration = "Debug"
let buildDir = "./build/"
let appReferences = !! "CWTools/CWTools.fsproj"
let testReferences = !! "CWToolsTests/CWToolsTests.fsproj"
let mutable dotnetExePath = "dotnet"
let project = "cwtools"
let authors = "Thomas Boby"
let owners = "Thomas Boby"
let description = "A library for parsing, editing, and validating Paradox Interactive script files."
let release =
File.read "RELEASE_NOTES.md"
|> Fake.Core.ReleaseNotes.parse
// --------------------------------------------------------------------------------------
// Helpers
// --------------------------------------------------------------------------------------
// let run' timeout cmd args dir =
// if execProcess (fun info ->
// info.FileName <- cmd
// if not (String.IsNullOrWhiteSpace dir) then
// info.WorkingDirectory <- dir
// info.Arguments <- args
// ) timeout |> not then
// failwithf "Error while running '%s' with args: %s" cmd args
// let run = run' System.TimeSpan.MaxValue
// let runDotnet workingDir args =
// let result =
// ExecProcess (fun info ->
// info.FileName <- dotnetExePath
// info.WorkingDirectory <- workingDir
// info.Arguments <- args) TimeSpan.MaxValue
// if result <> 0 then failwithf "dotnet %s failed" args
open Fake.DotNet.NuGet
let packParameters name =
[ //"--no-build"
//"--no-restore"
sprintf "/p:Title=\"%s\"" project
"/p:PackageVersion=" + release.NugetVersion
sprintf "/p:Authors=\"%s\"" authors
sprintf "/p:Owners=\"%s\"" owners
"/p:PackageRequireLicenseAcceptance=false"
sprintf "/p:Description=\"%s\"" (description.Replace(",",""))
sprintf "/p:PackageReleaseNotes=\"%O\"" ((Core.String.toLines release.Notes).Replace(",",""))
// sprintf "/p:Copyright=\"%s\"" copyright
// sprintf "/p:PackageTags=\"%s\"" tags
// sprintf "/p:PackageProjectUrl=\"%s\"" projectUrl
// sprintf "/p:PackageIconUrl=\"%s\"" iconUrl
// sprintf "/p:PackageLicenseUrl=\"%s\"" licenceUrl
]
|> String.concat " "
let buildParams (release : bool) =
(fun (b : DotNet.BuildOptions) ->
{ b with
Common =
{
b.Common with
WorkingDirectory = "src/Main"
CustomParams = Some ((if release then "" else " /p:LinkDuringPublish=false"))
}
OutputPath = Some ("../../out/server/local")
Configuration = if release then DotNet.BuildConfiguration.Release else DotNet.BuildConfiguration.Debug
})
// --------------------------------------------------------------------------------------
// Targets
// --------------------------------------------------------------------------------------
Core.Target.create "Clean" (fun _ ->
Shell.cleanDirs [buildDir; "bin"]
appReferences
|> Seq.iter (fun p ->
let dir = System.IO.Path.GetDirectoryName p
DotNet.exec ( (fun (b : DotNet.Options) -> { b with WorkingDirectory = dir })) "clean" "" |> ignore
)
DotNet.exec id "clean" "" |> ignore
!! "**/obj/**/*.nuspec"
|> File.deleteAll
)
Core.Target.create "Restore" (fun _ ->
appReferences
|> Seq.iter (fun p ->
let dir = System.IO.Path.GetDirectoryName p
DotNet.restore id dir
)
)
Core.Target.create "Build" (fun _ ->
appReferences
|> Seq.iter (fun p ->
let dir = System.IO.Path.GetDirectoryName p
DotNet.build id dir
)
)
Core.Target.create "Test" (fun _ ->
testReferences
|> Seq.iter (fun p ->
let dir = System.IO.Path.GetDirectoryName p
DotNet.exec ( (fun (b : DotNet.Options) -> { b with WorkingDirectory = dir })) "run" "" |> ignore
)
)
Core.Target.create "Pack" (fun _ ->
!! "CWTools/CWTools.fsproj"
|> Seq.iter (fun proj ->
let path = proj.Substring(0, proj.Length - ".fsproj".Length)
printfn "%A" path
let name = System.IO.Path.GetFileName path
DotNet.exec id "pack" (
sprintf
"\"%s\" -o ./bin %s"
//"pack \"%s\" -c Debug -o ../bin %s"
proj (packParameters name)) |> ignore
)
// DotNetCli.RunCommand id (
// sprintf
// "pack './CWTools/CWTools.fsproj' -o ../bin %s"
// (packParameters "CWTools")
// )
)
// let packParameters name =
// [ //"--no-build"
// //"--no-restore"
// sprintf "/p:Title=\"%s\"" project
// "/p:PackageVersion=" + release.NugetVersion
// sprintf "/p:Authors=\"%s\"" authors
// sprintf "/p:Owners=\"%s\"" owners
// "/p:PackageRequireLicenseAcceptance=false"
// sprintf "/p:Description=\"%s\"" (description.Replace(",",""))
// sprintf "/p:PackageReleaseNotes=\"%O\"" ((Core.String.toLines release.Notes).Replace(",",""))
// // sprintf "/p:Copyright=\"%s\"" copyright
// // sprintf "/p:PackageTags=\"%s\"" tags
// // sprintf "/p:PackageProjectUrl=\"%s\"" projectUrl
// // sprintf "/p:PackageIconUrl=\"%s\"" iconUrl
// // sprintf "/p:PackageLicenseUrl=\"%s\"" licenceUrl
// ]
// |> String.concat " "
Core.Target.create "PackageTool" (fun _ ->
!! "**/output/**/*.nupkg"
|> File.deleteAll
// DotNet.pack (fun po -> { po with Configuration = Fake.DotNet.DotNet.BuildConfiguration.Release } ) "CWToolsCLI/CWToolsCLI.fsproj"
DotNet.exec id "pack" (sprintf " ./CWToolsCLI/CWToolsCLI.fsproj -c Release -o ./CWToolsCLI/output") |> ignore
)
Core.Target.create "PublishTool" (fun _ ->
let token =
match Fake.Core.Environment.environVarOrDefault "NUGET_ACCESS_KEY" System.String.Empty with
| s when not (String.IsNullOrWhiteSpace s) -> s
| _ -> Fake.Core.UserInput.getUserPassword "NUGET token: "
DotNet.exec (fun o -> { o with WorkingDirectory = "./CWToolsCLI/output"}) "nuget" (sprintf " push *.nupkg -k %s -s https://api.nuget.org/v3/index.json" token) |> ignore
)
// <projectUrl>https://github.com/tboby/cwtools</projectUrl>
// <licenseUrl>https://github.com/tboby/cwtools/blob/master/LICENSE</licenseUrl>
// <iconUrl>https://raw.githubusercontent.com/tboby/cwtools-vscode/master/docs/cwtools_logo.png</iconUrl>
// --------------------------------------------------------------------------------------
// Build order
// --------------------------------------------------------------------------------------
"Clean"
==> "Restore"
==> "Pack"
"Clean"
==> "Restore"
==> "Build"
"Clean"
==> "Restore"
==> "Build"
==> "PackageTool"
==> "PublishTool"
Fake.Core.Target.runOrDefaultWithArguments "Build"