11// --------------------------------------------------------------------------------------
22// FAKE build script
33// --------------------------------------------------------------------------------------
4- #r " ./packages/build/FAKE/tools/FakeLib.dll"
5- #load " paket-files/build/fsharp/FAKE/modules/Octokit/Octokit.fsx"
6-
7- open Fake.ReleaseNotesHelper
8- open Fake.AssemblyInfoFile
9- open Fake.Git
10- open Fake
11- open System
12- open Octokit
4+ #r " paket: groupref build //"
5+ #load " .fake/build.fsx/intellisense.fsx"
6+
7+ open Fake.Core
8+ open Fake.DotNet
9+ open Fake.Tools
10+ open Fake.IO
11+ open Fake.IO .FileSystemOperators
12+ open Fake.IO .Globbing .Operators
13+ open Fake.Core .TargetOperators
14+ open Fake.Api
1315
1416// --------------------------------------------------------------------------------------
1517// Information about the project to be used at NuGet and in AssemblyInfo files
@@ -23,44 +25,50 @@ let gitOwner = "Krzysztof-Cieslak"
2325let gitName = " Saturn"
2426let gitHome = " https://github.com/" + gitOwner
2527
26-
2728// --------------------------------------------------------------------------------------
2829// Build variables
2930// --------------------------------------------------------------------------------------
3031
3132let buildDir = " ./build/"
32- let dotnetcliVersion = DotNetCli.GetDotNetSDKVersionFromGlobalJson ()
33+ let dotnetcliVersion = DotNet.getSDKVersionFromGlobalJson ()
3334
34- Environment.CurrentDirectory <- __ SOURCE_ DIRECTORY__
35- let release = parseReleaseNotes ( IO.File.ReadAllLines " RELEASE_NOTES.md" )
35+ System. Environment.CurrentDirectory <- __ SOURCE_ DIRECTORY__
36+ let release = ReleaseNotes.parse ( System. IO.File.ReadAllLines " RELEASE_NOTES.md" )
3637
3738// --------------------------------------------------------------------------------------
3839// Helpers
3940// --------------------------------------------------------------------------------------
41+ let isNullOrWhiteSpace = System.String.IsNullOrWhiteSpace
4042let exec cmd args dir =
41- if execProcess( fun info ->
42- info.FileName <- cmd
43- if not ( String.IsNullOrWhiteSpace dir) then
44- info.WorkingDirectory <- dir
45- info.Arguments <- args
46- ) System.TimeSpan.MaxValue = false then
47- failwithf " Error while running '%s ' with args: %s " cmd args
48-
43+ if Process.execSimple( fun info ->
44+
45+ { info with
46+ FileName = cmd
47+ WorkingDirectory =
48+ if ( isNullOrWhiteSpace dir) then info.WorkingDirectory
49+ else dir
50+ Arguments = args
51+ }
52+ ) System.TimeSpan.MaxValue <> 0 then
53+ failwithf " Error while running '%s ' with args: %s " cmd args
54+ let getBuildParam = Environment.environVar
55+
56+ let DoNothing = ignore
4957// --------------------------------------------------------------------------------------
5058// Build Targets
5159// --------------------------------------------------------------------------------------
5260
53- Target " Clean" ( fun _ ->
54- CleanDirs [ buildDir]
61+ Target.create " Clean" ( fun _ ->
62+ Shell.cleanDirs [ buildDir]
5563)
5664
57- Target " AssemblyInfo" ( fun _ ->
65+ Target.create " AssemblyInfo" ( fun _ ->
5866 let getAssemblyInfoAttributes projectName =
59- [ Attribute .Title projectName
60- Attribute .Product project
61- Attribute .Description summary
62- Attribute .Version release.AssemblyVersion
63- Attribute .FileVersion release.AssemblyVersion ]
67+ [ AssemblyInfo .Title projectName
68+ AssemblyInfo .Product project
69+ AssemblyInfo .Description summary
70+ AssemblyInfo .Version release.AssemblyVersion
71+ AssemblyInfo .FileVersion release.AssemblyVersion ]
6472
6573 let getProjectDetails projectPath =
6674 let projectName = System.IO.Path.GetFileNameWithoutExtension( projectPath)
@@ -74,35 +82,37 @@ Target "AssemblyInfo" (fun _ ->
7482 |> Seq.map getProjectDetails
7583 |> Seq.iter ( fun ( projFileName , _ , folderName , attributes ) ->
7684 match projFileName with
77- | Fsproj -> CreateFSharpAssemblyInfo ( folderName </> " AssemblyInfo.fs" ) attributes
78- | Csproj -> CreateCSharpAssemblyInfo (( folderName </> " Properties" ) </> " AssemblyInfo.cs" ) attributes
79- | Vbproj -> CreateVisualBasicAssemblyInfo (( folderName </> " My Project" ) </> " AssemblyInfo.vb" ) attributes
80- | Shproj -> ()
85+ | proj when proj.EndsWith ( " fsproj " ) -> AssemblyInfoFile.createFSharp ( folderName </> " AssemblyInfo.fs" ) attributes
86+ | proj when proj.EndsWith ( " csproj " ) -> AssemblyInfoFile.createCSharp (( folderName </> " Properties" ) </> " AssemblyInfo.cs" ) attributes
87+ | proj when proj.EndsWith ( " vbproj " ) -> AssemblyInfoFile.createVisualBasic (( folderName </> " My Project" ) </> " AssemblyInfo.vb" ) attributes
88+ | _ -> ()
8189 )
8290)
8391
84- Target " InstallDotNetCLI" ( fun _ ->
85- DotNetCli.InstallDotNetSDK dotnetcliVersion |> ignore
86- )
92+ Target.create " InstallDotNetCLI" ( fun _ ->
93+ let version = DotNet.CliVersion.Version dotnetcliVersion
94+ let options = DotNet.Options.Create()
95+ DotNet.install ( fun opts -> { opts with Version = version }) options |> ignore
96+ )
8797
88- Target " Restore" ( fun _ ->
89- DotNetCli.Restore id
98+ Target.create " Restore" ( fun _ ->
99+ DotNet.restore id " "
90100)
91101
92- Target " Build" ( fun _ ->
93- DotNetCli.Build id
102+ Target.create " Build" ( fun _ ->
103+ DotNet.build id " "
94104)
95105
96- Target " Test" ( fun _ ->
106+ Target.create " Test" ( fun _ ->
97107 exec " dotnet" @" run --project .\tests\Saturn.UnitTests\Saturn.UnitTests.fsproj" " ."
98108)
99109
100110// --------------------------------------------------------------------------------------
101111// Release Targets
102112// --------------------------------------------------------------------------------------
103113
104- Target " Pack" ( fun _ ->
105- Paket.Pack ( fun p ->
114+ Target.create " Pack" ( fun _ ->
115+ Paket.pack ( fun p ->
106116 { p with
107117 BuildConfig = " Release" ;
108118 OutputPath = buildDir;
@@ -113,53 +123,55 @@ Target "Pack" (fun _ ->
113123 )
114124)
115125
116- Target " ReleaseGitHub" ( fun _ ->
126+ Target.create " ReleaseGitHub" ( fun _ ->
117127 let remote =
118128 Git.CommandHelper.getGitResult " " " remote -v"
119129 |> Seq.filter ( fun ( s : string ) -> s.EndsWith( " (push)" ))
120130 |> Seq.tryFind ( fun ( s : string ) -> s.Contains( gitOwner + " /" + gitName))
121131 |> function None -> gitHome + " /" + gitName | Some ( s: string) -> s.Split().[ 0 ]
122132
123- StageAll " "
124- Git.Commit.Commit " " ( sprintf " Bump version to %s " release.NugetVersion)
125- Branches.pushBranch " " remote ( Information.getBranchName " " )
133+ Git.Staging.stageAll " "
134+ Git.Commit.exec " " ( sprintf " Bump version to %s " release.NugetVersion)
135+ Git.Branches.pushBranch " " remote ( Git.Information.getBranchName " " )
136+
126137
127- Branches.tag " " release.NugetVersion
128- Branches.pushTag " " remote release.NugetVersion
138+ Git. Branches.tag " " release.NugetVersion
139+ Git. Branches.pushTag " " remote release.NugetVersion
129140
130141 let client =
131142 let user =
132143 match getBuildParam " github-user" with
133- | s when not ( String.IsNullOrWhiteSpace s) -> s
134- | _ -> getUserInput " Username: "
144+ | s when not ( isNullOrWhiteSpace s) -> s
145+ | _ -> UserInput. getUserInput " Username: "
135146 let pw =
136147 match getBuildParam " github-pw" with
137- | s when not ( String.IsNullOrWhiteSpace s) -> s
138- | _ -> getUserPassword " Password: "
148+ | s when not ( isNullOrWhiteSpace s) -> s
149+ | _ -> UserInput. getUserPassword " Password: "
139150
140- createClient user pw
151+ // Git.createClient user pw
152+ GitHub.createClient user pw
141153 let file = !! ( buildDir </> " *.nupkg" ) |> Seq.head
142154
143155 // release on github
144156 client
145- |> createDraft gitOwner gitName release.NugetVersion ( release.SemVer.PreRelease <> None) release.Notes
146- |> uploadFile file
147- |> releaseDraft
157+ |> GitHub.draftNewRelease gitOwner gitName release.NugetVersion ( release.SemVer.PreRelease <> None) release.Notes
158+ |> GitHub. uploadFile file
159+ |> GitHub.publishDraft // releaseDraft
148160 |> Async.RunSynchronously
149161)
150162
151- Target " Push" ( fun _ ->
163+ Target.create " Push" ( fun _ ->
152164 let key =
153165 match getBuildParam " nuget-key" with
154- | s when not ( String.IsNullOrWhiteSpace s) -> s
155- | _ -> getUserPassword " NuGet Key: "
156- Paket.Push ( fun p -> { p with WorkingDir = buildDir; ApiKey = key }))
166+ | s when not ( isNullOrWhiteSpace s) -> s
167+ | _ -> UserInput. getUserPassword " NuGet Key: "
168+ Paket.push ( fun p -> { p with WorkingDir = buildDir; ApiKey = key }))
157169
158170// --------------------------------------------------------------------------------------
159171// Build order
160172// --------------------------------------------------------------------------------------
161- Target " Default" DoNothing
162- Target " Release" DoNothing
173+ Target.create " Default" DoNothing
174+ Target.create " Release" DoNothing
163175
164176" Clean"
165177 ==> " InstallDotNetCLI"
@@ -175,4 +187,4 @@ Target "Release" DoNothing
175187 ==> " Push"
176188 ==> " Release"
177189
178- RunTargetOrDefault " Default"
190+ Target.runOrDefault " Default"
0 commit comments