forked from SuaveIO/suave
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.fsx
147 lines (122 loc) · 4.48 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
#!/usr/bin/env fsharpi
#r "paket:
nuget FSharp.Core
nuget Fake.Api.GitHub
nuget Fake.DotNet.MSBuild
nuget Fake.DotNet.Cli
nuget Fake.DotNet.Paket
nuget Fake.DotNet.AssemblyInfoFile
nuget Fake.DotNet.Testing.Expecto
nuget Fake.Core.Target
nuget Fake.Core.Process
nuget Fake.Core.String
nuget Fake.Core.ReleaseNotes
nuget Fake.IO.FileSystem
nuget Fake.Tools.Git //"
#load ".fake/build.fsx/intellisense.fsx"
open Fake
open Fake.Core
open Fake.DotNet
open Fake.IO
open Fake.IO.Globbing.Operators
open Fake.IO.FileSystemOperators
open System
open System.IO
open System.Text
open Fake.Tools
open Fake.Api
Console.OutputEncoding <- Encoding.UTF8
// brew install libuv
let release = ReleaseNotes.load "RELEASE_NOTES.md"
let Configuration = Environment.environVarOrDefault "CONFIGURATION" "Release"
// Lazily install DotNet SDK in the correct version if not available
let install = lazy DotNet.install (fun opt -> { opt with Version = DotNet.Version "3.1.404" })
// Define general properties across various commands (with arguments)
let inline withWorkDir wd =
DotNet.Options.lift install.Value
>> DotNet.Options.withWorkingDirectory wd
>> DotNet.Options.withCustomParams (Some (sprintf "/p:Configuration=%s" Configuration))
// Set general properties without arguments
let inline dotnetSimple arg = DotNet.Options.lift install.Value arg
let projects =
!! "src/**/Suave*.fsproj"
-- "src/*.Tests/*.fsproj"
-- "src/*.IO/*.fsproj"
Target.create "Clean" <| fun _ ->
!! "src/**/bin"
++ "src/**/obj"
|> Shell.cleanDirs
Target.create "Restore" <| fun _ ->
DotNet.restore dotnetSimple "Suave.sln"
Target.create "AsmInfo" <| fun _ ->
projects |> Seq.iter (fun project ->
let dir = Path.GetDirectoryName project
let name = Path.GetFileNameWithoutExtension project
let filePath = dir </> "AssemblyInfo.fs"
AssemblyInfoFile.createFSharp filePath
[ AssemblyInfo.Title name
AssemblyInfo.Description "Suave — a smooth, open source, F# web server."
AssemblyInfo.Version release.AssemblyVersion
AssemblyInfo.FileVersion release.AssemblyVersion
AssemblyInfo.Metadata ("Commit", Git.Information.getCurrentHash ())
])
Target.create "Build" <| fun _ ->
DotNet.build dotnetSimple "Suave.sln"
Target.create "Tests" <| fun _ ->
let path = "src" </> "Suave.Tests"
let res = DotNet.exec id "run" (sprintf "--framework netcoreapp3.1 --project %s -- --summary --sequenced" path)
if not res.OK then
res.Errors |> Seq.iter (eprintfn "%s")
failwith "Tests failed."
Target.create "Pack" <| fun _ ->
let pkg = Path.GetFullPath "./pkg"
let props (project: string) (p: Paket.PaketPackParams) =
{ p with OutputPath = pkg
IncludeReferencedProjects = true
Symbols = true
ProjectUrl = "https://suave.io"
Version = release.SemVer.ToString()
WorkingDir = Path.GetDirectoryName project
ReleaseNotes = String.Join("\n", release.Notes)
//LicenseUrl = "https://opensource.org/licenses/Apache-2.0"
TemplateFile = "paket.template" }
projects
|> Seq.iter (fun project -> DotNet.Paket.pack (props project))
Target.create "Push" <| fun _ ->
Paket.push (fun p ->
{ p with WorkingDir = "./pkg"
ApiKey = Environment.environVarOrFail "NUGET_KEY" })
Target.create "CheckEnv" <| fun _ ->
ignore (Environment.environVarOrFail "NUGET_KEY")
ignore (Environment.environVarOrFail "GITHUB_TOKEN")
Target.create "Release" <| fun _ ->
let gitOwner, gitName = "SuaveIO", "suave"
let gitOwnerName = gitOwner + "/" + gitName
let remote =
Git.CommandHelper.getGitResult "" "remote -v"
|> Seq.tryFind (fun s -> s.EndsWith "(push)" && s.Contains gitOwnerName)
|> function None -> "[email protected]:SuaveIO/suave.git"
| Some s -> s.Split().[0]
Git.Staging.stageAll ""
Git.Commit.exec "" (sprintf "Release of v%O" release.SemVer)
Git.Branches.pushBranch "" remote (Git.Information.getBranchName "")
let tag = sprintf "v%O" release.SemVer
Git.Branches.tag "" tag
Git.Branches.pushTag "" remote tag
GitHub.createClientWithToken (Environment.environVarOrFail "GITHUB_TOKEN")
|> GitHub.draftNewRelease gitOwner gitName release.NugetVersion
(Option.isSome release.SemVer.PreRelease) release.Notes
|> GitHub.publishDraft
|> Async.RunSynchronously
// Dependencies
open Fake.Core.TargetOperators
"CheckEnv"
==> "Release"
"Clean"
==> "Restore"
==> "AsmInfo"
==> "Build"
==> "Tests"
==> "Pack"
==> "Release"
Target.runOrDefault "Tests"