This repository has been archived by the owner on Sep 26, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 54
/
build.fsx
221 lines (183 loc) · 7.81 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
// --------------------------------------------------------------------------------------
// FAKE build script
// --------------------------------------------------------------------------------------
#r "paket: groupref build //"
#load ".fake/build.fsx/intellisense.fsx"
open Fake.Core
open Fake.DotNet
open Fake.Tools
open Fake.IO
open Fake.IO.FileSystemOperators
open Fake.IO.Globbing.Operators
open Fake.Core.TargetOperators
open Fake.Api
// --------------------------------------------------------------------------------------
// Information about the project to be used at NuGet and in AssemblyInfo files
// --------------------------------------------------------------------------------------
let project = "Forge"
let summary = "Forge is a build tool that provides tasks for creating, compiling, and testing F# projects"
let gitOwner = "ionide"
let gitHome = "https://github.com/" + gitOwner
let gitName = "Forge"
let gitRaw = Environment.environVarOrDefault "gitRaw" ("https://raw.github.com/" + gitOwner)
// --------------------------------------------------------------------------------------
// Build variables
// --------------------------------------------------------------------------------------
let dotnetcliVersion = DotNet.getSDKVersionFromGlobalJson()
System.Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
let release = ReleaseNotes.parse (System.IO.File.ReadAllLines "RELEASE_NOTES.md")
let packageDir = __SOURCE_DIRECTORY__ </> "out"
let buildDir = __SOURCE_DIRECTORY__ </> "temp"
let forgeSh = "./forge.sh"
// --------------------------------------------------------------------------------------
// Helpers
// --------------------------------------------------------------------------------------
let isNullOrWhiteSpace = System.String.IsNullOrWhiteSpace
let exec cmd args dir =
if Process.execSimple( fun info ->
{ info with
FileName = cmd
WorkingDirectory =
if (isNullOrWhiteSpace dir) then info.WorkingDirectory
else dir
Arguments = args
}
) System.TimeSpan.MaxValue <> 0 then
failwithf "Error while running '%s' with args: %s" cmd args
let getBuildParam = Environment.environVar
let DoNothing = ignore
// --------------------------------------------------------------------------------------
// Build Targets
// --------------------------------------------------------------------------------------
Target.create "Clean" (fun _ ->
Shell.cleanDirs [buildDir; packageDir]
)
Target.create "AssemblyInfo" (fun _ ->
let getAssemblyInfoAttributes projectName =
[ AssemblyInfo.Title projectName
AssemblyInfo.Product project
AssemblyInfo.Description summary
AssemblyInfo.Version release.AssemblyVersion
AssemblyInfo.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
| proj when proj.EndsWith("fsproj") -> AssemblyInfoFile.createFSharp (folderName </> "AssemblyInfo.fs") attributes
| proj when proj.EndsWith("csproj") -> AssemblyInfoFile.createCSharp ((folderName </> "Properties") </> "AssemblyInfo.cs") attributes
| proj when proj.EndsWith("vbproj") -> AssemblyInfoFile.createVisualBasic ((folderName </> "My Project") </> "AssemblyInfo.vb") attributes
| _ -> ()
)
)
Target.create "InstallDotNetCLI" (fun _ ->
let version = DotNet.CliVersion.Version dotnetcliVersion
let options = DotNet.Options.Create()
DotNet.install (fun opts -> { opts with Version = version }) options |> ignore
)
Target.create "Restore" (fun _ ->
DotNet.restore id ""
)
Target.create "Build" (fun _ ->
DotNet.build id ""
)
Target.create "Publish" (fun _ ->
DotNet.publish (fun p -> {p with OutputPath = Some buildDir}) "src/Forge"
)
Target.create "Test" (fun _ ->
exec "dotnet" @"run --project .\tests\Forge.Tests\Forge.Tests.fsproj" "."
//exec "dotnet" @"run --project .\tests\Forge.IntegrationTests\Forge.IntegrationTests.fsproj" "."
)
// --------------------------------------------------------------------------------------
// Release Targets
// --------------------------------------------------------------------------------------
Target.create "Pack" (fun _ ->
//Pack Forge.Core
Paket.pack (fun p ->
{ p with
BuildConfig = "Release";
OutputPath = packageDir;
Version = release.NugetVersion
ReleaseNotes = String.concat "\n" release.Notes
MinimumFromLockFile = false
ToolPath = ".paket/paket.exe"
}
)
//Pack Forge global tool
Environment.setEnvironVar "PackageVersion" release.NugetVersion
Environment.setEnvironVar "Version" release.NugetVersion
Environment.setEnvironVar "Authors" "Krzysztof Cieslak"
Environment.setEnvironVar "Description" summary
Environment.setEnvironVar "PackageReleaseNotes" (release.Notes |> String.toLines)
Environment.setEnvironVar "PackageTags" "build;fake;f#"
Environment.setEnvironVar "PackageProjectUrl" "https://github.com/ionide/Forge"
Environment.setEnvironVar "PackageLicenseUrl" "https://raw.githubusercontent.com/ionide/Forge/master/LICENSE.txt"
DotNet.pack (fun p ->
{ p with
OutputPath = Some packageDir
Configuration = DotNet.BuildConfiguration.Release
}) "src/Forge"
)
Target.create "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]
Git.Staging.stageAll ""
Git.Commit.exec "" (sprintf "Bump version to %s" release.NugetVersion)
Git.Branches.pushBranch "" remote (Git.Information.getBranchName "")
Git.Branches.tag "" release.NugetVersion
Git.Branches.pushTag "" remote release.NugetVersion
let client =
let user =
match getBuildParam "github-user" with
| s when not (isNullOrWhiteSpace s) -> s
| _ -> UserInput.getUserInput "Username: "
let pw =
match getBuildParam "github-pw" with
| s when not (isNullOrWhiteSpace s) -> s
| _ -> UserInput.getUserPassword "Password: "
// Git.createClient user pw
GitHub.createClient user pw
let files = !! (packageDir </> "*.nupkg")
// release on github
let cl =
client
|> GitHub.draftNewRelease gitOwner gitName release.NugetVersion (release.SemVer.PreRelease <> None) release.Notes
(cl,files)
||> Seq.fold (fun acc e -> acc |> GitHub.uploadFile e)
|> GitHub.publishDraft//releaseDraft
|> Async.RunSynchronously
)
Target.create "Push" (fun _ ->
let key =
match getBuildParam "nuget-key" with
| s when not (isNullOrWhiteSpace s) -> s
| _ -> UserInput.getUserPassword "NuGet Key: "
Paket.push (fun p -> { p with WorkingDir = buildDir; ApiKey = key }))
// --------------------------------------------------------------------------------------
// Build order
// --------------------------------------------------------------------------------------
Target.create "Default" DoNothing
Target.create "Release" DoNothing
"Clean"
==> "InstallDotNetCLI"
==> "AssemblyInfo"
==> "Restore"
==> "Build"
==> "Publish"
==> "Test"
==> "Default"
"Default"
==> "Pack"
==> "ReleaseGitHub"
==> "Push"
==> "Release"
Target.runOrDefault "Default"