-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathbuild.fsx
211 lines (165 loc) · 6.05 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
// --------------------------------------------------------------------------------------
// FAKE build script
// --------------------------------------------------------------------------------------
#I "packages/build/FAKE/tools"
#r "packages/build/FAKE/tools/FakeLib.dll"
open System
open System.IO
open Fake
open Fake.Git
open Fake.ReleaseNotesHelper
open Fake.YarnHelper
// 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-paket"
// 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 |> not then
traceError <| sprintf "Error while running '%s' with args: %s" cmd args
let pickTool unixPath winPath =
match isUnix with
| true -> unixPath
| _ -> winPath
let platformTool tool path =
match isUnix with
| true -> tool
| _ -> match ProcessHelper.tryFindFileOnPath path with
| None -> failwithf "can't find tool %s on PATH" tool
| Some v -> v
let npmTool =
platformTool "npm" "npm.cmd"
let vsceTool = lazy (platformTool "vsce" "vsce.cmd")
let codeTool =
pickTool
"code"
ProgramFilesX86 </> "Microsoft VS Code" </> "bin/code.cmd"
// --------------------------------------------------------------------------------------
// 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 "YarnInstall" <| fun () ->
Yarn (fun p -> { p with Command = Install Standard })
Target "DotNetRestore" <| fun () ->
DotNetCli.Restore (fun p -> { p with WorkingDir = "src" } )
let runFable additionalArgs =
let cmd = "fable webpack -- --config webpack.config.js " + additionalArgs
DotNetCli.RunCommand (fun p -> { p with WorkingDir = "src" } ) cmd
Target "Build" (fun _ ->
runFable ""
)
Target "Watch" (fun _ ->
runFable "--watch"
)
let fsgrammarDir = "paket-files/github.com/ionide/ionide-fsgrammar/grammar"
let fsgrammarRelease = "release/grammar"
Target "CopyGrammar" (fun _ ->
ensureDirectory fsgrammarRelease
CleanDir fsgrammarRelease
CopyFiles fsgrammarRelease [
fsgrammarDir </> "paket.dependencies.json"
fsgrammarDir </> "paket.lock.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.Value "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.Value (sprintf "publish --pat %s" token) "release"
)
#load "paket-files/build/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 "Release" DoNothing
"YarnInstall" ?=> "Build"
"DotNetRestore" ?=> "Build"
"YarnInstall" ==> "Default"
"DotNetRestore" ==> "Default"
"Clean"
==> "Build"
==> "CopyGrammar"
==> "Default"
"Default"
==> "SetVersion"
==> "InstallVSCE"
==> "BuildPackage"
==> "ReleaseGitHub"
==> "PublishToGallery"
==> "Release"
RunTargetOrDefault "Default"