Repository navigation
Expand file tree
/
Copy pathbuild.fsx
More file actions
232 lines (179 loc) · 6.39 KB
/
Copy pathbuild.fsx
File metadata and controls
232 lines (179 loc) · 6.39 KB
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
#r "nuget: Fun.Build, 1.2.0"
open System
open System.Diagnostics
open System.IO
open System.Runtime.CompilerServices
open Fun.Build
let repoRoot = __SOURCE_DIRECTORY__
let releaseHeading =
File.ReadLines(Path.Combine(repoRoot, "RELEASE_NOTES.md"))
|> Seq.tryFind(fun line -> line.StartsWith("### ", StringComparison.Ordinal))
|> Option.defaultWith(fun () -> failwith "RELEASE_NOTES.md does not contain a release heading")
let releaseVersion =
let versionText =
releaseHeading.Substring(4).Split(' ', StringSplitOptions.RemoveEmptyEntries)
|> Array.tryHead
|> Option.defaultWith(fun () -> failwithf "Invalid release heading: %s" releaseHeading)
Version.Parse versionText
let cleanDirectory path =
if Directory.Exists path then
Directory.Delete(path, true)
Directory.CreateDirectory(path) |> ignore
let shellCommand command =
if OperatingSystem.IsWindows() then
"cmd /c " + command
else
command
let clean =
stage "Clean" {
run (fun _ ->
cleanDirectory(Path.Combine(repoRoot, "temp"))
cleanDirectory(Path.Combine(repoRoot, "out"))
Directory.CreateDirectory(Path.Combine(repoRoot, "release")) |> ignore
File.Copy(Path.Combine(repoRoot, "README.md"), Path.Combine(repoRoot, "release/README.md"), true)
File.Copy(Path.Combine(repoRoot, "LICENSE.md"), Path.Combine(repoRoot, "release/LICENSE.md"), true)
File.Copy(Path.Combine(repoRoot, "RELEASE_NOTES.md"), Path.Combine(repoRoot, "release/CHANGELOG.md"), true)
let readmePath = Path.Combine(repoRoot, "release/README.md")
File.ReadAllLines(readmePath)
|> Array.filter(fun line -> line.Contains(".svg") |> not)
|> fun lines -> File.WriteAllLines(readmePath, lines))
}
let yarnInstall =
stage "YarnInstall" {
run (shellCommand "yarn install")
}
let checkFormat =
stage "CheckFormat" {
run "dotnet fantomas src tests --check"
echo "No files need formatting"
}
let runScript =
stage "RunScript" {
run "dotnet fable ./src/extension/Extension.fsproj --outDir ./out --run webpack --mode=production"
}
let watch =
stage "Watch" {
run "dotnet fable watch ./src/extension/Extension.fsproj --outDir ./out --define DEBUG --runWatch webpack --mode=development"
}
let buildServer =
stage "BuildServer" {
run "dotnet publish src/Server/Server.fsproj -c Release -o release/bin"
}
let runTests =
stage "RunTests" {
run "dotnet test tests/Server.Tests/Server.Tests.fsproj -m:1"
}
let buildProject =
stage "BuildProject" {
clean
yarnInstall
checkFormat
runScript
buildServer
}
let setPackageJsonField name value releaseDirectory =
let packageJson = Path.Combine(repoRoot, releaseDirectory, "package.json")
let prefix = sprintf "\"%s\":" name
let mutable found = false
let updatedLines =
File.ReadAllLines(packageJson)
|> Array.map(fun line ->
if line.TrimStart().StartsWith(prefix, StringComparison.Ordinal) then
found <- true
let indentLength = line.Length - line.TrimStart().Length
sprintf "%s\"%s\": %s," (line.Substring(0, indentLength)) name value
else
line)
if not found then
failwithf "Could not find package.json field %s in %s" name packageJson
File.WriteAllLines(packageJson, updatedLines)
let setVersion =
stage "SetVersion" {
run (fun _ -> setPackageJsonField "version" (sprintf "\"%O\"" releaseVersion) "release")
}
let killAllByName processName =
for proc in Process.GetProcessesByName(processName) do
use proc = proc
try
if not proc.HasExited then
proc.Kill(true)
with _ -> ()
let buildPackage =
stage "BuildPackage" {
run (fun _ -> killAllByName "vsce")
stage "Package extension" {
workingDir (Path.Combine(repoRoot, "release"))
run (shellCommand "vsce package")
}
run (fun _ ->
let tempDirectory = Path.Combine(repoRoot, "temp")
Directory.CreateDirectory(tempDirectory) |> ignore
Directory.GetFiles(Path.Combine(repoRoot, "release"), "*.vsix")
|> Array.iter(fun packagePath ->
let destination = Path.Combine(tempDirectory, Path.GetFileName(packagePath))
File.Move(packagePath, destination, true)))
}
let readPassword () =
if Console.IsInputRedirected then
failwith "Set the vsce-token environment variable when no interactive terminal is available."
Console.Write("VSCE Token: ")
let token = ResizeArray<char>()
let mutable reading = true
while reading do
let key = Console.ReadKey(true)
match key.Key with
| ConsoleKey.Enter -> reading <- false
| ConsoleKey.Backspace when token.Count > 0 ->
token.RemoveAt(token.Count - 1)
Console.Write("\b \b")
| _ when Char.IsControl(key.KeyChar) |> not ->
token.Add(key.KeyChar)
Console.Write('*')
| _ -> ()
Console.WriteLine()
String(token.ToArray())
let publishToGallery =
stage "PublishToGallery" {
workingDir (Path.Combine(repoRoot, "release"))
run (fun context -> async {
let token = Environment.GetEnvironmentVariable("vsce-token")
let token =
if String.IsNullOrWhiteSpace token then
readPassword ()
else
token
let commandFormat =
if OperatingSystem.IsWindows() then
"cmd /c vsce publish --pat {0}"
else
"vsce publish --pat {0}"
let command = FormattableStringFactory.Create(commandFormat, [| box token |])
return! context.RunSensitiveCommand command
})
}
pipeline "Default" {
workingDir repoRoot
buildProject
runIfOnlySpecified false
}
pipeline "Build" {
workingDir repoRoot
buildProject
runTests
runIfOnlySpecified
}
pipeline "Release" {
workingDir repoRoot
buildProject
runTests
setVersion
buildPackage
publishToGallery
runIfOnlySpecified
}
pipeline "Watch" {
workingDir repoRoot
watch
runIfOnlySpecified
}
tryPrintPipelineCommandHelp ()