-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.fsx
More file actions
168 lines (133 loc) · 4.88 KB
/
build.fsx
File metadata and controls
168 lines (133 loc) · 4.88 KB
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
#r "paket: groupref build //"
#load "./.fake/build.fsx/intellisense.fsx"
#if !FAKE
#r "netstandard"
#r "Facades/netstandard" // https://github.com/ionide/ionide-vscode-fsharp/issues/839#issuecomment-396296095
#endif
open System
open Fake.Core
open Fake.DotNet
open Fake.IO
open System
open System.IO
open Fake
open Fake.Tools.Git
open Fake.DotNet
open Fake.IO
open Fake.IO.FileSystemOperators
open Fake.IO.Globbing.Operators
open Fake.Core.TargetOperators
open Fake.Tools
open Fake.Core
let project = "TypeSpec"
let summary = "Versionable Type Contracts"
let gitOwner = "musheddev"
let gitHome = "https://github.com/" + gitOwner
let gitName = "TypeSpec"
let release = ReleaseNotes.load "RELEASE_NOTES.md"
let srcPath = Path.getFullName "./src/TypeSpec"
module Util =
let join pathParts =
Path.Combine(Array.ofSeq pathParts)
let runDotNet cmd workingDir =
let result =
DotNet.exec (DotNet.Options.withWorkingDirectory workingDir) cmd ""
if result.ExitCode <> 0 then failwithf "'dotnet %s' failed in %s" cmd workingDir
// let normalizeVersion (version: string) =
// let i = version.IndexOf("-")
// if i > 0 then version.Substring(0, i) else version
// let assemblyInfo projectDir extra =
// let asmInfoPath = projectDir </> "AssemblyInfo.fs"
// (AssemblyInfo.Version release.AssemblyVersion) :: extra
// |> AssemblyInfoFile.createFSharp asmInfoPath
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)
)
Target.create "AssemblyInfo" (fun _ ->
!! "src/**/*.??proj"
|> Seq.map Util.getProjectDetails
|> Seq.iter (fun (projFileName, _, folderName, attributes) ->
match projFileName with
| Fsproj -> AssemblyInfoFile.createFSharp (folderName </> "AssemblyInfo.fs") attributes
| Csproj -> AssemblyInfoFile.createCSharp ((folderName </> "Properties") </> "AssemblyInfo.cs") attributes
| Shproj -> ()
)
)
Target.create "CopyBinaries" (fun _ ->
!! "src/**/*.??proj"
-- "src/**/*.shproj"
-- "src/netcore/**/*.??proj"
|> Seq.map (fun f -> ((System.IO.Path.GetDirectoryName f) </> "bin/Release", "bin" </> (System.IO.Path.GetFileNameWithoutExtension f)))
|> Seq.iter (fun (fromDir, toDir) -> Shell.copyDir toDir fromDir (fun _ -> true))
)
Target.create "Clean" (fun _ ->
Shell.cleanDirs ["bin"]
)
Target.create "CleanDocs" (fun _ ->
Shell.cleanDirs ["docs/output"]
)
Target.create "Restore" (fun _ ->
!! "src/**/*.??proj"
-- "src/**/*.shproj"
|> Seq.iter (DotNet.restore id))
Target.create "Build" (fun _ ->
!! "src/**/*.??proj"
-- "src/**/*.shproj"
|> Seq.iter (DotNet.build (fun options ->
{ options with
Configuration = DotNet.BuildConfiguration.Release
Common = { options.Common with
CustomParams = Some "--no-restore" } })))
Target.create "RunTests" (fun _ ->
let restore =
DotNet.restore id
let build =
DotNet.build (fun options ->
{ options with
Configuration = DotNet.BuildConfiguration.Release
Common = { options.Common with
CustomParams = Some "--no-restore" } })
let runTests (project : string) =
restore project
build project
DotNet.test (fun options ->
{ options with
Configuration = DotNet.BuildConfiguration.Release
Common = { options.Common with
CustomParams = Some "--no-build -v=normal" } }) project
runTests "tests/FSharp.Data.GraphQL.Tests/FSharp.Data.GraphQL.Tests.fsproj")
let pack id =
Shell.cleanDir <| sprintf "nuget/%s.%s" project id
Paket.pack(fun p ->
{ p with
Version = release.NugetVersion
OutputPath = sprintf "nuget/%s.%s" project id
TemplateFile = sprintf "src/%s.%s/%s.%s.fsproj.paket.template" project id project id
MinimumFromLockFile = true
IncludeReferencedProjects = false })
let publishPackage id =
pack id
Paket.push(fun p ->
{ p with
WorkingDir = sprintf "nuget/%s.%s" project id
PublishUrl = "https://www.nuget.org/api/v2/package" })
Target.create "Publish" (fun _ ->
publishPackage "TypeSpec"
)
open Fake.Core.TargetOperators
"Clean"
==> "AssemblyInfo"
==> "Build"
"Build"
==> "RunTests"
Target.runOrDefault "Build"