Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fantomas5 #194

Merged
merged 8 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
"commands": [
"fable"
]
},
"fantomas": {
"version": "5.0.3",
"commands": [
"fantomas"
]
}
}
}
26 changes: 26 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
; EditorConfig helps developers define and maintain consistent
; coding styles between different editors and IDEs.

; For more visit http://editorconfig.org.
root = true

; Choose between lf or rf on "end_of_line" property
[*]
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[{*.fs,*.fsx}]
indent_size = 4
indent_style = space
max_line_length=150
fsharp_max_function_binding_width=10
fsharp_max_infix_operator_expression=70
fsharp_space_before_parameter=false
fsharp_space_before_lowercase_invocation=false
fsharp_multiline_block_brackets_on_same_column=true
fsharp_experimental_stroustrup_style=true
fsharp_bar_before_discriminated_union_declaration=true
fsharp_keep_max_number_of_blank_lines=3
186 changes: 111 additions & 75 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ source https://api.nuget.org/v3/index.json
framework net6.0
nuget FSharp.Core
nuget Fake.Core.Target
nuget Fake.Core.ReleaseNotes
nuget Fake.Core.ReleaseNotes
nuget Fake.IO.FileSystem
nuget Fake.Tools.Git
nuget Fake.Runtime
nuget Fake.DotNet.Paket
nuget Fake.DotNet.AssemblyInfoFile
nuget Fake.DotNet.Cli
nuget Fake.DotNet.Cli
nuget Fake.DotNet.MSBuild
nuget Fake.DotNet.Paket
nuget Fake.DotNet.Testing.Expecto
Expand Down Expand Up @@ -44,79 +44,77 @@ let configuration = "Release"
let release = ReleaseNotes.load "RELEASE_NOTES.md"

// Helper active pattern for project types
let (|Fsproj|Csproj|Vbproj|) (projFileName:string) =
let (|Fsproj|Csproj|Vbproj|)(projFileName: string) =
match projFileName with
| f when f.EndsWith("fsproj") -> Fsproj
| f when f.EndsWith("csproj") -> Csproj
| f when f.EndsWith("vbproj") -> Vbproj
| _ -> failwith (sprintf "Project file %s not supported. Unknown project type." projFileName)
| _ -> failwith(sprintf "Project file %s not supported. Unknown project type." projFileName)

// Generate assembly info files with the right version & up-to-date information
Target.create "AssemblyInfo" (fun _ ->
let getAssemblyInfoAttributes projectName =
[ AssemblyInfo.Title (projectName)
AssemblyInfo.Product "FSharpx.Collections"
AssemblyInfo.Description "FSharpx.Collections is a collection of datastructures for use with F# and C#."
AssemblyInfo.InternalsVisibleTo "FSharpx.Collections.Tests"
AssemblyInfo.InternalsVisibleTo "FSharpx.Collections.Experimental.Tests"
AssemblyInfo.Version release.AssemblyVersion
AssemblyInfo.FileVersion release.AssemblyVersion
AssemblyInfo.Configuration configuration ]

let getProjectDetails (projectPath:string) =
let getAssemblyInfoAttributes projectName = [
AssemblyInfo.Title(projectName)
AssemblyInfo.Product "FSharpx.Collections"
AssemblyInfo.Description "FSharpx.Collections is a collection of datastructures for use with F# and C#."
AssemblyInfo.InternalsVisibleTo "FSharpx.Collections.Tests"
AssemblyInfo.InternalsVisibleTo "FSharpx.Collections.Experimental.Tests"
AssemblyInfo.Version release.AssemblyVersion
AssemblyInfo.FileVersion release.AssemblyVersion
AssemblyInfo.Configuration configuration
]

let getProjectDetails(projectPath: string) =
let projectName = System.IO.Path.GetFileNameWithoutExtension(projectPath)
( projectPath,
projectName,
System.IO.Path.GetDirectoryName(projectPath),
(getAssemblyInfoAttributes projectName)
)
(projectPath, projectName, System.IO.Path.GetDirectoryName(projectPath), (getAssemblyInfoAttributes projectName))

!! "src/**/*.??proj"
|> Seq.map getProjectDetails
|> Seq.iter (fun (projFileName, _, folderName, attributes) ->
|> Seq.iter(fun (projFileName, _, folderName, attributes) ->
match projFileName with
| Fsproj -> AssemblyInfoFile.createFSharp (folderName </> "AssemblyInfo.fs") attributes
| Csproj -> AssemblyInfoFile.createCSharp ((folderName </> "Properties") </> "AssemblyInfo.cs") attributes
| Vbproj -> AssemblyInfoFile.createVisualBasic ((folderName </> "My Project") </> "AssemblyInfo.vb") attributes
)
)
| Vbproj -> AssemblyInfoFile.createVisualBasic ((folderName </> "My Project") </> "AssemblyInfo.vb") attributes))

// --------------------------------------------------------------------------------------
// Clean build results

let buildConfiguration = DotNet.Custom <| Environment.environVarOrDefault "configuration" configuration
let buildConfiguration =
DotNet.Custom
<| Environment.environVarOrDefault "configuration" configuration

Target.create "Clean" (fun _ ->
Shell.cleanDirs ["bin"; "temp"]
)
Target.create "Clean" (fun _ -> Shell.cleanDirs [ "bin"; "temp" ])

// --------------------------------------------------------------------------------------
// Build library & test project

Target.create "Build" (fun _ ->
"FSharpx.Collections.sln"
|> DotNet.build (fun p ->
|> DotNet.build(fun p ->
{ p with
Configuration = buildConfiguration})
)
Configuration = buildConfiguration
}))

// --------------------------------------------------------------------------------------
// Run the unit tests using test runner

Target.create "RunTests" (fun _ ->
!! "tests/**/bin/Release/net6.0/*Tests.dll"
|> Expecto.run (fun x ->
{ x with
|> Expecto.run(fun x ->
{ x with
Parallel = true
ParallelWorkers = System.Environment.ProcessorCount})
)
ParallelWorkers = System.Environment.ProcessorCount
}))

Target.create "RunTestsFable" (fun _ ->
let setParams = (fun (o : Yarn.YarnParams) -> { o with WorkingDirectory = "tests/fable" })
let setParams =
(fun (o: Yarn.YarnParams) ->
{ o with
WorkingDirectory = "tests/fable"
})

Yarn.installPureLock setParams
Yarn.exec "test" setParams
)
Yarn.exec "test" setParams)

// --------------------------------------------------------------------------------------
// Build a NuGet package
Expand All @@ -128,44 +126,42 @@ let nuGet out suffix =
ToolType = ToolType.CreateLocalTool()
OutputPath = out
Version = release.NugetVersion + (suffix |> Option.defaultValue "")
ReleaseNotes = releaseNotes})
ReleaseNotes = releaseNotes
})

Target.create "NuGet" (fun _ ->
nuGet "bin" None
)
Target.create "NuGet" (fun _ -> nuGet "bin" None)

Target.create "CINuGet" (fun _ ->
let suffix = "-alpha" + (System.DateTime.UtcNow.ToString("yyyyMMddHHmmss"))
nuGet "temp" (Some suffix)
)
nuGet "temp" (Some suffix))

let ensureOk (pr:ProcessResult) =
if not pr.OK then failwith (String.concat "," pr.Errors)
let ensureOk(pr: ProcessResult) =
if not pr.OK then
failwith(String.concat "," pr.Errors)

Target.create "PublishCINuGet" (fun _ ->
let token = Environment.environVarOrFail "GITHUB_TOKEN"

!! "temp/*.nupkg"
|> Seq.iter (fun file ->
|> Seq.iter(fun file ->
DotNet.exec id "nuget" (sprintf "push %s -s https://nuget.pkg.github.com/fsprojects/index.json -k %s" file token)
|> ensureOk //
)
)
|> ensureOk //
))

Target.create "PublishNuget" (fun _ ->
Paket.push (fun p ->
Paket.push(fun p ->
{ p with
ToolType = ToolType.CreateLocalTool()
WorkingDir = "bin" })
)
WorkingDir = "bin"
}))

// --------------------------------------------------------------------------------------
// Generate the documentation

Target.create "GenerateDocs" (fun _ ->
Shell.cleanDir ".fsdocs"
DotNet.exec id "build" "" |> ensureOk // we need assemblies compiled in debug mode for docs
DotNet.exec id "fsdocs" "build --clean --eval" |> ensureOk
)
DotNet.exec id "fsdocs" "build --clean --eval" |> ensureOk)
// --------------------------------------------------------------------------------------
// Release Scripts

Expand All @@ -175,39 +171,79 @@ Target.create "ReleaseDocs" (fun _ ->
Git.Repository.clone "" projectRepo "temp/gh-pages"
Git.Branches.checkoutBranch "temp/gh-pages" "gh-pages"
Shell.copyRecursive "output" "temp/gh-pages" true |> printfn "%A"
Git.CommandHelper.runSimpleGitCommand "temp/gh-pages" "add ." |> printfn "%s"
let cmd = sprintf """commit -a -m "Update generated documentation for version %s""" release.NugetVersion
Git.CommandHelper.runSimpleGitCommand "temp/gh-pages" cmd |> printfn "%s"
Git.Branches.push "temp/gh-pages"
)

Git.CommandHelper.runSimpleGitCommand "temp/gh-pages" "add ."
|> printfn "%s"

let cmd =
sprintf """commit -a -m "Update generated documentation for version %s""" release.NugetVersion

Git.CommandHelper.runSimpleGitCommand "temp/gh-pages" cmd
|> printfn "%s"

Git.Branches.push "temp/gh-pages")

Target.create "Release" (fun _ ->
Git.Staging.stageAll ""
Git.Commit.exec "" (sprintf "Bump version to %s" release.NugetVersion)
Git.Branches.push ""

Git.Branches.tag "" release.NugetVersion
Git.Branches.pushTag "" "origin" release.NugetVersion
)
Git.Branches.pushTag "" "origin" release.NugetVersion)

// --------------------------------------------------------------------------------------
// Fantomas code formatting and style checking

let sourceFiles =
!! "**/*.fs" ++ "**/*.fsx"
-- "**/fable_modules/**/**.fs"
-- "packages/**/*.*"
-- "paket-files/**/*.*"
-- ".fake/**/*.*"
-- "**/obj/**/*.*"
-- "**/AssemblyInfo.fs"

Target.create "Format" (fun _ ->
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)

Target.create "CheckFormat" (fun _ ->
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, run `dotnet fake build -t Format` to format them"
else
Trace.logf "Errors while formatting: %A" result.Errors
failwith "Unknown errors while formatting")

// --------------------------------------------------------------------------------------
// Run all targets by default. Invoke 'build <Target>' to override

Target.create "All" ignore

"Clean"
==> "AssemblyInfo"
==> "Build"
==> "RunTests"
==> "RunTestsFable"
==> "CINuGet"
==> "GenerateDocs"
==> "All"

"All"
==> "NuGet"
==> "PublishNuget"
==> "ReleaseDocs"
==> "Release"
==> "AssemblyInfo"
==> "CheckFormat"
==> "Build"
==> "RunTests"
==> "RunTestsFable"
==> "CINuGet"
==> "GenerateDocs"
==> "All"

"All" ==> "NuGet" ==> "PublishNuget" ==> "ReleaseDocs" ==> "Release"

Target.runOrDefault "All"
Loading