forked from causiq/logary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.fsx
204 lines (168 loc) · 6.58 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
#r "paket: groupref Build //"
#nowarn "52"
#load "./.fake/build.fsx/intellisense.fsx"
#load "paket-files/build/eiriktsarpalis/snippets/SlnTools/SlnTools.fs"
open System
open System.IO
open Fake.Api
open Fake.BuildServer
open Fake.Core
open Fake.Core.TargetOperators
open Fake.DotNet
open Fake.IO
open Fake.IO.Globbing.Operators
open Fake.SystemHelper
open Fake.Tools
Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
let configuration =
Environment.environVarOrDefault "CONFIGURATION" "Release"
|> DotNet.BuildConfiguration.fromString
let release = ReleaseNotes.load "RELEASE_NOTES.md"
let testFramework = "netcoreapp3.1"
let dotnetExePath = "dotnet"
let githubToken = lazy(Environment.environVarOrFail "GITHUB_TOKEN")
let nugetToken = lazy(Environment.environVarOrFail "NUGET_TOKEN")
let pkgPath = Path.GetFullPath "./pkg"
BuildServer.install [
Travis.Installer
AppVeyor.Installer
]
let testProjects =
!! "src/tests/**/*.fsproj"
++ "src/services/*.Tests/*.fsproj"
++ "src/*.Tests/*.fsproj"
-- "src/tests/Logary.Targets.SSE.Tests/*.fsproj"
-- "src/tests/Logary.Targets.OpsGenie.Tests/*.fsproj"
let libProjects =
!! "src/targets/**/*.fsproj"
++ "src/adapters/**/*.fsproj"
++ "src/ingestion/**/*.fsproj"
++ "src/Logary/Logary.fsproj"
++ "src/Logary.Prometheus/Logary.Prometheus.fsproj"
++ "src/Logary.CSharp/Logary.CSharp.csproj"
Target.create "Clean" <| fun _ ->
!! "./**/bin/"
++ "./**/obj/"
++ pkgPath
|> Shell.cleanDirs
// This line actually ensures we get the correct version checked in instead of the one previously bundled with 'fake`
Git.CommandHelper.gitCommand "" "checkout .paket/Paket.Restore.targets"
Target.create "AssemblyInfo" (fun _ ->
[ yield "Logary", None
yield "Logary.Tests", None
yield "Logary.Facade", None
yield "Logary.Adapters.Facade", Some "adapters"
yield! Directory.GetDirectories "src/targets" |> Array.map Path.GetFileName |> Seq.map (fun x -> x, Some "targets")
yield! Directory.GetDirectories "src/adapters" |> Array.map Path.GetFileName |> Seq.map (fun x -> x, Some "adapters")
yield! Directory.GetDirectories "src/ingestion" |> Array.map Path.GetFileName |> Seq.map (fun x -> x, Some "ingestion")
yield "Logary.Facade.Tests", None
yield "Logary.Services.Rutta", Some "services"
]
|> Seq.iter (fun (proj, subPath) ->
[ AssemblyInfo.Title proj
AssemblyInfo.Product proj
AssemblyInfo.Version release.AssemblyVersion
AssemblyInfo.FileVersion release.AssemblyVersion
]
|> AssemblyInfoFile.createFSharp (
match subPath with
| None -> sprintf "src/%s/AssemblyInfo.fs" proj
| Some path -> sprintf "src/%s/%s/AssemblyInfo.fs" path proj)
)
)
let replace fromStr toStr path =
Shell.replaceInFiles [fromStr, toStr] [path]
Target.create "PaketFiles" (fun _ ->
replace "module FsMtParserFull" "module Logary.Internals.FsMtParserFull"
"paket-files/messagetemplates/messagetemplates-fsharp/src/FsMtParser/FsMtParserFull.fs"
replace "module TypeShape.Core.Core" "module Logary.Internals.TypeShape.Core.Core"
"paket-files/eiriktsarpalis/TypeShape/src/TypeShape/TypeShape.fs"
replace "module TypeShape.Core.Utils" "module Logary.Internals.TypeShape.Core.Utils"
"paket-files/eiriktsarpalis/TypeShape/src/TypeShape/Utils.fs"
replace "module Aether" "module Logary.Internals.Aether"
"paket-files/xyncro/aether/src/Aether/Aether.fs"
replace "module YoLo" "module internal Logary.YoLo"
"paket-files/haf/YoLo/YoLo.fs"
replace "module Hopac" "namespace Logary.Internals"
"paket-files/logary/RingBuffer/RingBuffer.fs"
replace "namespace Logary.Facade" "namespace Libryy.Logging"
"paket-files/logary/logary/src/Logary.Facade/Facade.fs"
replace "namespace Logary.Facade" "namespace Cibryy.Logging"
"paket-files/logary/logary/src/Logary.CSharp.Facade/Facade.cs"
replace "namespace Utilities" "namespace Logary.Internals"
"paket-files/haf/DVar/src/DVar/DVar.fs"
)
/// This also restores.
Target.create "Build" <| fun _ ->
let msbuildParams =
{ MSBuild.CliArguments.Create() with
Verbosity = Some Quiet
NoLogo = true
Properties = [ "Optimize", "true"; "DebugSymbols", "true"; "Version", release.AssemblyVersion ] }
let setParams (o: DotNet.BuildOptions) =
{ o with
Configuration = configuration
MSBuildParams = msbuildParams }
DotNet.build setParams "src/Logary.sln"
Target.create "Tests" (fun _ ->
let commandLine (file: string) =
let projectName = file.Substring(0, file.Length - ".fsproj".Length) |> Path.GetFileName
let path = Path.GetDirectoryName file
sprintf "%s/bin/%O/%s/%s.dll --summary" path configuration testFramework projectName
testProjects
|> Seq.iter (commandLine >> DotNet.exec id "" >> ignore))
Target.create "Pack" <| fun _ ->
let args =
{ MSBuild.CliArguments.Create() with
NoLogo = true
DoRestore = false
Properties = [
"Version", release.NugetVersion
"PackageReleaseNotes", String.toLines release.Notes
]
}
let pkgSln = SlnTools.createTempSolutionFile libProjects
let setParams (p: DotNet.PackOptions) =
{ p with
OutputPath = Some pkgPath
Configuration = configuration
MSBuildParams = args }
DotNet.pack setParams pkgSln
Target.create "Push" <| fun _ ->
let setParams (p: Paket.PaketPushParams) =
{ p with
WorkingDir = pkgPath
ApiKey = nugetToken.Value }
// for f in *.nupkg; do dotnet paket push --api-key $NUGET_TOKEN $f; done
Paket.push setParams
Target.create "CheckEnv" <| fun _ ->
ignore (githubToken.Value)
ignore (nugetToken.Value)
Target.create "Release" <| fun _ ->
let remote =
Git.CommandHelper.getGitResult "" "remote -v"
|> Seq.tryFind (fun s -> s.EndsWith "(push)" && s.Contains "logary/logary")
|> function None -> "[email protected]:logary/logary.git"
| Some s -> s.Split().[0]
Git.Staging.stageAll ""
Git.CommitMessage.setMessage "" (sprintf "Bump version to %s" release.NugetVersion)
Git.Branches.pushBranch "" remote (Git.Information.getBranchName "")
Git.Branches.tag "" release.NugetVersion
Git.Branches.pushTag "" remote release.NugetVersion
githubToken.Value
|> GitHub.createClientWithToken
|> GitHub.draftNewRelease "logary" "logary" release.NugetVersion
release.SemVer.PreRelease.IsSome release.Notes
|> GitHub.publishDraft
|> Async.RunSynchronously
"CheckEnv"
==> "Release"
"Clean"
==> "AssemblyInfo"
==> "PaketFiles"
==> "Build"
==> "Tests"
==> "Pack"
==> "Push"
==> "Release"
Target.runOrDefault "Pack"