forked from ionide/ionide-vscode-fsharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.fsx
245 lines (187 loc) · 6.55 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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
// --------------------------------------------------------------------------------------
// FAKE build script
// --------------------------------------------------------------------------------------
#I "packages/FAKE/tools"
#r "FakeLib.dll"
open System
open System.Diagnostics
open System.IO
open Fake
open Fake.Git
open Fake.ProcessHelper
open Fake.ReleaseNotesHelper
open Fake.ZipHelper
// Git configuration (used for publishing documentation in gh-pages branch)
// The profile where the project is posted
let gitOwner = "ionide"
let gitHome = "https://github.com/" + gitOwner
// The name of the project on GitHub
let gitName = "ionide-vscode-fsharp"
// The url for the raw files hosted
let gitRaw = environVarOrDefault "gitRaw" "https://raw.github.com/ionide"
// Read additional information from the release notes document
let releaseNotesData =
File.ReadAllLines "RELEASE_NOTES.md"
|> parseAllReleaseNotes
let release = List.head releaseNotesData
let msg = release.Notes |> List.fold (fun r s -> r + s + "\n") ""
let releaseMsg = (sprintf "Release %s\n" release.NugetVersion) + msg
let run cmd args dir =
if execProcess( fun info ->
info.FileName <- cmd
if not( String.IsNullOrWhiteSpace dir) then
info.WorkingDirectory <- dir
info.Arguments <- args
) System.TimeSpan.MaxValue = false then
failwithf "Error while running '%s' with args: %s" cmd args
let platformTool tool path =
isUnix |> function | true -> tool | _ -> path |> ProcessHelper.tryFindFileOnPath |> fun n -> n.Value
let npmTool =
platformTool "npm" "npm.cmd"
let vsceTool =
platformTool "vsce" "vsce.cmd"
let codeTool =
platformTool "code" (ProgramFilesX86 </> "Microsoft VS Code" </> "bin/code.cmd")
let releaseBin = "release/bin"
let fsacBin = "paket-files/github.com/ionide/FsAutoComplete/bin/release"
// --------------------------------------------------------------------------------------
// Build the Generator project and run it
// --------------------------------------------------------------------------------------
Target "Clean" (fun _ ->
CleanDir "./temp"
CopyFiles "release" ["README.md"; "LICENSE.md"]
CopyFile "release/CHANGELOG.md" "RELEASE_NOTES.md"
)
Target "RunScript" (fun _ ->
run npmTool "install" "release"
run npmTool "run build" "release"
)
Target "CopyFSAC" (fun _ ->
ensureDirectory releaseBin
CleanDir releaseBin
!! (fsacBin + "/*")
|> CopyFiles releaseBin
)
let releaseBinForge = "release/bin_forge"
let forgeBin = "paket-files/github.com/fsharp-editing/Forge/temp/bin"
let forgeExe = forgeBin </> "Forge.exe"
let posixDll = forgeBin </> "Mono.Posix.dll"
let nettDll = forgeBin </> "Nett.dll"
Target "CopyForge" (fun _ ->
ensureDirectory releaseBinForge
CleanDir releaseBinForge
checkFileExists forgeExe
checkFileExists posixDll
checkFileExists nettDll
!! forgeExe
++ posixDll
++ nettDll
|> CopyFiles releaseBinForge
)
let fsgrammarDir = "paket-files/github.com/ionide/ionide-fsgrammar/grammar"
let fsgrammarRelease = "release/syntaxes"
Target "CopyGrammar" (fun _ ->
ensureDirectory fsgrammarRelease
CleanDir fsgrammarRelease
CopyFiles fsgrammarRelease [
fsgrammarDir </> "fsharp.fsi.json"
fsgrammarDir </> "fsharp.fsl.json"
fsgrammarDir </> "fsharp.fsx.json"
fsgrammarDir </> "fsharp.json"
]
)
let fsschemaDir = "schemas"
let fsschemaRelease = "release/schemas"
Target "CopySchemas" (fun _ ->
ensureDirectory fsschemaRelease
CleanDir fsschemaRelease
CopyFile fsschemaRelease (fsschemaDir </> "fableconfig.json")
)
Target "InstallVSCE" ( fun _ ->
killProcess "npm"
run npmTool "install -g vsce" ""
)
Target "SetVersion" (fun _ ->
let fileName = "./release/package.json"
let lines =
File.ReadAllLines fileName
|> Seq.map (fun line ->
if line.TrimStart().StartsWith("\"version\":") then
let indent = line.Substring(0,line.IndexOf("\""))
sprintf "%s\"version\": \"%O\"," indent release.NugetVersion
else line)
File.WriteAllLines(fileName,lines)
)
Target "BuildPackage" ( fun _ ->
killProcess "vsce"
run vsceTool "package" "release"
!! "release/*.vsix"
|> Seq.iter(MoveFile "./temp/")
)
Target "TryPackage"(fun _ ->
killProcess "code"
run codeTool (sprintf "./temp/Ionide-fsharp-%s.vsix" release.NugetVersion) ""
)
Target "PublishToGallery" ( fun _ ->
let token =
match getBuildParam "vsce-token" with
| s when not (String.IsNullOrWhiteSpace s) -> s
| _ -> getUserPassword "VSCE Token: "
killProcess "vsce"
run vsceTool (sprintf "publish --pat %s" token) "release"
)
#load "paket-files/fsharp/FAKE/modules/Octokit/Octokit.fsx"
open Octokit
Target "ReleaseGitHub" (fun _ ->
let user =
match getBuildParam "github-user" with
| s when not (String.IsNullOrWhiteSpace s) -> s
| _ -> getUserInput "Username: "
let pw =
match getBuildParam "github-pw" with
| s when not (String.IsNullOrWhiteSpace s) -> s
| _ -> getUserPassword "Password: "
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]
StageAll ""
Git.Commit.Commit "" (sprintf "Bump version to %s" release.NugetVersion)
Branches.pushBranch "" remote (Information.getBranchName "")
Branches.tag "" release.NugetVersion
Branches.pushTag "" remote release.NugetVersion
let file = !! ("./temp" </> "*.vsix") |> Seq.head
// release on github
createClient user pw
|> createDraft gitOwner gitName release.NugetVersion (release.SemVer.PreRelease <> None) release.Notes
|> uploadFile file
|> releaseDraft
|> Async.RunSynchronously
)
// --------------------------------------------------------------------------------------
// Run generator by default. Invoke 'build <Target>' to override
// --------------------------------------------------------------------------------------
Target "Default" DoNothing
Target "Build" DoNothing
Target "Release" DoNothing
"Clean"
==> "RunScript"
==> "Default"
"Clean"
==> "RunScript"
==> "CopyFSAC"
==> "CopyForge"
==> "CopyGrammar"
==> "CopySchemas"
==> "Build"
"Build"
==> "SetVersion"
// ==> "InstallVSCE"
==> "BuildPackage"
==> "ReleaseGitHub"
==> "PublishToGallery"
==> "Release"
"BuildPackage"
==> "TryPackage"
RunTargetOrDefault "Default"