Skip to content

Commit

Permalink
Make code style consistent with the latest Fantomas settings
Browse files Browse the repository at this point in the history
  • Loading branch information
xperiandri committed Aug 6, 2024
1 parent 995f2a9 commit c8fe9aa
Show file tree
Hide file tree
Showing 289 changed files with 17,201 additions and 12,868 deletions.
24 changes: 24 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,28 @@ indent_size = 4
# Either crlf | lf, default is system-dependent (when not specified at all)
# end_of_line=crlf

# false: let a = [1;2;3]
# true: let a = [ 1;2;3 ]
# default true
fsharp_space_around_delimiter=true

# breaks a single-line record declaration
# i.e. if this gets too wide: { X = 10; Y = 12 }
# default 40
fsharp_max_record_width=60

# breaks a record into one item per line if items exceed this number
# i.e. if set to 1, this will be on three lines: { X = 10; Y = 12 }
# requires fsharp_record_multiline_formatter=number_of_items to take effect
# default 1
fsharp_max_record_number_of_items=1

# whether to use line-length (by counting chars) or items (by counting fields)
# for the record settings above
# either number_of_items or character_width
# default character_width
fsharp_record_multiline_formatter=character_width

# set maximal number of consecutive blank lines to keep from original source
# it doesn't change number of new blank lines generated by Fantomas
fsharp_keep_max_number_of_blank_lines=2
158 changes: 94 additions & 64 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,11 @@ let releaseSecret replacement name =
match getVarOrDefaultFromVault name "default_unset" with
| "default_unset" -> failwithf "variable '%s' is not set" name
| s -> s

if BuildServer.buildServer <> BuildServer.TeamFoundation then
// on TFS/VSTS the build will take care of this.
TraceSecrets.register replacement env

env

secrets <- secret :: secrets
Expand All @@ -134,10 +136,12 @@ let chocoSource =
getVarOrDefaultFromVault "CHOCO_SOURCE" "https://push.chocolatey.org/"

let artifactsDir = getVarOrDefaultFromVault "ARTIFACTS_DIRECTORY" ""

let docsDomain =
match BuildServer.isLocalBuild with
| true -> "http://127.0.0.1:8083/"
| false -> getVarOrDefaultFromVault "DOCS_DOMAIN" "fake.build"

let fromArtifacts = not <| String.isNullOrEmpty artifactsDir
let apiKey = releaseSecret "<nugetkey>" "NUGET_KEY"
let chocoKey = releaseSecret "<chocokey>" "CHOCOLATEY_API_KEY"
Expand Down Expand Up @@ -213,7 +217,9 @@ let version =

let d = System.DateTime.Now
let newLocalVersionNumber = currentVer + 1I
[ PreReleaseSegment.AlphaNumeric("local." + newLocalVersionNumber.ToString()) ], d.ToString("yyyy-MM-dd-HH-mm")

[ PreReleaseSegment.AlphaNumeric("local." + newLocalVersionNumber.ToString()) ],
d.ToString("yyyy-MM-dd-HH-mm")

let semVer = SemVer.parse release.NugetVersion

Expand All @@ -224,11 +230,7 @@ let version =

match String.IsNullOrWhiteSpace toAdd with
| true -> None
| false ->
Some
{ Name = ""
Values = source
Origin = toAdd }
| false -> Some { Name = ""; Values = source; Origin = toAdd }
| Some p ->
let toAdd = String.Join(".", source |> Seq.map segToString)
let toAdd = if String.IsNullOrEmpty toAdd then toAdd else "." + toAdd
Expand Down Expand Up @@ -454,9 +456,14 @@ let rec nugetPush tries nugetPackage =
try
if not <| String.IsNullOrEmpty apiKey.Value then
let quoteString str = sprintf "\"%s\"" str

let args = sprintf "push %s %s -Source %s" (quoteString nugetPackage) (quoteString apiKey.Value) (quoteString nugetSource)


let args =
sprintf
"push %s %s -Source %s"
(quoteString nugetPackage)
(quoteString apiKey.Value)
(quoteString nugetSource)

let errors = System.Collections.Generic.List<string>()
let results = System.Collections.Generic.List<string>()

Expand All @@ -474,22 +481,24 @@ let rec nugetPush tries nugetPackage =
|> CreateProcess.redirectOutput
|> CreateProcess.withOutputEventsNotNull errorF messageF
|> Proc.run

if processResult.ExitCode <> 0 then
if
not ignore_conflict
|| not (errors |> Seq.exists (fun err -> err.Contains "409"))
then
let msgs =
errors |> Seq.map (fun c -> "(Err) " + c)
|> Seq.append results |> Seq.map (fun c -> c)
errors
|> Seq.map (fun c -> "(Err) " + c)
|> Seq.append results
|> Seq.map (fun c -> c)

let msg = String.Join("\n", msgs)

failwithf "failed to push package %s (code %d): \n%s" nugetPackage processResult.ExitCode msg
else
Trace.traceFAKE "ignore conflict error because IGNORE_CONFLICT=true!"

else
Trace.traceFAKE "could not push '%s', because api key was not set" nugetPackage
with exn when tries > 1 ->
Expand Down Expand Up @@ -525,9 +534,7 @@ Target.create "Clean" (fun _ ->
Shell.rm ("paket-files" </> "paket.restore.cached")
callPaket "." "restore"

Shell.cleanDirs
[ nugetDncDir
collectedArtifactsDir ]
Shell.cleanDirs [ nugetDncDir; collectedArtifactsDir ]

// Clean Data for tests
cleanForTests ())
Expand All @@ -537,33 +544,33 @@ Target.create "CheckReleaseSecrets" (fun _ ->
secret.Force() |> ignore)

Target.create "CheckFormatting" (fun _ ->
let dotnetOptions = (fun (buildOptions:DotNet.Options) -> { buildOptions with RedirectOutput = false})
let result =
DotNet.exec id "fantomas" "src/app/ src/template/ src/test/ --check"
let dotnetOptions =
(fun (buildOptions: DotNet.Options) -> { buildOptions with RedirectOutput = false })

let result = DotNet.exec id "fantomas" "src/app/ src/template/ src/test/ --check"

if result.ExitCode = 0 then
Trace.log "No files need formatting"
elif result.ExitCode = 99 then
failwith
"Some files need formatting, please run \"dotnet fantomas src/app/ src/template/ src/test/\" to resolve this."
else
failwith "Errors while formatting"
)
failwith "Errors while formatting")

// ----------------------------------------------------------------------------------------------------
// Documentation targets.

Target.create "GenerateDocs" (fun _ ->
let source = "./docs"

Shell.cleanDir ".fsdocs"
Directory.ensure "output"

let projInfo =
seq {
("root", docsDomain)
("fsdocs-logo-src", docsDomain @@ "content/img/logo.svg")
("fsdocs-fake-version", simpleVersion)
("root", docsDomain)
("fsdocs-logo-src", docsDomain @@ "content/img/logo.svg")
("fsdocs-fake-version", simpleVersion)
}

File.writeString false "./output/.nojekyll" ""
Expand All @@ -572,26 +579,31 @@ Target.create "GenerateDocs" (fun _ ->

try
Npm.install (fun o -> { o with WorkingDirectory = "./docs" })

Npm.run "build" (fun o -> { o with WorkingDirectory = "./docs" })

Shell.copy "./output" [source </> "robots.txt"]
Shell.copy "./output" [ source </> "robots.txt" ]

// renaming node_modules directory so that fsdocs skip it when generating site.
Directory.Move("./docs/node_modules", "./docs/.node_modules")

let command = sprintf "build --clean --input ./docs --saveimages --properties Configuration=release --parameters fsdocs-logo-src %s fsdocs-fake-version %s" (docsDomain @@ "content/img/logo.svg") simpleVersion
let command =
sprintf
"build --clean --input ./docs --saveimages --properties Configuration=release --parameters fsdocs-logo-src %s fsdocs-fake-version %s"
(docsDomain @@ "content/img/logo.svg")
simpleVersion

DotNet.exec id "fsdocs" command |> ignore

// Fsdocs.build (fun p -> { p with
// Input = Some(source)
// SaveImages = Some(true)
// Clean = Some(true)
// Parameters = Some projInfo
// Properties = Some "Configuration=debug"
// //Strict = Some(true)
// })
// Fsdocs.build (fun p -> { p with
// Input = Some(source)
// SaveImages = Some(true)
// Clean = Some(true)
// Parameters = Some projInfo
// Properties = Some "Configuration=debug"
// //Strict = Some(true)
// })

finally
// clean up
Shell.rm (source </> "guide/RELEASE_NOTES.md")
Expand All @@ -601,19 +613,31 @@ Target.create "GenerateDocs" (fun _ ->


// validate site generation and ensure all components are generated successfully.
if DirectoryInfo.ofPath("./output/guide").GetFiles().Length = 0 then failwith "site generation failed due to missing guide directory"
if DirectoryInfo.ofPath("./output/reference").GetFiles().Length = 0 then failwith "site generation failed due to missing reference directory"
if DirectoryInfo.ofPath("./output/articles").GetFiles().Length = 0 then failwith "site generation failed due to missing articles directory"
if not (File.exists("./output/data.json")) then failwith "site generation failed due to missing data.json file"
if not (File.exists("./output/guide/RELEASE_NOTES.html")) then failwith "site generation failed due to missing RELEASE_NOTES.html file"
if not (File.exists("./output/guide.html")) then failwith "site generation failed due to missing guide.html file"
if not (File.exists("./output/index.html")) then failwith "site generation failed due to missing index.html file"
if DirectoryInfo.ofPath("./output/guide").GetFiles().Length = 0 then
failwith "site generation failed due to missing guide directory"

if DirectoryInfo.ofPath("./output/reference").GetFiles().Length = 0 then
failwith "site generation failed due to missing reference directory"

if DirectoryInfo.ofPath("./output/articles").GetFiles().Length = 0 then
failwith "site generation failed due to missing articles directory"

if not (File.exists ("./output/data.json")) then
failwith "site generation failed due to missing data.json file"

if not (File.exists ("./output/guide/RELEASE_NOTES.html")) then
failwith "site generation failed due to missing RELEASE_NOTES.html file"

if not (File.exists ("./output/guide.html")) then
failwith "site generation failed due to missing guide.html file"

if not (File.exists ("./output/index.html")) then
failwith "site generation failed due to missing index.html file"

// prepare artifact
Directory.ensure "temp"

!!("output" </> "**/*")
|> Zip.zip docsDir "temp/docs.zip"

!!("output" </> "**/*") |> Zip.zip docsDir "temp/docs.zip"
publish "temp/docs.zip")

Target.create "HostDocs" (fun _ ->
Expand All @@ -626,23 +650,28 @@ Target.create "HostDocs" (fun _ ->

Shell.copy (source @@ "guide") [ "RELEASE_NOTES.md" ]

Shell.copy "./output" [source </> "robots.txt"]
Shell.copy "./output" [ source </> "robots.txt" ]

// renaming node_modules directory so that fsdocs skip it when generating site.
Directory.Move("./docs/node_modules", "./docs/.node_modules")

let command = sprintf "watch --input ./docs --saveimages --properties Configuration=release --parameters fsdocs-logo-src %s fsdocs-fake-version %s" (docsDomain @@ "content/img/logo.svg") simpleVersion
let command =
sprintf
"watch --input ./docs --saveimages --properties Configuration=release --parameters fsdocs-logo-src %s fsdocs-fake-version %s"
(docsDomain @@ "content/img/logo.svg")
simpleVersion

DotNet.exec id "fsdocs" command |> ignore

// Fsdocs.watch id
// Fsdocs.watch id

finally
// clean up
Shell.rm (source </> "guide/RELEASE_NOTES.md")

// renaming node_modules directory back after fsdocs generated site.
Directory.Move("./docs/.node_modules", "./docs/node_modules")

)

// ----------------------------------------------------------------------------------------------------
Expand All @@ -663,7 +692,7 @@ Target.create "TemplateIntegrationTests" (fun _ ->
targetDir
"bin/Release/net6.0/Fake.DotNet.Cli.IntegrationTests.dll"
"Fake_DotNet_Cli_IntegrationTests.TestResults.xml"

Shell.rm_rf (root </> "test"))

Target.create "DotNetCoreUnitTests" (fun _ ->
Expand Down Expand Up @@ -727,14 +756,16 @@ Target.create "BootstrapFake" (fun _ ->


let processResult =
CreateProcess.fromRawCommandLine fileName (sprintf "run --fsiargs \"--define:BOOTSTRAP\" %s --target %s" script target)
CreateProcess.fromRawCommandLine
fileName
(sprintf "run --fsiargs \"--define:BOOTSTRAP\" %s --target %s" script target)
|> CreateProcess.withWorkingDirectory "."
|> CreateProcess.setEnvironmentVariable "FAKE_DETAILED_ERRORS" "true"
|> CreateProcess.withTimeout timeout
|> Proc.run

processResult.ExitCode

let result = executeTarget "BootstrapFake_PrintColors"

if result <> 0 then
Expand Down Expand Up @@ -971,11 +1002,7 @@ Target.create "DotNetPushChocolateyPackage" (fun _ ->
{ p with ToolPath = altToolPath }

path
|> Choco.push (fun p ->
{ p with
Source = chocoSource
ApiKey = chocoKey.Value }
|> changeToolPath))
|> Choco.push (fun p -> { p with Source = chocoSource; ApiKey = chocoKey.Value } |> changeToolPath))

Target.create "DotNetPushToNuGet" (fun _ ->
!!(appDir </> "*/*.fsproj") -- (appDir </> "Fake.netcore/*.fsproj")
Expand Down Expand Up @@ -1035,7 +1062,7 @@ Target.create "GitHubRelease" (fun _ ->
|> GitHub.uploadFiles files
|> GitHub.publishDraft
|> Async.RunSynchronously

let bumpVersionMessage = (sprintf "Bump version to %s" simpleVersion)
let branch = "bump-version-to-" + simpleVersion
Git.Staging.stageAll ".config"
Expand All @@ -1045,9 +1072,12 @@ Target.create "GitHubRelease" (fun _ ->

// when we release the GitHub module, this will be replaced with GitHub.createPullRequest API
let pullRequest = new NewPullRequest(bumpVersionMessage, branch, "master")

let pullRequestTask (client: GitHubClient) =
client.PullRequest.Create(githubReleaseUser, gitName, pullRequest) |> Async.AwaitTask |> Async.RunSynchronously

client.PullRequest.Create(githubReleaseUser, gitName, pullRequest)
|> Async.AwaitTask
|> Async.RunSynchronously

GitHub.createClientWithToken token
|> Async.RunSynchronously
|> pullRequestTask
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ nuget Fake.Core.Context prerelease"
#load ".fake/context.exists.fsx/intellisense.fsx"

printfn "loading context"
let context = Fake.Core.Context.forceFakeContext()
let context = Fake.Core.Context.forceFakeContext ()
printfn "got: %A" context
Original file line number Diff line number Diff line change
@@ -1 +1 @@
printfn "Hello FAKE"
printfn "Hello FAKE"
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
module OtherFile

open Fake.Core

[<System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)>]
let createTargets () =

Target.create "OtherFileTarget" (fun _ ->
printfn "Doing Something."
)
Target.create "OtherFileTarget" (fun _ -> printfn "Doing Something.")

// required because otherwise JIT is still inlining this :(
printfn "test"
printfn "test"
Loading

0 comments on commit c8fe9aa

Please sign in to comment.