Skip to content

Commit

Permalink
fix formatting and formatting build tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
kMutagene committed Apr 1, 2022
1 parent fec9a3b commit 5c6f359
Show file tree
Hide file tree
Showing 41 changed files with 1,182 additions and 1,001 deletions.
33 changes: 14 additions & 19 deletions build/BasicTasks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,19 @@ open Fake.IO.Globbing.Operators

open ProjectInfo

let setPrereleaseTag = BuildTask.create "SetPrereleaseTag" [] {
printfn "Please enter pre-release package suffix"
let suffix = System.Console.ReadLine()
prereleaseSuffix <- suffix
prereleaseTag <- (sprintf "%s-%s" release.NugetVersion suffix)
isPrerelease <- true
}
let setPrereleaseTag =
BuildTask.create "SetPrereleaseTag" [] {
printfn "Please enter pre-release package suffix"
let suffix = System.Console.ReadLine()
prereleaseSuffix <- suffix
prereleaseTag <- (sprintf "%s-%s" release.NugetVersion suffix)
isPrerelease <- true
}

let clean = BuildTask.create "Clean" [] {
!! "src/**/bin"
++ "src/**/obj"
++ "tests/**/bin"
++ "tests/**/obj"
++ "pkg"
|> Shell.cleanDirs
}
let clean =
BuildTask.create "Clean" [] {
!! "src/**/bin" ++ "src/**/obj" ++ "tests/**/bin" ++ "tests/**/obj" ++ "pkg" |> Shell.cleanDirs
}

let build = BuildTask.create "Build" [clean] {
solutionFile
|> DotNet.build id
}
let build =
BuildTask.create "Build" [ clean ] { solutionFile |> DotNet.build id }
109 changes: 88 additions & 21 deletions build/Build.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,106 @@ open Fake.IO.Globbing.Operators
open Fake.Tools

open Helpers

initializeContext()

open BasicTasks
open TestTasks
open PackageTasks
open DocumentationTasks
open ReleaseTasks

initializeContext ()

let sourceFiles =
!! "src/Plotly.NET/**/*.fs"
++ "src/Plotly.NET.ImageExport/**/*.fs"
++ "src/Plotly.NET.Interactive/**/*.fs"
++ "build/*.fs"
-- "**/obj/**/*.*"
-- "**/bin/**/*.*"

let checkFormat =
BuildTask.create "CheckFormat" [] {
let result =
sourceFiles
|> Seq.map (sprintf "\"%s\"")
|> String.concat " "
|> sprintf "%s --check"
|> DotNet.exec id "fantomas"

if result.ExitCode = 0 then
Trace.log "No files need formatting"
elif result.ExitCode = 99 then
failwith "Some files need formatting, check output for more info"
else
Trace.logf "Errors while formatting: %A" result.Errors
}

let format =
BuildTask.create "Format" [] {
let result =
sourceFiles |> Seq.map (sprintf "\"%s\"") |> String.concat " " |> DotNet.exec id "fantomas"

if not result.OK then
printfn "Errors while formatting all files: %A" result.Messages
}


/// Full release of nuget package, git tag, and documentation for the stable version.
let _release =
BuildTask.createEmpty
"Release"
[clean; build; runTests; pack; buildDocs; createTag; publishNuget; releaseDocs]
let _release =
BuildTask.createEmpty
"Release"
[
clean
build
runTests
pack
buildDocs
createTag
publishNuget
releaseDocs
]

/// Full release of nuget package, git tag, and documentation for the prerelease version.
let _preRelease =
BuildTask.createEmpty
"PreRelease"
[setPrereleaseTag; clean; build; runTests; packPrerelease; buildDocsPrerelease; createPrereleaseTag; publishNugetPrerelease; prereleaseDocs]
let _preRelease =
BuildTask.createEmpty
"PreRelease"
[
setPrereleaseTag
clean
build
runTests
packPrerelease
buildDocsPrerelease
createPrereleaseTag
publishNugetPrerelease
prereleaseDocs
]

/// Full release of nuget package for the prerelease version.
let _releaseNoDocs =
BuildTask.createEmpty
"ReleaseNoDocs"
[clean; build; runTests; pack; createTag; publishNuget;]
let _releaseNoDocs =
BuildTask.createEmpty
"ReleaseNoDocs"
[
clean
build
runTests
pack
createTag
publishNuget
]

/// Full release of nuget package for the prerelease version.
let _preReleaseNoDocs =
BuildTask.createEmpty
"PreReleaseNoDocs"
[setPrereleaseTag; clean; build; runTests; packPrerelease; createPrereleaseTag; publishNugetPrerelease]
let _preReleaseNoDocs =
BuildTask.createEmpty
"PreReleaseNoDocs"
[
setPrereleaseTag
clean
build
runTests
packPrerelease
createPrereleaseTag
publishNugetPrerelease
]

[<EntryPoint>]
let main args =
runOrDefault build args
let main args = runOrDefault build args
70 changes: 43 additions & 27 deletions build/DocumentationTasks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,46 @@ open BasicTasks

open BlackFox.Fake

let buildDocs = BuildTask.create "BuildDocs" [build] {
printfn "building docs with stable version %s" stableVersionTag
runDotNet
(sprintf "fsdocs build --eval --clean --properties Configuration=Release --parameters fsdocs-package-version %s" stableVersionTag)
"./"
}

let buildDocsPrerelease = BuildTask.create "BuildDocsPrerelease" [setPrereleaseTag; build] {
printfn "building docs with prerelease version %s" prereleaseTag
runDotNet
(sprintf "fsdocs build --eval --clean --properties Configuration=Release --parameters fsdocs-package-version %s" prereleaseTag)
"./"
}

let watchDocs = BuildTask.create "WatchDocs" [build] {
printfn "watching docs with stable version %s" stableVersionTag
runDotNet
(sprintf "fsdocs watch --eval --clean --properties Configuration=Release --parameters fsdocs-package-version %s" stableVersionTag)
"./"
}

let watchDocsPrerelease = BuildTask.create "WatchDocsPrerelease" [setPrereleaseTag; build] {
printfn "watching docs with prerelease version %s" prereleaseTag
runDotNet
(sprintf "fsdocs watch --eval --clean --properties Configuration=Release --parameters fsdocs-package-version %s" prereleaseTag)
"./"
}
let buildDocs =
BuildTask.create "BuildDocs" [ build ] {
printfn "building docs with stable version %s" stableVersionTag

runDotNet
(sprintf
"fsdocs build --eval --clean --properties Configuration=Release --parameters fsdocs-package-version %s"
stableVersionTag)
"./"
}

let buildDocsPrerelease =
BuildTask.create "BuildDocsPrerelease" [ setPrereleaseTag; build ] {
printfn "building docs with prerelease version %s" prereleaseTag

runDotNet
(sprintf
"fsdocs build --eval --clean --properties Configuration=Release --parameters fsdocs-package-version %s"
prereleaseTag)
"./"
}

let watchDocs =
BuildTask.create "WatchDocs" [ build ] {
printfn "watching docs with stable version %s" stableVersionTag

runDotNet
(sprintf
"fsdocs watch --eval --clean --properties Configuration=Release --parameters fsdocs-package-version %s"
stableVersionTag)
"./"
}

let watchDocsPrerelease =
BuildTask.create "WatchDocsPrerelease" [ setPrereleaseTag; build ] {
printfn "watching docs with prerelease version %s" prereleaseTag

runDotNet
(sprintf
"fsdocs watch --eval --clean --properties Configuration=Release --parameters fsdocs-package-version %s"
prereleaseTag)
"./"
}
50 changes: 0 additions & 50 deletions build/FormattingTasks.fs

This file was deleted.

18 changes: 12 additions & 6 deletions build/Helpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,30 @@ open Fake.Core
open Fake.DotNet

let initializeContext () =
let execContext = Context.FakeExecutionContext.Create false "build.fsx" [ ]
let execContext =
Context.FakeExecutionContext.Create false "build.fsx" []

Context.setExecutionContext (Context.RuntimeContext.Fake execContext)

/// Executes a dotnet command in the given working directory
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

if result.ExitCode <> 0 then
failwithf "'dotnet %s' failed in %s" cmd workingDir

let runOrDefault defaultTarget args =
Trace.trace (sprintf "%A" args)

try
match args with
| [| target |] -> Target.runOrDefault target
| arr when args.Length > 1 ->
Target.run 0 (Array.head arr) ( Array.tail arr |> List.ofArray )
| arr when args.Length > 1 -> Target.run 0 (Array.head arr) (Array.tail arr |> List.ofArray)
| _ -> BuildTask.runOrDefault defaultTarget

0
with e ->
with
| e ->
printfn "%A" e
1
1
25 changes: 17 additions & 8 deletions build/MessagePrompts.fs
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
module MessagePrompts

let prompt (msg:string) =
let prompt (msg: string) =
System.Console.Write(msg)

System.Console.ReadLine().Trim()
|> function | "" -> None | s -> Some s
|> Option.map (fun s -> s.Replace ("\"","\\\""))
|> function
| "" -> None
| s -> Some s
|> Option.map (fun s -> s.Replace("\"", "\\\""))

let rec promptYesNo msg =
match prompt (sprintf "%s [Yn]: " msg) with
| Some "Y" | Some "y" -> true
| Some "N" | Some "n" -> false
| _ -> System.Console.WriteLine("Sorry, invalid answer"); promptYesNo msg
| Some "Y"
| Some "y" -> true
| Some "N"
| Some "n" -> false
| _ ->
System.Console.WriteLine("Sorry, invalid answer")
promptYesNo msg

let releaseMsg = """This will stage all uncommitted changes, push them to the origin and bump the release version to the latest number in the RELEASE_NOTES.md file.
let releaseMsg =
"""This will stage all uncommitted changes, push them to the origin and bump the release version to the latest number in the RELEASE_NOTES.md file.
Do you want to continue?"""

let releaseDocsMsg = """This will push the docs to gh-pages. Remember building the docs prior to this. Do you want to continue?"""
let releaseDocsMsg =
"""This will push the docs to gh-pages. Remember building the docs prior to this. Do you want to continue?"""
Loading

0 comments on commit 5c6f359

Please sign in to comment.