-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.fsx
More file actions
115 lines (97 loc) · 4.35 KB
/
build.fsx
File metadata and controls
115 lines (97 loc) · 4.35 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
#r "nuget: Fun.Build"
open System
open System.IO
open System.IO.Compression
open Fun.Result
open Fun.Build
let (</>) x y = Path.Combine(x, y)
let publishDir = __SOURCE_DIRECTORY__ </> "publish"
let options = {|
platform = CmdArg.Create(longName = "--platform", values = [ "win-x64"; "linux-x64"; "linux-arm64"; "osx-x64"; "osx-arm64" ])
run = CmdArg.Create(longName = "--run", shortName = "-r")
docker = CmdArg.Create(longName = "--docker")
zip = CmdArg.Create(longName = "--zip")
|}
let stage_checkEnvs = stage "check-env" { run "dotnet --version" }
pipeline "dev" {
description "Setup local env for dev"
whenCmdArg options.platform
stage_checkEnvs
stage "build" {
run "dotnet build"
run (fun ctx -> asyncResult {
let platform = ctx.GetCmdArg(options.platform)
let nativesDir = __SOURCE_DIRECTORY__ </> "Brainloop" </> "runtimes" </> platform </> "native"
let publishDir = __SOURCE_DIRECTORY__ </> "Brainloop" </> "bin" </> "Debug" </> "net9.0"
for file in Directory.GetFiles(nativesDir) do
File.Copy(file, Path.Combine(publishDir </> Path.GetFileName(file)), true)
})
}
stage "run" {
whenCmdArg options.run
workingDir "Brainloop"
run "dotnet run --no-restore"
}
runIfOnlySpecified
}
pipeline "publish" {
description "Publish single executable"
whenAny {
cmdArg options.platform
cmdArg options.docker
}
whenAny {
when' true
cmdArg options.zip
}
stage_checkEnvs
stage "bundle" {
workingDir "Brainloop"
run (fun ctx -> asyncResult {
let platform =
match ctx.TryGetCmdArg(options.platform) with
| Some x -> x
| None ->
match Environment.OSVersion.Platform with
| PlatformID.Win32NT -> "win-x64"
| PlatformID.Unix when Environment.Is64BitOperatingSystem -> "linux-x64"
| PlatformID.Unix when Environment.Is64BitProcess -> "linux-arm64"
| PlatformID.MacOSX when Environment.Is64BitOperatingSystem -> "osx-x64"
| PlatformID.MacOSX when Environment.Is64BitProcess -> "osx-arm64"
| _ -> failwith $"Unsupported platform: {Environment.OSVersion.Platform}"
let isDocker = ctx.TryGetCmdArg(options.docker) |> Option.isSome
let nativesDir = __SOURCE_DIRECTORY__ </> "Brainloop" </> "runtimes" </> platform </> "native"
let publishDir = __SOURCE_DIRECTORY__ </> publishDir </> (if isDocker then "docker" else platform)
if Directory.Exists publishDir then Directory.Delete(publishDir, true)
if isDocker then
do!
ctx.RunCommand
$"""dotnet publish -c Release /p:SelfContained=false /p:PublishReadyToRun=true /p:PublishTrimmed=false -o {publishDir}"""
else
do!
ctx.RunCommand
$"""dotnet publish -c Release -r {platform} /p:PublishSingleFile=true /p:PublishReadyToRun=false /p:PublishTrimmed=true -o {publishDir}"""
for file in Directory.GetFiles(nativesDir) do
File.Copy(file, publishDir </> Path.GetFileName(file), true)
if ctx.TryGetCmdArg options.zip |> Option.isSome then
let changelog = Changelog.GetLastVersion(__SOURCE_DIRECTORY__ </> "Brainloop")
let destinationFileName =
publishDir </> ".." </> "brainloop-" + Path.GetFileName publishDir + "-" + changelog.Value.Version + ".zip"
if File.Exists destinationFileName then File.Delete destinationFileName
ZipFile.CreateFromDirectory(publishDir, destinationFileName)
})
}
runIfOnlySpecified
}
pipeline "publish-all" {
description "Publish all platforms"
stage "bundles" {
run "dotnet fsi ./build.fsx -- -p publish --platform win-x64 --zip"
run "dotnet fsi ./build.fsx -- -p publish --platform linux-x64 --zip"
run "dotnet fsi ./build.fsx -- -p publish --platform linux-arm64 --zip"
run "dotnet fsi ./build.fsx -- -p publish --platform osx-x64 --zip"
run "dotnet fsi ./build.fsx -- -p publish --platform osx-arm64 --zip"
}
runIfOnlySpecified
}
tryPrintPipelineCommandHelp ()