-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.fsx
131 lines (109 loc) · 3.34 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
#I @"./packages/FAKE/tools"
#r @"./packages/FAKE/tools/FakeLib.dll"
open System
open Fake
open Fake.Git
open Fake.AssemblyInfoFile
type Version = { Major:int; Minor:int; Build:int }
[<AutoOpen>]
module Helpers =
let parseVersion (v:string) =
let regex = new System.Text.RegularExpressions.Regex("^(\d+).(\d+).(\d+)$");
let m = regex.Match(v.Trim())
if not (m.Success) then failwithf "Invalid version file: %A" v
let getValue (x:int) = m.Groups.Item(x).Value |> System.Int32.Parse
{ Major = getValue 1;
Minor = getValue 2;
Build = getValue 3 }
let versionToString version =
sprintf "%d.%d.%d" version.Major version.Minor version.Build
let versionToCommitMsg version =
version
|> versionToString
|> sprintf "v-%s"
let getVersion () =
ReadFileAsString "version.txt"
|> parseVersion
let getCommitMsg () =
getVersion ()
|> versionToCommitMsg
let writeVersion version =
version
|> versionToString
|> WriteStringToFile false "version.txt"
Target "Build" <| fun _ ->
let version = getVersion () |> versionToString
CreateFSharpAssemblyInfo "./core/AssemblyInfo.fs" [
Attribute.Title "FSpec"
Attribute.Version version
Attribute.FileVersion version
]
CreateFSharpAssemblyInfo "./FSpec.AutoFoq/AssemblyInfo.fs" [
Attribute.Title "FSpec.AutoFoq"
Attribute.Version version
Attribute.FileVersion version
]
CreateFSharpAssemblyInfo "./FSpec.MbUnitWrapper/AssemblyInfo.fs" [
Attribute.Title "FSpec.MbUnitWrapper"
Attribute.Version version
Attribute.FileVersion version
]
let result = ExecProcess (fun info ->
info.FileName <- "c:\\Ruby193\\bin\\rake.bat"
info.WorkingDirectory <- ".") (TimeSpan.FromMinutes 5.0)
if result <> 0 then failwithf "MyProc.exe returned with a non-zero exit code"
Target "CreatePackage" <| fun _ ->
let version = getVersion() |> versionToString
ensureDirectory "NuGet"
NuGet (fun p ->
{p with
Version = version
WorkingDir = "."
})
"fspec.nuspec"
NuGet (fun p ->
{p with
Version = version
WorkingDir = "."
})
"FSpec.AutoFoq.nuspec"
NuGet (fun p ->
{p with
Version = version
WorkingDir = "."
})
"FSpec.MbUnitWrapper.nuspec"
Target "IncBuildNo" <| fun _ ->
let version = getVersion()
{ version with Build = version.Build + 1 }
|> writeVersion
Target "IncMinorVersion" <| fun _ ->
let version = getVersion()
{ version with Build = 0; Minor = version.Minor + 1 }
|> writeVersion
Target "Commit" <| fun _ ->
StageAll "."
let commitMsg = getCommitMsg ()
Commit "." commitMsg
sprintf "tag %s" commitMsg
|> runSimpleGitCommand "."
|> trace
// Default target
Target "Default" <| fun _ -> ()
Target "TestCreateBuild" <| fun _ ->
run "IncBuildNo"
run "Build"
run "CreatePackage"
Target "TestCreateMinor" <| fun _ ->
run "IncMinorVersion"
run "Build"
run "CreatePackage"
Target "CreateBuild" <| fun _ ->
run "TestCreateBuild"
run "Commit"
Target "CreateMinor" <| fun _ ->
run "TestCreateMinor"
run "Commit"
"Build" ==> "Default"
// start build
RunTargetOrDefault "Default"