-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.fsx
162 lines (149 loc) · 6.86 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
#if FAKE
#r "paket: groupref Build //"
#endif
#load "./versionnumbering.fsx"
#load "./.fake/build.fsx/intellisense.fsx"
open Fake.Core
open Fake.DotNet
open Fake.IO
let ReleaseNotesLocation = System.IO.Path.Combine [|__SOURCE_DIRECTORY__;"./ReleaseNotes.txt"|]
type PublicDirs () =
static member Packagedirectory = System.IO.Path.Combine [|__SOURCE_DIRECTORY__;"./nuget_package"|]
static member Packagerepository = ""
module BuildDomain =
type Projectname =
|FsTensor
type Projectfile = Projectfile of string
type Directory = Directory of string
type Version = Version of string
type VersionDescription = VersionDescription of string
type Repository = Repository of string
type Assemblyfile = Assemblyfile of string
type Publishfunction = Directory -> Repository -> unit
type ReleaseNotesAssemblyFile =
{
version:Version
assemblyfile:Assemblyfile
attributes:AssemblyInfoFile.Attribute list
}
type BuildStep =
|Clean of Directory list
|Versioning of ReleaseNotesAssemblyFile
|PrePackage of Projectfile*Directory
|Package of Directory*Version
|Publish of Publishfunction*Projectname*Version*VersionDescription
module TargetBuilders =
open BuildDomain
let list_of_targets ((project,stappen):Projectname*BuildStep list) =
let projectname = sprintf "%A" project
stappen
|> List.map
(fun stap ->
match stap with
|Clean _ -> stap,"Clean"+projectname |> List.singleton
|Versioning _ -> stap,"Versioning"+projectname |> List.singleton
|PrePackage _ -> stap,"PrePackage"+projectname |> List.singleton
|Package _ -> stap,"Package"+projectname |> List.singleton
|Publish _ -> stap,"Publish"+projectname |> List.singleton
)
let generate_targets (steps:(BuildStep*string list)list) =
steps
|> List.iter (
fun (step,targetnames) ->
match step with
|Clean dirLijst ->
Target.create targetnames.Head
(fun _ -> dirLijst |> List.map (fun (Directory dirnaam) -> dirnaam) |> Shell.cleanDirs )
|Versioning releaseNotes ->
let (Version version) = releaseNotes.version
let (Assemblyfile assemblyfile) = releaseNotes.assemblyfile
Target.create targetnames.Head
(fun _ ->
releaseNotes.attributes@[AssemblyInfo.Version version]
|> AssemblyInfoFile.createFSharp assemblyfile
)
|PrePackage ((Projectfile projfile),(Directory dest)) ->
Target.create targetnames.Head (fun _ ->
CreateProcess.fromRawCommand "dotnet" ["publish";"--output";dest;"--configuration";"Release";projfile] |> Proc.run |> ignore
)
|Package (Directory src,Version version) ->
Target.create targetnames.Head (fun _ ->
Paket.pack (fun p ->
{ p with
WorkingDir = src
BuildConfig = "Release";
OutputPath = PublicDirs.Packagedirectory
Version = version
ReleaseNotes = Fake.Tools.Git.Branches.getSHA1 "./.git/" "HEAD"
MinimumFromLockFile = false
}
)
)
|Publish (publishfunctie,name,Version version,VersionDescription description) ->
Target.create targetnames.Head (fun _ ->
publishfunctie (Directory PublicDirs.Packagedirectory) (Repository PublicDirs.Packagerepository)
System.IO.File.AppendAllLines
(ReleaseNotesLocation,
[
sprintf "Timestamp: %A" System.DateTime.Now
sprintf "Assembly : %A" name
sprintf "Version : %s" version
sprintf "Description: %s\n" description
])
)
)
module SetTargets =
open BuildDomain
let publish_to_repository (Directory src) (Repository repo) =
// let nugetPath = System.IO.Path.Combine [|__SOURCE_DIRECTORY__;"nuget";"nuget.exe"|]
// CreateProcess.fromRawCommand nugetPath ["init";src;repo] |> Proc.run |> ignore
() // to be done
Target.create "CleanPackages" (fun _ -> [PublicDirs.Packagedirectory] |> Shell.cleanDirs)
let fsTensorBuild =
(FsTensor,
[
Clean [Directory "src/FsTensor/bin/";Directory "src/FsTensor/obj/";Directory "src/FsTensor/publish"]
Versioning
{
version = Version Versionnumbering.fsTensorVersion
assemblyfile = Assemblyfile "src/FsTensor/AssemblyInfo.fs"
attributes =
[
AssemblyInfo.Title "FsTensor"
AssemblyInfo.Description
("FsTensor, Tensor manipulations and calculations as part of FsLab\n"+Versionnumbering.fsTensorDescription)
AssemblyInfo.Company "F# incubation space"
]
}
PrePackage (Projectfile "src/FsTensor/FsTensor.fsproj",Directory "src/FsTensor/publish")
Package (Directory "src/FsTensor/",Version Versionnumbering.fsTensorVersion)
Publish
(publish_to_repository,
FsTensor,
Version Versionnumbering.fsTensorVersion,
VersionDescription Versionnumbering.fsTensorDescription)
]
)
do
[
fsTensorBuild
]
|> List.iter (
fun targetProject ->
targetProject
|> TargetBuilders.list_of_targets
|> fun targets ->
do
targets
|> List.map (snd >> String.concat " ")
|> String.concat " "
|> Fake.Core.Trace.trace
targets |> TargetBuilders.generate_targets
)
open Fake.Core.TargetOperators
"CleanFsTensor"
==> "VersioningFsTensor"
==> "PrepackageFsTensor"
==> "PackageFsTensor" // not working yet
==> "PublishFsTensor" // not working yet
Target.runOrDefault "PrepackageFsTensor"