-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
build.fsx
193 lines (158 loc) · 5.52 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
// --------------------------------------------------------------------------------------
// FAKE build script
// --------------------------------------------------------------------------------------
#I "packages/FAKE/tools"
#r "packages/FAKE/tools/FakeLib.dll"
open System
open System.Diagnostics
open System.IO
open Fake
open Fake.Git
open Fake.ProcessHelper
open Fake.ReleaseNotesHelper
open Fake.ZipHelper
#if MONO
#else
#load "src/vscode-bindings.fsx"
#load "src/fake.fs"
#load "src/main.fs"
#endif
// 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-fake"
// 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
traceError <| sprintf "Error while running '%s' with args: %s" cmd args
let npmTool =
match isUnix with
| true -> "/usr/local/bin/npm"
| _ -> __SOURCE_DIRECTORY__ </> "packages/Npm.js/tools/npm.cmd"
let vsceTool =
#if MONO
"vsce"
#else
"packages" </> "Node.js" </> "vsce.cmd" |> FullName
#endif
// --------------------------------------------------------------------------------------
// 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"
)
#if MONO
Target "BuildGenerator" (fun () ->
[ __SOURCE_DIRECTORY__ </> "src" </> "Ionide.Fake.fsproj" ]
|> MSBuildDebug "" "Rebuild"
|> Log "AppBuild-Output: "
)
Target "RunGenerator" (fun () ->
(TimeSpan.FromMinutes 5.0)
|> ProcessHelper.ExecProcess (fun p ->
p.FileName <- __SOURCE_DIRECTORY__ </> "src" </> "bin" </> "Debug" </> "Ionide.Fake.exe" )
|> ignore
)
#else
Target "RunScript" (fun () ->
Ionide.VSCode.Generator.translateModules typeof<Ionide.VSCode.Fake> (".." </> "release" </> "fake.js")
)
#endif
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 "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 "Release" DoNothing
#if MONO
"Clean"
==> "BuildGenerator"
==> "RunGenerator"
==> "Default"
#else
"Clean"
==> "RunScript"
==> "Default"
#endif
"Default"
==> "SetVersion"
==> "InstallVSCE"
==> "BuildPackage"
==> "ReleaseGitHub"
==> "PublishToGallery"
==> "Release"
RunTargetOrDefault "Default"