This repository has been archived by the owner on Oct 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathesbuild-ci.fsx
76 lines (56 loc) · 2.02 KB
/
esbuild-ci.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
#r "nuget: CliWrap, 3.5.0"
#r "nuget: Flurl.Http, 3.2.4"
#r "nuget: SharpZipLib, 1.4.1"
open System
open System.IO
open System.Threading.Tasks
open CliWrap
open Flurl.Http
open ICSharpCode.SharpZipLib.GZip
open ICSharpCode.SharpZipLib.Tar
let EsbuildBinaryPath () : string =
"/home/runner/.local/share/perla/0.19.5/package/bin/esbuild"
|> Path.GetFullPath
let chmodBinCmd () =
Cli
.Wrap("chmod")
.WithStandardErrorPipe(PipeTarget.ToStream(Console.OpenStandardError()))
.WithStandardOutputPipe(PipeTarget.ToStream(Console.OpenStandardOutput()))
.WithArguments($"+x {EsbuildBinaryPath()}")
let tryDownloadEsBuild () : Task<string option> =
let url =
"https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.19.5.tgz"
let compressedFile = "/home/runner/.local/share/perla/0.19.5/esbuild.tgz"
compressedFile |> Path.GetDirectoryName |> Directory.CreateDirectory |> ignore
task {
try
use! stream = url.GetStreamAsync()
Console.WriteLine $"Downloading esbuild from: {url}"
use file = File.OpenWrite(compressedFile)
do! stream.CopyToAsync(file)
Console.WriteLine $"Downloaded esbuild to: {file.Name}"
return Some(file.Name)
with ex ->
Console.Error.WriteLine($"Failed to download esbuild from: {url}", ex)
return None
}
let decompressEsbuild (path: Task<string option>) = task {
match! path with
| Some path ->
use stream = new GZipInputStream(File.OpenRead path)
use archive = TarArchive.CreateInputTarArchive(stream, Text.Encoding.UTF8)
path |> Path.GetDirectoryName |> archive.ExtractContents
Console.WriteLine $"Executing: chmod +x on \"{EsbuildBinaryPath()}\""
let res = chmodBinCmd().ExecuteAsync()
do! res.Task :> Task
Console.WriteLine "Cleaning up!"
File.Delete(path)
Console.WriteLine "This setup should happen once per machine"
Console.WriteLine "If you see it often please report a bug."
| None -> ()
return ()
}
tryDownloadEsBuild ()
|> decompressEsbuild
|> Async.AwaitTask
|> Async.RunSynchronously