forked from SaturnFramework/Saturn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.fsx
161 lines (131 loc) · 5.26 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
// --------------------------------------------------------------------------------------
// FAKE build script
// --------------------------------------------------------------------------------------
#r "./packages/build/FAKE/tools/FakeLib.dll"
#load "paket-files/build/fsharp/FAKE/modules/Octokit/Octokit.fsx"
open Fake.ReleaseNotesHelper
open Fake.AssemblyInfoFile
open Fake.Git
open Fake
open System
open Octokit
// --------------------------------------------------------------------------------------
// Information about the project to be used at NuGet and in AssemblyInfo files
// --------------------------------------------------------------------------------------
let project = "Saturn"
let summary = "Opinionated, web development framework for F# which implements the server-side, functional MVC pattern"
let gitOwner = "Krzysztof-Cieslak"
let gitName = "Saturn"
let gitHome = "https://github.com/" + gitOwner
// --------------------------------------------------------------------------------------
// Build variables
// --------------------------------------------------------------------------------------
let buildDir = "./build/"
let dotnetcliVersion = DotNetCli.GetDotNetSDKVersionFromGlobalJson()
Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
let release = parseReleaseNotes (IO.File.ReadAllLines "RELEASE_NOTES.md")
// --------------------------------------------------------------------------------------
// Build Targets
// --------------------------------------------------------------------------------------
Target "Clean" (fun _ ->
CleanDirs [buildDir]
)
Target "AssemblyInfo" (fun _ ->
let getAssemblyInfoAttributes projectName =
[ Attribute.Title projectName
Attribute.Product project
Attribute.Description summary
Attribute.Version release.AssemblyVersion
Attribute.FileVersion release.AssemblyVersion ]
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, _, 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 "InstallDotNetCLI" (fun _ ->
DotNetCli.InstallDotNetSDK dotnetcliVersion |> ignore
)
Target "Restore" (fun _ ->
DotNetCli.Restore id
)
Target "Build" (fun _ ->
DotNetCli.Build id
)
// --------------------------------------------------------------------------------------
// Release Targets
// --------------------------------------------------------------------------------------
Target "Pack" (fun _ ->
Paket.Pack (fun p ->
{ p with
BuildConfig = "Release";
OutputPath = buildDir;
Version = release.NugetVersion
ReleaseNotes = String.concat "\n" release.Notes
MinimumFromLockFile = true
}
)
)
Target "ReleaseGitHub" (fun _ ->
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
let client =
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: "
createClient user pw
let file = !! (buildDir </> "*.nupkg") |> Seq.head
// release on github
client
|> createDraft gitOwner gitName release.NugetVersion (release.SemVer.PreRelease <> None) release.Notes
|> uploadFile file
|> releaseDraft
|> Async.RunSynchronously
)
Target "Push" (fun _ ->
let key =
match getBuildParam "nuget-key" with
| s when not (String.IsNullOrWhiteSpace s) -> s
| _ -> getUserPassword "NuGet Key: "
Paket.Push (fun p -> { p with WorkingDir = buildDir; ApiKey = key }))
// --------------------------------------------------------------------------------------
// Build order
// --------------------------------------------------------------------------------------
Target "Default" DoNothing
Target "Release" DoNothing
"Clean"
==> "InstallDotNetCLI"
==> "AssemblyInfo"
==> "Restore"
==> "Build"
==> "Default"
"Default"
==> "Pack"
==> "ReleaseGitHub"
==> "Push"
==> "Release"
RunTargetOrDefault "Default"