-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.fsx
161 lines (128 loc) · 4.89 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
#I "packages/FAKE/tools/"
#r "FakeLib.dll"
#load "paket-files\dolly22\FAKE.Gitsemver\Gitsemver.fsx"
open Fake
open Fake.Git
open Fake.FSharpFormatting
open Fake.ReleaseNotesHelper
open Fake.AssemblyInfoFile
open Fake.SemVerHelper
open Gitsemver
let authors = ["Tomas Dolezal"]
let docsDir = "./artifacts/docs"
let buildDir = "./artifacts/build"
let mutable version : SemVerHelper.SemVerInfo option = None
let mutable currentGitSha : string = ""
let appendMygetPrerelease (semver: SemVerInfo, comitsSinceCreated: string) =
let buildRunner = environVar "BuildRunner"
let mygetBuild = buildRunner <> null && buildRunner.ToLowerInvariant() = "myget"
if mygetBuild then
// use myget coutner
let buildCounter = environVar "BuildCounter"
let buildCounterFixed = buildCounter.PadLeft(5, '0')
let versionWithBuild =
match semver.PreRelease with
| Some ver -> sprintf "%s-%s" ver.Origin buildCounterFixed
| _ -> sprintf "ci-%s" buildCounterFixed
let prereleaseInfo =
Some {
PreRelease.Origin = versionWithBuild
Name = versionWithBuild
Number = None
}
tracefn "[myget] Using semver prerelease: %A" versionWithBuild
{ semver with PreRelease = prereleaseInfo }
else
// use default handling, append prerelease counter only when specified
tracefn "Using local build versioning"
(semver, comitsSinceCreated)
|> appendPreReleaseBuildNumber 3
Target "Clean" (fun _ ->
!! "artifacts" ++ "src/*/bin"
|> DeleteDirs
)
Target "UpdateVersion" (fun _ ->
let semver =
getSemverInfoDefault
|> appendMygetPrerelease
version <- Some semver
currentGitSha <- getCurrentSHA1 currentDirectory
let fileVersion = sprintf "%d.%d.%d" semver.Major semver.Minor semver.Patch
let assemblyVersion = sprintf "%d.0.0" semver.Major
// update version info file
CreateFSharpAssemblyInfo "src/SolutionInfo.fs"
[ Attribute.Version assemblyVersion
Attribute.FileVersion fileVersion
Attribute.InformationalVersion (semver.ToString())
Attribute.Metadata("githash", currentGitSha) ]
tracefn "Using version: %A" version.Value
)
Target "BuildProjects" (fun _ ->
!! "src/*/*.fsproj"
|> Seq.iter(fun proj ->
build (fun p ->
{
p with
Targets = [ "Build" ]
Properties =
[
("Configuration", "Release");
("OutDir", currentDirectory @@ buildDir) ]
}) proj
)
)
Target "GenerateDocs" (fun _ ->
let toolRoot = "./packages/FSharp.Formatting.CommandTool";
let templatesDir = toolRoot @@ "templates/reference/"
let githubLink = "https://github.com/dolly22/FAKE.Dotnet"
let projInfo =
[ "page-description", "FAKE.Dotnet"
"page-author", separated ", " authors
"project-author", separated ", " authors
"github-link", githubLink
"project-github", githubLink
"project-nuget", "https://www.nuget.org/packages/FAKE.Dotnet"
"root", "http://dolly22.github.io/FAKE.Dotnet"
"project-name", "FAKE.Dotnet" ]
CreateDir docsDir
let dllFiles =
[ buildDir @@ "Fake.Dotnet.dll" ]
let apiDocsDir = docsDir @@ "apidocs"
CreateDir apiDocsDir
CreateDocsForDlls apiDocsDir templatesDir (projInfo @ ["--libDirs", buildDir]) (githubLink + "/blob/"+ currentGitSha) dllFiles
CopyDir (docsDir @@ "content") "help/content" allFiles
)
Target "UpdateDocs" (fun _ ->
let githubPagesDir = currentDirectory @@ "gh-pages"
CleanDir githubPagesDir
cloneSingleBranch "" "https://github.com/dolly22/FAKE.Dotnet" "gh-pages" githubPagesDir
fullclean githubPagesDir
CopyRecursive docsDir githubPagesDir true |> printfn "%A"
StageAll githubPagesDir
Commit githubPagesDir (sprintf "Update generated documentation %s" <| version.Value.ToString())
)
Target "NugetPack" (fun _ ->
CreateDir "artifacts"
let nugetVersion =
match version with
| None -> "0.0.1-dev"
| Some x -> x.ToString()
NuGetPackDirectly (fun p ->
{
p with
ToolPath = "packages/NuGet.CommandLine/tools/nuget.exe"
OutputPath = "artifacts"
WorkingDir = "artifacts"
Version = nugetVersion
}) "Fake.Dotnet.nuspec"
)
Target "Default" <| DoNothing
"Clean"
==> "UpdateVersion"
==> "BuildProjects"
==> "NugetPack"
==> "GenerateDocs"
=?> ("UpdateDocs", hasBuildParam "--update-docs")
==> "Default"
// start build
RunTargetOrDefault "Default"