forked from SAFE-Stack/SAFE-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuild.fs
121 lines (100 loc) · 3.59 KB
/
Build.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
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
open System
open Fake.Core
open Fake.DotNet
open Fake.IO
open Fake.Tools
let execContext = Context.FakeExecutionContext.Create false "build.fsx" [ ]
Context.setExecutionContext (Context.RuntimeContext.Fake execContext)
let templatePath = "./Content/.template.config/template.json"
let templateProj = "SAFE.Template.proj"
let templateName = "SAFE-Stack Web App"
let nupkgDir = Path.getFullName "./nupkg"
let skipTests = Environment.hasEnvironVar "yolo"
let release = ReleaseNotes.load "RELEASE_NOTES.md"
let formattedRN =
release.Notes
|> List.map (sprintf "* %s")
|> String.concat "\n"
Target.create "Clean" (fun _ ->
Shell.cleanDirs [ nupkgDir ]
)
let msBuildParams msBuildParameter: MSBuild.CliArguments = { msBuildParameter with DisableInternalBinLog = true }
Target.create "Pack" (fun _ ->
Shell.regexReplaceInFileWithEncoding
" \"name\": .+,"
(" \"name\": \"" + templateName + " v" + release.NugetVersion + "\",")
Text.Encoding.UTF8
templatePath
DotNet.pack
(fun args ->
{ args with
OutputPath = Some nupkgDir
MSBuildParams = msBuildParams args.MSBuildParams
Common =
{ args.Common with
CustomParams =
Some (sprintf "/p:PackageVersion=%s /p:PackageReleaseNotes=\"%s\""
release.NugetVersion
formattedRN) }
})
templateProj
)
Target.create "Install" (fun _ ->
let args=
let nupkgFileName = sprintf "SAFE.Template.%s.nupkg" release.NugetVersion
let fullPathToNupkg = System.IO.Path.Combine(nupkgDir, nupkgFileName)
sprintf "install \"%s\"" fullPathToNupkg
let result = DotNet.exec (fun x -> { x with DotNetCliPath = "dotnet" }) "new" args
if not result.OK then failwithf "`dotnet %s` failed with %O" args result
)
let psi exe arg dir (x: ProcStartInfo) : ProcStartInfo =
{ x with
FileName = exe
Arguments = arg
WorkingDirectory = dir }
let run exe arg dir =
let result = Process.execWithResult (psi exe arg dir) TimeSpan.MaxValue
if not result.OK then (failwithf "`%s %s` failed: %A" exe arg result.Errors)
Target.create "Tests" (fun _ ->
let cmd = "run"
let args = "--project tests/tests.fsproj"
let result = DotNet.exec (fun x -> { x with DotNetCliPath = "dotnet" }) cmd args
if not result.OK then failwithf "`dotnet %s %s` failed" cmd args
)
Target.create "Push" (fun _ ->
Paket.push ( fun args ->
{ args with
PublishUrl = "https://www.nuget.org"
WorkingDir = nupkgDir
}
)
let remoteGit = "upstream"
let commitMsg = sprintf "Bumping version to %O" release.NugetVersion
let tagName = string release.NugetVersion
Git.Branches.checkout "" false "master"
Git.CommandHelper.directRunGitCommand "" "fetch origin" |> ignore
Git.CommandHelper.directRunGitCommand "" "fetch origin --tags" |> ignore
Git.Staging.stageAll ""
Git.Commit.exec "" commitMsg
Git.Branches.pushBranch "" remoteGit "master"
Git.Branches.tag "" tagName
Git.Branches.pushTag "" remoteGit tagName
)
Target.create "Release" ignore
open Fake.Core.TargetOperators
"Clean"
==> "Pack"
==> "Install"
=?> ("Tests", not skipTests)
==> "Push"
==> "Release"
[<EntryPoint>]
let main args =
try
match args with
| [| target |] -> Target.runOrDefault target
| _ -> Target.runOrDefault "Install"
0
with e ->
printfn "%A" e
1