-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublish.fsx
93 lines (65 loc) · 2.19 KB
/
publish.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
#r "nuget: dotenv.net"
open System
open dotenv.net
open System.Diagnostics
open System
DotEnv.Load(DotEnvOptions(envFilePaths = [ ".env.local" ]))
let run (command: string) (arguments: string) =
printfn "> %s %s" command arguments
let startInfo =
ProcessStartInfo(
command,
arguments,
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
)
use p = new Process()
p.StartInfo <- startInfo
p.Start() |> ignore
let output = p.StandardOutput.ReadToEnd()
let error = p.StandardError.ReadToEnd()
p.WaitForExit()
let exitCode = p.ExitCode
if exitCode = 0 then
()
// printfn "Command executed successfully."
else
eprintfn "Command failed with exit code %d" exitCode
// Output the command output and error (if any)
if not (String.IsNullOrEmpty output) then
printfn "%s" output
if not (String.IsNullOrEmpty error) then
eprintfn "%s" error
exitCode
let apiKey = Environment.GetEnvironmentVariable("nuget-api-key")
if String.IsNullOrEmpty apiKey then
eprintf "no api key found. Create a file '.env.local' with content 'nuget-api-key=<your api key>'"
exit -1
let publishfile file =
let _ =
run "dotnet" $"nuget push {file} --source https://api.nuget.org/v3/index.json --api-key {apiKey}"
()
let deleteFolder folder =
fun () ->
if System.IO.Directory.Exists folder then
System.IO.Directory.Delete(folder, true)
let restore () = run "dotnet" "restore" |> ignore
let pack (path: string) =
fun () -> if run "dotnet" $"pack {path}" = 0 then () else exit -1
let publish folderPath pattern =
fun () ->
let files = System.IO.Directory.EnumerateFiles(folderPath, pattern)
printfn "%A" files
files |> Seq.iter publishfile
()
let execute =
(deleteFolder ".\\src\\TinyEventStore\\bin")
>> (deleteFolder ".\\src\\TinyEventStore.ef\\bin")
>> restore
>> pack ".\\src\\TinyEventStore\\TinyEventStore.fsproj"
>> pack ".\\src\\TinyEventStore.Ef\\TinyEventStore.Ef.fsproj"
>> publish ".\\src\\TinyEventStore\\bin\\Release" "TinyEventStore.*.nupkg"
>> publish ".\\src\\TinyEventStore.Ef\\bin\\Release" "TinyEventStore.*.nupkg"
execute ()