-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.fsx
181 lines (153 loc) · 5.97 KB
/
build.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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// --------------------------------------------------------------------------------------
// FAKE build script
// --------------------------------------------------------------------------------------
#r @"packages/build/FAKE/tools/FakeLib.dll"
open Fake
open Fake.AssemblyInfoFile
open Fake.Git
open Fake.ReleaseNotesHelper
open System
// --------------------------------------------------------------------------------------
// Build variables
// --------------------------------------------------------------------------------------
let buildDir = "./build/"
let appReferences = !! "src/**/*.??proj"
let examplesReferences = !! "examples/**/*.??proj"
let dotnetcliVersion = DotNetCli.GetDotNetSDKVersionFromGlobalJson()
let mutable dotnetExePath = "dotnet"
let project = "protoactor-fsharp"
let summary = "F# API for proto.actor"
let configuration = "Release"
let release = LoadReleaseNotes "RELEASE_NOTES.md"
let gitOwner = "mastoj"
let gitName = project
let gitUrl = "https://github.com"
let gitHome = sprintf "%s/%s" gitUrl gitOwner
let outputDir = "./.temp"
// --------------------------------------------------------------------------------------
// Helpers
// --------------------------------------------------------------------------------------
let run' timeout cmd args dir =
if execProcess (fun info ->
info.FileName <- cmd
if not (String.IsNullOrWhiteSpace dir) then
info.WorkingDirectory <- dir
info.Arguments <- args
) timeout |> not then
failwithf "Error while running '%s' with args: %s" cmd args
let run = run' System.TimeSpan.MaxValue
let runDotnet workingDir args =
let result =
ExecProcess (fun info ->
info.FileName <- dotnetExePath
info.WorkingDirectory <- workingDir
info.Arguments <- args) TimeSpan.MaxValue
if result <> 0 then failwithf "dotnet %s failed" args
// --------------------------------------------------------------------------------------
// Targets
// --------------------------------------------------------------------------------------
Target "AssemblyInfo" (fun _ ->
let getAssemblyInfoAttributes projectName =
[ Attribute.Title (projectName)
Attribute.Product project
Attribute.Description summary
Attribute.Version release.AssemblyVersion
Attribute.FileVersion release.AssemblyVersion
Attribute.Configuration configuration ]
let getProjectDetails projectPath =
let projectName = System.IO.Path.GetFileNameWithoutExtension(projectPath)
( projectPath,
projectName,
System.IO.Path.GetDirectoryName(projectPath),
(getAssemblyInfoAttributes projectName)
)
!! "src/**/*.??proj"
|> Seq.map getProjectDetails
|> Seq.iter (fun (projFileName, projectName, folderName, attributes) ->
match projFileName with
| Fsproj -> CreateFSharpAssemblyInfo (folderName </> "AssemblyInfo.fs") attributes
| Csproj -> CreateCSharpAssemblyInfo ((folderName </> "Properties") </> "AssemblyInfo.cs") attributes
| Vbproj -> CreateVisualBasicAssemblyInfo ((folderName </> "My Project") </> "AssemblyInfo.vb") attributes
| Shproj -> ()
)
)
Target "Clean" (fun _ ->
CleanDirs [buildDir; outputDir]
)
Target "InstallDotNetCLI" (fun _ ->
dotnetExePath <- DotNetCli.InstallDotNetSDK dotnetcliVersion
)
Target "Restore" (fun _ ->
appReferences
|> Seq.iter (fun p ->
let dir = System.IO.Path.GetDirectoryName p
runDotnet dir "restore"
)
)
let build fileIncludes _ =
fileIncludes
|> Seq.iter (fun p ->
let dir = System.IO.Path.GetDirectoryName p
let target = sprintf "build -c %s" configuration
runDotnet dir target
)
Target "Build" (build appReferences)
Target "BuildExamples" (build examplesReferences)
Target "NuGet" (fun _ ->
Paket.Pack(fun p ->
{ p with
OutputPath = outputDir
Version = release.NugetVersion
ReleaseNotes = toLines release.Notes})
)
Target "PublishNuget" (fun _ ->
Paket.Push(fun p ->
{ p with
PublishUrl = "https://www.nuget.org"
WorkingDir = outputDir })
)
Target "Release" (fun _ ->
let user =
match getBuildParam "github-user" with
| s when not (String.IsNullOrWhiteSpace s) -> s
| _ -> getUserInput "Username: "
let pw =
match getBuildParam "github-pw" with
| s when not (String.IsNullOrWhiteSpace s) -> s
| _ -> getUserPassword "Password: "
let remote =
Git.CommandHelper.getGitResult "" "remote -v"
|> Seq.filter (fun (s: string) -> s.EndsWith("(push)"))
|> Seq.tryFind (fun (s: string) -> s.Contains(gitOwner + "/" + gitName))
|> function None -> gitHome + "/" + gitName | Some (s: string) -> s.Split().[0]
StageAll ""
Git.Commit.Commit "" (sprintf "Bump version to %s" release.NugetVersion)
Branches.pushBranch "" remote (Information.getBranchName "")
Branches.tag "" release.NugetVersion
Branches.pushTag "" remote release.NugetVersion
// release on github
// createClient user pw
// |> createDraft gitOwner gitName release.NugetVersion (release.SemVer.PreRelease <> None) release.Notes
// // TODO: |> uploadFile "PATH_TO_FILE"
// |> releaseDraft
// |> Async.RunSynchronously
)
Target "All" DoNothing
Target "BuildPackage" DoNothing
// --------------------------------------------------------------------------------------
// Build order
// --------------------------------------------------------------------------------------
"AssemblyInfo"
==> "Clean"
==> "InstallDotNetCLI"
==> "Restore"
==> "Build"
==> "NuGet"
==> "BuildPackage"
==> "All"
"BuildPackage"
==> "PublishNuget"
==> "Release"
"Build"
==> "BuildExamples"
RunTargetOrDefault "All"