Skip to content

Commit 341c231

Browse files
jeremyabbottKrzysztof-Cieslak
authored andcommitted
Use fake 5 api (#118)
* Update global.json to latest dotnet SDK * WIP * Clean up paket fake dependencies * build works with fake 5 * Updates build scripts to use fake global tool * Fixes build warnings in samples due to obsolete constructs * Updates some of the example comments
1 parent 6663614 commit 341c231

File tree

12 files changed

+856
-202
lines changed

12 files changed

+856
-202
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Debug
99
obj
1010
bin
1111

12+
### fake ###
13+
build.fsx.lock
1214

1315
### Linux ###
1416
*~

build.cmd

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
@echo off
2-
cls
1+
SET TOOL_PATH=.fake
32

4-
.paket\paket.exe restore
5-
if errorlevel 1 (
6-
exit /b %errorlevel%
3+
IF NOT EXIST "%TOOL_PATH%\fake.exe" (
4+
dotnet tool install fake-cli --tool-path ./%TOOL_PATH% --version 5.*
75
)
86

9-
packages\build\FAKE\tools\FAKE.exe build.fsx %*
7+
"%TOOL_PATH%/fake.exe build" %*

build.fsx

Lines changed: 76 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
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"
2325
let gitName = "Saturn"
2426
let gitHome = "https://github.com/" + gitOwner
2527

26-
2728
// --------------------------------------------------------------------------------------
2829
// Build variables
2930
// --------------------------------------------------------------------------------------
3031

3132
let 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
4042
let 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"

build.sh

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
1-
#!/bin/bash
2-
if test "$OS" = "Windows_NT"
3-
then
4-
# use .Net
1+
#!/usr/bin/env bash
52

6-
.paket/paket.exe restore
7-
exit_code=$?
8-
if [ $exit_code -ne 0 ]; then
9-
exit $exit_code
10-
fi
3+
set -eu
4+
set -o pipefail
115

12-
packages/build/FAKE/tools/FAKE.exe $@ --fsiargs build.fsx
13-
else
14-
# use mono
15-
mono .paket/paket.exe restore
16-
exit_code=$?
17-
if [ $exit_code -ne 0 ]; then
18-
exit $exit_code
19-
fi
20-
mono packages/build/FAKE/tools/FAKE.exe $@ --fsiargs -d:MONO build.fsx
6+
# liberated from https://stackoverflow.com/a/18443300/433393
7+
realpath() {
8+
OURPWD=$PWD
9+
cd "$(dirname "$1")"
10+
LINK=$(readlink "$(basename "$1")")
11+
while [ "$LINK" ]; do
12+
cd "$(dirname "$LINK")"
13+
LINK=$(readlink "$(basename "$1")")
14+
done
15+
REALPATH="$PWD/$(basename "$1")"
16+
cd "$OURPWD"
17+
echo "$REALPATH"
18+
}
19+
20+
TOOL_PATH=$(realpath .fake)
21+
FAKE="$TOOL_PATH"/fake
22+
23+
if ! [ -e "$FAKE" ]
24+
then
25+
dotnet tool install fake-cli --tool-path $TOOL_PATH --version 5.*
2126
fi
27+
28+
if [[ $# -eq 0 ]] ; then
29+
fake build
30+
else
31+
"$FAKE" build "$@"
32+
fi

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"sdk": {
3-
"version": "2.1.300"
3+
"version": "2.1.302"
44
}
55
}

paket.dependencies

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,15 @@ nuget Expecto
2525
group Build
2626
source https://www.nuget.org/api/v2
2727

28-
nuget FAKE
29-
github fsharp/FAKE modules/Octokit/Octokit.fsx
28+
nuget Fake.Core.Target
29+
nuget Fake.Core.Process
30+
nuget Fake.DotNet.Cli
31+
nuget Fake.Core.ReleaseNotes
32+
nuget Fake.DotNet.AssemblyInfoFile
33+
nuget Fake.DotNet.Paket
34+
nuget Fake.Tools.Git
35+
nuget Fake.Core.Environment
36+
nuget Fake.Core.UserInput
37+
nuget Fake.IO.FileSystem
38+
nuget Fake.DotNet.MsBuild
39+
nuget Fake.Api.GitHub

0 commit comments

Comments
 (0)