-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.fsx
169 lines (132 loc) · 5.15 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
163
164
165
166
167
168
#r "paket: groupref Build //"
#load ".fake/build.fsx/intellisense.fsx"
open System
open System.IO
open Fake.Core
open Fake.Core.TargetOperators
open Fake.DotNet
open Fake.IO
open Fake.IO.Globbing.Operators
open Fake.Tools
open System.Text.RegularExpressions
do Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
let notes = ReleaseNotes.load "RELEASE_NOTES.md"
let isWindows =
Environment.OSVersion.Platform <> PlatformID.Unix && Environment.OSVersion.Platform <> PlatformID.MacOSX
Target.create "Clean" (fun _ ->
if Directory.Exists "bin/Debug" then
Trace.trace "deleting bin/Debug"
Directory.delete "bin/Debug"
if Directory.Exists "bin/Release" then
Trace.trace "deleting bin/Release"
Directory.delete "bin/Release"
let pkgs = !!"bin/*.nupkg" |> Seq.toList
if not (List.isEmpty pkgs) then
Trace.tracefn "deleting packages: %s" (pkgs |> Seq.map Path.GetFileNameWithoutExtension |> String.concat ", ")
File.deleteAll pkgs
let dirs = Directory.EnumerateDirectories("src", "obj", SearchOption.AllDirectories) |> Seq.toList
if not (List.isEmpty dirs) then
for d in dirs do
let parent = Path.GetDirectoryName d
let proj = Directory.GetFiles(parent, "*.fsproj") |> Seq.isEmpty |> not
if proj then
Trace.tracefn "deleting %s" d
Directory.delete d
)
Target.create "Compile" (fun _ ->
let options (o : DotNet.BuildOptions) =
let v = sprintf "%d.%d.%d.%s" notes.SemVer.Major notes.SemVer.Minor notes.SemVer.Patch (string notes.SemVer.Build)
{ o with
Configuration = DotNet.BuildConfiguration.Release
MSBuildParams =
{ o.MSBuildParams with
Properties =
[
"GenerateAssemblyInfo", "true"
"AssemblyVersion", v
"FileVersion", v
"AssemblyFileVersion", v
"ProductVersion", v
"InformationalVersion", v
]
}
}
DotNet.build options "lensfun-net.sln"
)
Target.create "Pack" (fun _ ->
Paket.pack (fun o ->
{ o with
WorkingDir = Environment.CurrentDirectory
OutputPath = "bin"
PinProjectReferences = true
ProjectUrl = "https://github.com/haraldsteinlechner/lensfun.NET"
Version = notes.NugetVersion
ReleaseNotes = String.concat "\n" notes.Notes
}
)
"src/tool/lensfunNet-undist.fsproj" |> DotNet.pack (fun o ->
{ o with
NoRestore = true
NoBuild = true
MSBuildParams = { o.MSBuildParams with Properties = ["Version", notes.NugetVersion] }
}
)
)
Target.create "Push" (fun _ ->
let packageNameRx = Regex @"^(?<name>[a-zA-Z_0-9\.-]+?)\.(?<version>([0-9]+\.)*[0-9]+.*?)\.nupkg$"
if not (Git.Information.isCleanWorkingCopy ".") then
Git.Information.showStatus "."
failwith "repo not clean"
if File.exists "deploy.targets" then
let packages =
!!"bin/*.nupkg"
|> Seq.filter (fun path ->
let name = Path.GetFileName path
let m = packageNameRx.Match name
if m.Success then
m.Groups.["version"].Value = notes.NugetVersion
else
false
)
|> Seq.toList
let targetsAndKeys =
File.ReadAllLines "deploy.targets"
|> Array.map (fun l -> l.Split(' '))
|> Array.choose (function [|dst; key|] -> Some (dst, key) | _ -> None)
|> Array.choose (fun (dst, key) ->
let path =
Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
".ssh",
key
)
if File.exists path then
let key = File.ReadAllText(path).Trim()
Some (dst, key)
else
None
)
|> Map.ofArray
Git.CommandHelper.directRunGitCommandAndFail "." "fetch --tags"
Git.Branches.tag "." notes.NugetVersion
let branch = Git.Information.getBranchName "."
Git.Branches.pushBranch "." "origin" branch
if List.isEmpty packages then
failwith "no packages produced"
if Map.isEmpty targetsAndKeys then
failwith "no deploy targets"
for (dst, key) in Map.toSeq targetsAndKeys do
Trace.tracefn "pushing to %s" dst
let options (o : Paket.PaketPushParams) =
{ o with
PublishUrl = dst
ApiKey = key
WorkingDir = "bin"
}
Paket.pushFiles options packages
Git.Branches.pushTag "." "origin" notes.NugetVersion
()
)
"Compile" ==> "Pack" ==> "Push"
Target.create "Default" ignore
Target.runOrDefault "Default"