forked from ionide/FsAutoComplete
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.fsx
222 lines (178 loc) · 7.31 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
#r "paket: groupref build //"
#load ".fake/build.fsx/intellisense.fsx"
// open Fake
open Fake.Core
open Fake.IO
open Fake.IO.FileSystemOperators
open Fake.IO.Globbing.Operators
open Fake.DotNet
open Fake.Core.TargetOperators
open Fake.Api
open Fake.Tools
let project = "FsAutoComplete"
// Read additional information from the release notes document
let release = ReleaseNotes.load "RELEASE_NOTES.md"
let configuration = Environment.environVarOrDefault "configuration" "Release"
let buildDir = "src" </> project </> "bin" </> "Debug"
let buildReleaseDir = "src" </> project </> "bin" </> "Release"
let pkgsDir = "bin" </> "pkgs"
let releaseArchiveNetCore = pkgsDir </> "fsautocomplete.netcore.zip"
let gitOwner = "fsharp"
let gitName = project
let gitHome = "https://github.com/" + gitOwner
Target.initEnvironment ()
let fsacAssemblies =
"FsAutoComplete|FsAutoComplete.Core|FsAutoComplete.BackgroundServices|LanguageServerProtocol"
let versionProp = "Version", release.AssemblyVersion
let packAsToolProp = "PackAsTool", "true"
let latestReleaseNotesProp = "PackageReleaseNotes", release.Notes |> String.concat "\n"
Target.create "LspTest" (fun _ ->
let msbuildCli : Fake.DotNet.MSBuild.CliArguments =
{ MSBuild.CliArguments.Create() with
Properties =
[ "AltCover", "true"
// "AltCoverAssemblyFilter", fsacAssemblies
"AltCoverAssemblyExcludeFilter", "System.Reactive|FSharp.Compiler.Service|Ionide.ProjInfo|FSharp.Analyzers|Analyzer|Humanizer|FSharp.Core|Dapper|FSharp.DependencyManager|FsAutoComplete.Tests.Lsp"
versionProp
latestReleaseNotesProp
]
}
let testOpts (opts: DotNet.TestOptions) =
{ opts with Configuration = DotNet.BuildConfiguration.Release
RunSettingsArguments = Some ("Expecto.fail-on-focused-tests=true")
MSBuildParams = msbuildCli }
DotNet.test testOpts "./test/FsAutoComplete.Tests.Lsp/FsAutoComplete.Tests.Lsp.fsproj"
)
Target.create "Coverage" (fun _ ->
DotNet.exec id "reportgenerator" "-reports:test/FsAutoComplete.Tests.Lsp/coverage.xml -reporttypes:Html;HtmlSummary -targetdir:./coverage"
|> fun r -> if not r.OK then failwithf "Errors while generating coverage report: %A" r.Errors
)
Target.create "ReleaseArchive" (fun _ ->
Shell.cleanDirs [ "bin/pkgs" ]
Directory.ensure "bin/pkgs"
!! "bin/release_netcore/**/*"
|> Zip.zip "bin/release_netcore" releaseArchiveNetCore
!! (sprintf "bin/release_as_tool/fsautocomplete.%s.nupkg" release.AssemblyVersion)
|> Shell.copy "bin/pkgs"
)
Target.create "LocalRelease" (fun _ ->
Directory.ensure "bin/release_netcore"
Shell.cleanDirs [ "bin/release_netcore" ]
Shell.cleanDirs [ "bin/release_netcore" ]
DotNet.publish (fun p ->
{ p with
OutputPath = Some (__SOURCE_DIRECTORY__ </> "bin/release_netcore")
Framework = Some "net5.0"
Configuration = DotNet.BuildConfiguration.fromString configuration
MSBuildParams = { MSBuild.CliArguments.Create () with Properties = [ versionProp ] } }) "src/FsAutoComplete"
Directory.ensure "bin/release_as_tool"
Shell.cleanDirs [ "bin/release_as_tool" ]
DotNet.pack (fun p ->
{ p with
OutputPath = Some (__SOURCE_DIRECTORY__ </> "bin/release_as_tool")
Configuration = DotNet.BuildConfiguration.fromString configuration
MSBuildParams = { MSBuild.CliArguments.Create () with Properties = [ versionProp; packAsToolProp; latestReleaseNotesProp ] } }) "src/FsAutoComplete"
)
Target.create "Clean" (fun _ ->
Shell.cleanDirs [ buildDir; buildReleaseDir; pkgsDir ]
)
Target.create "Restore" (fun _ ->
DotNet.restore id ""
)
Target.create "Build" (fun _ ->
DotNet.build (fun p ->
{ p with
Configuration = DotNet.BuildConfiguration.fromString configuration
MSBuildParams = { MSBuild.CliArguments.Create () with Properties = [versionProp ] } }) "FsAutoComplete.sln"
)
let ensureGitUser user email =
match Fake.Tools.Git.CommandHelper.runGitCommand "." "config user.name" with
| true, [username], _ when username = user -> ()
| _, _, _ ->
Fake.Tools.Git.CommandHelper.directRunGitCommandAndFail "." (sprintf "config user.name %s" user)
Fake.Tools.Git.CommandHelper.directRunGitCommandAndFail "." (sprintf "config user.email %s" email)
Target.create "ReplaceFsLibLogNamespaces" <| fun _ ->
let replacements =
[ "FsLibLog\\n", "FsAutoComplete.Logging\n"
"FsLibLog\\.", "FsAutoComplete.Logging" ]
replacements
|> List.iter (fun (``match``, replace) ->
(!! "paket-files/TheAngryByrd/FsLibLog/**/FsLibLog*.fs")
|> Shell.regexReplaceInFilesWithEncoding ``match`` replace System.Text.Encoding.UTF8
)
Target.create "ReleaseGitHub" (fun _ ->
let remote =
Git.CommandHelper.getGitResult "" "remote -v"
|> Seq.filter (fun (s: string) -> s.EndsWith("(push)"))
|> Seq.tryFind (fun (s: string) -> s.Contains(gitOwner + "/" + gitName))
|> function None -> gitHome + "/" + gitName | Some (s: string) -> s.Split().[0]
let user =
match Environment.environVarOrDefault "github-user" "" with
| s when not (String.isNullOrWhiteSpace s) -> s
| _ -> UserInput.getUserInput "Username: "
let email =
match Environment.environVarOrDefault "user-email" "" with
| s when not (String.isNullOrWhiteSpace s) -> s
| _ -> UserInput.getUserInput "Email: "
ensureGitUser user email
Git.Staging.stageAll ""
Git.Commit.exec "" (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
let client =
let token =
match Environment.environVarOrNone "github-token" with
| Some s when not (String.isNullOrWhiteSpace s) -> s
| _ -> UserInput.getUserInput "Token: "
GitHub.createClientWithToken token
let notes =
release.Notes
|> List.map (fun s -> "* " + s)
let files = !! (pkgsDir </> "*.*")
// release on github
let cl =
client
|> GitHub.draftNewRelease gitOwner gitName release.NugetVersion (release.SemVer.PreRelease <> None) notes
(cl,files)
||> Seq.fold (fun acc e -> GitHub.uploadFile e acc)
|> GitHub.publishDraft
|> Async.RunSynchronously
)
Target.create "PublishTool" (fun _ ->
let apikey =
match Environment.environVarOrNone "nuget-key" with
| Some s when not (String.isNullOrWhiteSpace s) -> s
| _ -> UserInput.getUserInput "Token: "
let configurePush (p: DotNet.NuGetPushOptions) =
{ p with
PushParams = {
p.PushParams with
ApiKey = Some apikey
PushTrials = 3
Source = Some "https://api.nuget.org/v3/index.json"
} }
!! (pkgsDir </> "*.nupkg")
|> Seq.iter (DotNet.nugetPush configurePush)
)
Target.create "NoOp" ignore
Target.create "Test" ignore
Target.create "All" ignore
Target.create "Release" ignore
"Restore"
==> "ReplaceFsLibLogNamespaces"
==> "Build"
"Build"
==> "LspTest"
==> "Coverage"
==> "Test"
==> "All"
"ReplaceFsLibLogNamespaces"
==> "LocalRelease"
==> "ReleaseArchive"
==> "ReleaseGitHub"
==> "PublishTool"
==> "Release"
"ReleaseArchive"
==> "All"
Target.runOrDefaultWithArguments "Build"