forked from demystifyfp/FsToolkit.ErrorHandling
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.fsx
211 lines (172 loc) · 6.06 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
#r "paket: groupref Build //"
#load "./.fake/build.fsx/intellisense.fsx"
open Fake.Api
open Fake.Core
open Fake.IO
open Fake.DotNet
open Fake.IO.FileSystemOperators
open Fake.Core.TargetOperators
open Fake.DotNet.Testing
open Fake.IO.Globbing.Operators
open Fake.Tools
open Fake.JavaScript
open System
open System.IO
let project = "FsToolkit.ErrorHandling"
let summary = "An opinionated error handling library for F#"
let configuration = "Release"
let solutionFile = "FsToolkit.ErrorHandling.sln"
let gitOwner ="demystifyfp"
let distDir = __SOURCE_DIRECTORY__ @@ "bin"
let distGlob = distDir @@ "*.nupkg"
let githubToken = Environment.environVarOrNone "GITHUB_TOKEN"
Option.iter(TraceSecrets.register "<GITHUB_TOKEN>" )
Target.create "Clean" (fun _ ->
!! "bin"
++ "src/**/bin"
++ "tests/**/bin"
++ "src/**/obj"
++ "tests/**/obj"
|> Shell.cleanDirs
[
"paket-files/paket.restore.cached"
]
|> Seq.iter Shell.rm
)
Target.create "Build" (fun _ ->
let setParams (defaults:DotNet.BuildOptions) =
{ defaults with
NoRestore = true
Configuration = DotNet.BuildConfiguration.fromString configuration}
DotNet.build setParams solutionFile
)
Target.create "Restore" (fun _ ->
DotNet.restore id solutionFile
)
Target.create "NpmRestore" (fun _ ->
Npm.install id
)
let runTestAssembly setParams testAssembly =
let exitCode =
let fakeStartInfo testAssembly (args : Expecto.Params) =
let workingDir =
if String.isNotNullOrEmpty args.WorkingDirectory
then args.WorkingDirectory else Fake.IO.Path.getDirectory testAssembly
(fun (info: ProcStartInfo) ->
{ info with
FileName = "dotnet"
Arguments = sprintf "%s %s" testAssembly (string args)
WorkingDirectory = workingDir } )
let execWithExitCode testAssembly argsString timeout =
Process.execSimple (fakeStartInfo testAssembly argsString) timeout
execWithExitCode testAssembly (setParams Expecto.Params.DefaultParams) TimeSpan.MaxValue
testAssembly, exitCode
let runTests setParams testAssemblies =
let details = testAssemblies |> String.separated ", "
use __ = Trace.traceTask "Expecto" details
let res =
testAssemblies
|> Seq.map (runTestAssembly setParams)
|> Seq.filter( snd >> (<>) 0)
|> Seq.toList
match res with
| [] -> ()
| failedAssemblies ->
failedAssemblies
|> List.map (fun (testAssembly,exitCode) ->
sprintf "Expecto test of assembly '%s' failed. Process finished with exit code %d." testAssembly exitCode )
|> String.concat System.Environment.NewLine
|> Fake.Testing.Common.FailedTestsException |> raise
__.MarkSuccess()
let testAssemblies = "tests/**/bin" </> configuration </> "**" </> "*Tests.dll"
Target.create "RunTests" (fun _ ->
runTests id (!! testAssemblies)
)
let runFableTests _ =
Npm.test id
Target.create "RunFableTests" runFableTests
let release = ReleaseNotes.load "RELEASE_NOTES.md"
Target.create "AssemblyInfo" (fun _ ->
let getAssemblyInfoAttributes projectName =
[ AssemblyInfo.Title (projectName)
AssemblyInfo.Product project
AssemblyInfo.Description summary
AssemblyInfo.Version release.AssemblyVersion
AssemblyInfo.FileVersion release.AssemblyVersion
AssemblyInfo.Configuration configuration ]
let getProjectDetails projectPath =
let projectName = Path.GetFileNameWithoutExtension(projectPath)
( projectPath,
projectName,
Path.GetDirectoryName(projectPath),
(getAssemblyInfoAttributes projectName)
)
!! "src/**/*.??proj"
|> Seq.map getProjectDetails
|> Seq.iter (fun (_, _, folderName, attributes) ->
AssemblyInfoFile.createFSharp (folderName </> "AssemblyInfo.fs") attributes)
)
let releaseNotes = String.toLines release.Notes
Target.create "NuGet" (fun _ ->
["src/FsToolkit.ErrorHandling"
"src/FsToolkit.ErrorHandling.TaskResult"
"src/FsToolkit.ErrorHandling.JobResult"]
|> Seq.iter (
DotNet.pack(fun p ->
{ p with
// ./bin from the solution root matching the "PublishNuget" target WorkingDir
OutputPath = Some distDir
Configuration = DotNet.BuildConfiguration.Release
MSBuildParams = {MSBuild.CliArguments.Create() with
// "/p" (property) arguments to MSBuild.exe
Properties = [("Version", release.NugetVersion)
("PackageReleaseNotes", releaseNotes)]}}))
)
Target.create "PublishNuget" (fun _ ->
Paket.push(fun p ->
{ p with
ToolType = ToolType.CreateLocalTool()
PublishUrl = "https://www.nuget.org"
WorkingDir = distDir })
)
let remote = Environment.environVarOrDefault "FSTK_GIT_REMOTE" "origin"
Target.create "GitRelease"(fun _ ->
Git.Staging.stageAll ""
Git.Commit.exec "" (sprintf "Bump version to %s\n\n%s" release.NugetVersion releaseNotes)
Git.Branches.push ""
Git.Branches.tag "" release.NugetVersion
Git.Branches.pushTag "" remote release.NugetVersion
)
Target.create "GitHubRelease" (fun _ ->
let token =
match githubToken with
| Some s -> s
| _ -> failwith "please set the github_token environment variable to a github personal access token with repo access."
let files = !! distGlob
GitHub.createClientWithToken token
|> GitHub.draftNewRelease gitOwner project release.NugetVersion (release.SemVer.PreRelease <> None) (releaseNotes |> Seq.singleton)
|> GitHub.uploadFiles files
|> GitHub.publishDraft
|> Async.RunSynchronously
)
Target.create "Release" ignore
Target.create "UpdateDocs" (fun _ ->
Git.Staging.stageAll ""
Git.Commit.exec "" "update docs"
Git.Branches.push ""
)
// *** Define Dependencies ***
"Clean"
==> "AssemblyInfo"
==> "Restore"
==> "NpmRestore"
==> "Build"
==> "RunTests"
==> "RunFableTests"
==> "NuGet"
==> "PublishNuGet"
==> "GitRelease"
==> "GitHubRelease"
==> "Release"
// *** Start Build ***
Target.runOrDefaultWithArguments "Build"