forked from fsprojects/FSharpLint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.fsx
160 lines (130 loc) · 5.24 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
// --------------------------------------------------------------------------------------
// 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
Target.initEnvironment()
// --------------------------------------------------------------------------------------
// Information about the project to be used at NuGet and in AssemblyInfo files
// --------------------------------------------------------------------------------------
let project = "FSharpLint"
let authors = "Matthew Mcveigh"
let gitOwner = "fsprojects"
let gitName = "FSharpLint"
let gitHome = "https://github.com/" + gitOwner
let gitUrl = gitHome + "/" + gitName
// --------------------------------------------------------------------------------------
// Build variables
// --------------------------------------------------------------------------------------
let buildDir = "./build/"
let nugetDir = "./out/"
System.Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
let changelogFilename = "CHANGELOG.md"
let changelog = Changelog.load changelogFilename
let nugetVersion =
match changelog.Unreleased with
| None ->
changelog.LatestEntry.NuGetVersion
| Some _unreleased ->
let current = changelog.LatestEntry.NuGetVersion |> SemVer.parse
let bumped = { current with
Minor = current.Minor + 1u
Patch = 0u
Original = None
PreRelease = PreRelease.TryParse "alpha01" }
string bumped
let packageReleaseNotes = sprintf "%s/blob/v%s/CHANGELOG.md" gitUrl nugetVersion
// --------------------------------------------------------------------------------------
// Helpers
// --------------------------------------------------------------------------------------
let isNullOrWhiteSpace = System.String.IsNullOrWhiteSpace
let exec cmd args dir =
let proc =
CreateProcess.fromRawCommandLine cmd args
|> CreateProcess.ensureExitCodeWithMessage (sprintf "Error while running '%s' with args: %s" cmd args)
(if isNullOrWhiteSpace dir then proc
else proc |> CreateProcess.withWorkingDirectory dir)
|> Proc.run
|> ignore
let getBuildParam = Environment.environVar
let DoNothing = ignore
// --------------------------------------------------------------------------------------
// Build Targets
// --------------------------------------------------------------------------------------
Target.create "Clean" (fun _ ->
Shell.cleanDirs [buildDir; nugetDir]
)
Target.create "Build" (fun _ ->
DotNet.build id "FSharpLint.sln"
)
let filterPerformanceTests (p:DotNet.TestOptions) = { p with Filter = Some "\"TestCategory!=Performance\""; Configuration = DotNet.Release }
Target.create "Test" (fun _ ->
DotNet.test filterPerformanceTests "tests/FSharpLint.Core.Tests"
DotNet.test filterPerformanceTests "tests/FSharpLint.Console.Tests"
DotNet.restore id "tests/FSharpLint.FunctionalTest.TestedProject/FSharpLint.FunctionalTest.TestedProject.sln"
DotNet.test filterPerformanceTests "tests/FSharpLint.FunctionalTest"
)
Target.create "Docs" (fun _ ->
exec "dotnet" @"fornax build" "docs"
)
// --------------------------------------------------------------------------------------
// Release Targets
// --------------------------------------------------------------------------------------
Target.create "BuildRelease" (fun _ ->
DotNet.build (fun p ->
{ p with
Configuration = DotNet.BuildConfiguration.Release
OutputPath = Some buildDir
MSBuildParams = { p.MSBuildParams with Properties = [("Version", nugetVersion); ("PackageReleaseNotes", packageReleaseNotes)]}
}
) "FSharpLint.sln"
)
Target.create "Pack" (fun _ ->
let properties = [
("Version", nugetVersion);
("Authors", authors)
("PackageProjectUrl", gitUrl)
("RepositoryType", "git")
("RepositoryUrl", gitUrl)
("PackageLicenseExpression", "MIT")
("PackageReleaseNotes", packageReleaseNotes)
]
DotNet.pack (fun p ->
{ p with
Configuration = DotNet.BuildConfiguration.Release
OutputPath = Some nugetDir
MSBuildParams = { p.MSBuildParams with Properties = properties }
}
) "FSharpLint.sln"
)
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 = nugetDir; ApiKey = key; ToolType = ToolType.CreateLocalTool() }))
// --------------------------------------------------------------------------------------
// Build order
// --------------------------------------------------------------------------------------
Target.create "Default" DoNothing
Target.create "Release" DoNothing
"Clean"
==> "Build"
==> "Test"
==> "Default"
"Clean"
==> "BuildRelease"
==> "Docs"
"Default"
==> "Pack"
==> "Push"
==> "Release"
Target.runOrDefaultWithArguments "Default"