-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sample.fs
87 lines (76 loc) · 2.81 KB
/
Sample.fs
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
module Scripts.Sample
open System
open System.IO
open System.Management.Automation
open Scripts.Git
open Serilog
[<RequireQualifiedAccess>]
type CodebaseSpec =
| GitHub of CheckoutSpec
| Local of string
with
static member MakeGithub(org : string, repo : string, rev : string, ?suffix : string) =
{
OrgRepo = OrgRepo.Make(org, repo)
Revision = rev
Suffix = suffix
}
|> GitHub
[<RequireQualifiedAccess>]
type PrepareScript =
| PowerShell of string
| Nothing
type Sample =
{
Name : string
CodebaseSpec : CodebaseSpec
PrepareScript : PrepareScript
MainSolution : string
MSBuildProps : Map<string, string>
SDKRequirementsDescription : string
ExcludeProjects : string option
}
type AllConfig =
{
CacheDir : string
}
module SamplePreparation =
let codebaseDir (config : CheckoutsConfig) (codebase : CodebaseSpec) : string =
match codebase with
| CodebaseSpec.GitHub spec -> specDir config spec
| CodebaseSpec.Local dir -> dir
let preparationMarkerPath (config : CheckoutsConfig) (spec : CheckoutSpec) =
(specDir config spec) + ".marker"
let prepare (config : CheckoutsConfig) (sample : Sample) =
match sample.CodebaseSpec with
| CodebaseSpec.Local _ -> ()
| CodebaseSpec.GitHub spec ->
prepareCheckout config spec
let prepare (dir : string) (script : string) =
Log.Information $"Running codebase preparation PowerShell script."
use ps = PowerShell.Create()
ps.AddScript($"cd {dir}") |> ignore
let results = ps.AddScript(script).Invoke()
results
|> Seq.iter (fun r -> Log.Information(r.ToString()))
if ps.HadErrors then
failwith "PowerShell preparation script failed."
let dir = codebaseDir config sample.CodebaseSpec
match sample.PrepareScript with
| PrepareScript.PowerShell script ->
match sample.CodebaseSpec with
| CodebaseSpec.Local _ ->
prepare dir script
| CodebaseSpec.GitHub spec ->
let markerPath = preparationMarkerPath config spec
if File.Exists(markerPath) then
Log.Information("Skipping preparation script as preparation marker file exists: {markerPath}", markerPath)
else
prepare dir script
File.WriteAllText(markerPath, DateTime.Now.ToString("o"))
Log.Information("Preparation finished. Marker file created: {markerPath}", markerPath)
()
()
| PrepareScript.Nothing ->
()
dir