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

Upgrade Fantomas and add CheckFormat to build pipeline #195

Merged
merged 6 commits into from
Jul 10, 2022
Merged
Show file tree
Hide file tree
Changes from all 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: 3 additions & 3 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
"dotnet-serve"
]
},
"fantomas-tool": {
"version": "5.0.0-alpha-002",
"fantomas": {
"version": "5.0.0-alpha-010",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah shoot, this is already merged. @yisusalanpng I released alpha 11 on Friday. Would you mind making another PR?

"commands": [
"fantomas"
]
}
}
}
}
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.fs]
[{*.fs,*.fsx}]
indent_size = 4
indent_style = space
max_line_length=150
Expand All @@ -21,4 +21,4 @@ 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_ragnarok=true
fsharp_experimental_stroustrup_style=true
alanlomeli marked this conversation as resolved.
Show resolved Hide resolved
136 changes: 83 additions & 53 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,14 @@ let release = ReleaseNotes.load "docs/RELEASE_NOTES.md"
// Generate assembly info files with the right version & up-to-date information
Target.create "AssemblyInfo" (fun _ ->
let fileName = "src/Common/AssemblyInfo.fs"
AssemblyInfoFile.createFSharp fileName
[ AssemblyInfo.Title gitName

AssemblyInfoFile.createFSharp fileName [
AssemblyInfo.Title gitName
AssemblyInfo.Product gitName
AssemblyInfo.Description description
AssemblyInfo.Version release.AssemblyVersion
AssemblyInfo.FileVersion release.AssemblyVersion ]
)
AssemblyInfo.FileVersion release.AssemblyVersion
])

// --------------------------------------------------------------------------------------
// Clean build results
Expand All @@ -68,69 +69,66 @@ Target.create "Clean" (fun _ ->
!! "**/**/bin/" |> Shell.cleanDirs
//!! "**/**/obj/" |> Shell.cleanDirs

Shell.cleanDirs ["bin"; "temp"]
try File.Delete("swaggerlog") with | _ -> ()
)
Shell.cleanDirs [ "bin"; "temp" ]

Target.create "CleanDocs" (fun _ ->
Shell.cleanDirs ["docs/output"]
)
try
File.Delete("swaggerlog")
with _ ->
())

Target.create "CleanDocs" (fun _ -> Shell.cleanDirs [ "docs/output" ])

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

Target.create "Build" (fun _ ->
DotNet.exec id "build" "SwaggerProvider.sln -c Release" |> ignore
)
Target.create "Build" (fun _ -> DotNet.exec id "build" "SwaggerProvider.sln -c Release" |> ignore)

let webApiInputStream = StreamRef.Empty

Target.create "StartServer" (fun _ ->
Target.activateFinal "StopServer"

CreateProcess.fromRawCommandLine "dotnet" "tests/Swashbuckle.WebApi.Server/bin/Release/net6.0/Swashbuckle.WebApi.Server.dll"
|> CreateProcess.withStandardInput (CreatePipe webApiInputStream)
|> CreateProcess.withStandardInput(CreatePipe webApiInputStream)
|> Proc.start
|> ignore

// We need delay to guarantee that server is bootstrapped
System.Threading.Thread.Sleep(2000)
)
System.Threading.Thread.Sleep(2000))

Target.createFinal "StopServer" (fun _ ->
// Write something to input stream to stop server
try
webApiInputStream.Value.Write([|0uy|],0,1)
with
| e -> printfn "%s" e.Message
//Process.killAllByName "dotnet"
webApiInputStream.Value.Write([| 0uy |], 0, 1)
with e ->
printfn "%s" e.Message
//Process.killAllByName "dotnet"
)

Target.create "BuildTests" (fun _ ->
DotNet.exec id "build" "SwaggerProvider.TestsAndDocs.sln -c Release" |> ignore
)
DotNet.exec id "build" "SwaggerProvider.TestsAndDocs.sln -c Release"
|> ignore)

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

let runTests assembly =
[Path.Combine(__SOURCE_DIRECTORY__, assembly)]
|> Testing.Expecto.run (fun p ->
[
Path.Combine(__SOURCE_DIRECTORY__, assembly)
]
|> Testing.Expecto.run(fun p ->
{ p with
WorkingDirectory = __SOURCE_DIRECTORY__
FailOnFocusedTests = true
PrintVersion = true
Parallel = false
Summary = true
Summary = true
Debug = false
})

Target.create "RunUnitTests" (fun _ ->
runTests "tests/SwaggerProvider.Tests/bin/Release/net6.0/SwaggerProvider.Tests.dll"
)
Target.create "RunUnitTests" (fun _ -> runTests "tests/SwaggerProvider.Tests/bin/Release/net6.0/SwaggerProvider.Tests.dll")

Target.create "RunIntegrationTests" (fun _ ->
runTests "tests/SwaggerProvider.ProviderTests/bin/Release/net6.0/SwaggerProvider.ProviderTests.dll"
)
Target.create "RunIntegrationTests" (fun _ -> runTests "tests/SwaggerProvider.ProviderTests/bin/Release/net6.0/SwaggerProvider.ProviderTests.dll")

Target.create "RunTests" ignore

Expand All @@ -143,15 +141,15 @@ Target.create "NuGet" (fun _ ->
ToolType = ToolType.CreateLocalTool()
OutputPath = "bin"
Version = release.NugetVersion
ReleaseNotes = String.toLines release.Notes})
)
ReleaseNotes = String.toLines release.Notes
}))

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

// --------------------------------------------------------------------------------------
// Generate the documentation
Expand Down Expand Up @@ -180,8 +178,7 @@ Target.create "PublishNuget" (fun _ ->

Target.create "BrowseDocs" (fun _ ->
CreateProcess.fromRawCommandLine "dotnet" "serve -o -d ./docs"
|> (Proc.run >> ignore)
)
|> (Proc.run >> ignore))

// Target.create "GenerateDocs" (fun _ ->
// let exit = Fake.executeFAKEWithOutput "docs" "docs.fsx" "" ["target", "GenerateDocs"]
Expand Down Expand Up @@ -228,11 +225,43 @@ Target.create "Release" (fun _ ->
Git.Branches.push ""

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

Target.create "BuildPackage" ignore

let sourceFiles =
!! "**/*.fs" ++ "**/*.fsx"
-- "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

Expand All @@ -243,19 +272,20 @@ let skipTests = Environment.environVarAsBoolOrDefault "skipTests" false


"Clean"
==> "AssemblyInfo"
==> "Build"
==> "RunUnitTests"
==> "StartServer"
==> "BuildTests"
=?> ("RunIntegrationTests", not skipTests)
==> "StopServer"
==> "RunTests"
//=?> ("GenerateDocs", BuildServer.isLocalBuild)
==> "NuGet"
==> "All"
==> "BuildPackage"
==> "PublishNuget"
==> "Release"
==> "AssemblyInfo"
==> "CheckFormat"
==> "Build"
==> "RunUnitTests"
==> "StartServer"
==> "BuildTests"
=?> ("RunIntegrationTests", not skipTests)
==> "StopServer"
==> "RunTests"
//=?> ("GenerateDocs", BuildServer.isLocalBuild)
==> "NuGet"
==> "All"
==> "BuildPackage"
==> "PublishNuget"
==> "Release"

Target.runOrDefault "BuildPackage"
Loading