diff --git a/Content/Console/Directory.Build.targets b/Content/Console/Directory.Build.targets index 2800462b..452554fd 100644 --- a/Content/Console/Directory.Build.targets +++ b/Content/Console/Directory.Build.targets @@ -7,6 +7,7 @@ See https://learn.microsoft.com/en-us/visualstudio/msbuild/customize-by-director <_DotnetToolManifestFile>$(MSBuildThisFileDirectory).config\dotnet-tools.json <_DotnetToolRestoreOutputFile>$(MSBuildThisFileDirectory)build\obj\dotnet-tool-restore-$(NETCoreSdkVersion) + <_DotnetFantomasOutputFile>$(BaseIntermediateOutputPath)dotnet-fantomas-msbuild @@ -15,4 +16,10 @@ See https://learn.microsoft.com/en-us/visualstudio/msbuild/customize-by-director + + + + + + diff --git a/Content/Console/build/build.fs b/Content/Console/build/build.fs index 84d960c5..80684e72 100644 --- a/Content/Console/build/build.fs +++ b/Content/Console/build/build.fs @@ -29,12 +29,20 @@ let environVarAsBoolOrDefault varName defaultValue = with _ -> defaultValue + +let isCI = lazy environVarAsBoolOrDefault "CI" false + //----------------------------------------------------------------------------- // Metadata and Configuration //----------------------------------------------------------------------------- let productName = "MyLib.1" + +let rootDirectory = + __SOURCE_DIRECTORY__ + ".." + let sln = __SOURCE_DIRECTORY__ ".." @@ -175,8 +183,7 @@ let failOnBadExitAndPrint (p: ProcessResult) = failwithf "failed with exitcode %d" p.ExitCode let rec retryIfInCI times fn = - match Environment.environVarOrNone "CI" with - | Some _ -> + if isCI.Value then if times > 1 then try fn () @@ -184,7 +191,8 @@ let rec retryIfInCI times fn = retryIfInCI (times - 1) fn else fn () - | _ -> fn () + else + fn () let allReleaseChecks () = @@ -544,21 +552,26 @@ let githubRelease _ = |> GitHub.publishDraft |> Async.RunSynchronously + let formatCode _ = - let result = dotnet.fantomas "." + let result = dotnet.fantomas $"{rootDirectory}" if not result.OK then printfn "Errors while formatting all files: %A" result.Messages -let checkFormatCode _ = - let result = dotnet.fantomas "--check ." +let checkFormatCode ctx = + if isCI.Value then + let result = dotnet.fantomas $"{rootDirectory} --check" - 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" + 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 else - Trace.logf "Errors while formatting: %A" result.Errors + // Only verify in CI, otherwise format all files + formatCode ctx let initTargets () = BuildServer.install [ GitHubActions.Installer ] diff --git a/Content/Library/Directory.Build.targets b/Content/Library/Directory.Build.targets index 2800462b..452554fd 100644 --- a/Content/Library/Directory.Build.targets +++ b/Content/Library/Directory.Build.targets @@ -7,6 +7,7 @@ See https://learn.microsoft.com/en-us/visualstudio/msbuild/customize-by-director <_DotnetToolManifestFile>$(MSBuildThisFileDirectory).config\dotnet-tools.json <_DotnetToolRestoreOutputFile>$(MSBuildThisFileDirectory)build\obj\dotnet-tool-restore-$(NETCoreSdkVersion) + <_DotnetFantomasOutputFile>$(BaseIntermediateOutputPath)dotnet-fantomas-msbuild @@ -15,4 +16,10 @@ See https://learn.microsoft.com/en-us/visualstudio/msbuild/customize-by-director + + + + + + diff --git a/Content/Library/build/FsDocs.fs b/Content/Library/build/FsDocs.fs index 07036730..d69b4524 100644 --- a/Content/Library/build/FsDocs.fs +++ b/Content/Library/build/FsDocs.fs @@ -14,71 +14,70 @@ module Fsdocs = /// /// Fsdocs build command parameters and options /// - type BuildCommandParams = - { - /// Input directory of content (default: docs) - Input: string option + type BuildCommandParams = { + /// Input directory of content (default: docs) + Input: string option - /// Project files to build API docs for outputs, defaults to all packable projects - Projects: seq option + /// Project files to build API docs for outputs, defaults to all packable projects + Projects: seq option - /// Output Directory (default output for build and tmp/watch for watch) - Output: string option + /// Output Directory (default output for build and tmp/watch for watch) + Output: string option - /// Disable generation of API docs - NoApiDocs: bool option + /// Disable generation of API docs + NoApiDocs: bool option - /// Evaluate F# fragments in scripts - Eval: bool option + /// Evaluate F# fragments in scripts + Eval: bool option - /// Save images referenced in docs - SaveImages: bool option + /// Save images referenced in docs + SaveImages: bool option - /// Add line numbers - LineNumbers: bool option + /// Add line numbers + LineNumbers: bool option - /// Additional substitution parameters for templates - Parameters: seq option + /// Additional substitution parameters for templates + Parameters: seq option - /// Disable project cracking. - IgnoreProjects: bool option + /// Disable project cracking. + IgnoreProjects: bool option - /// In API doc generation qualify the output by the collection name, e.g. 'reference/FSharp.Core/...' instead of 'reference/...' . - Qualify: bool option + /// In API doc generation qualify the output by the collection name, e.g. 'reference/FSharp.Core/...' instead of 'reference/...' . + Qualify: bool option - /// The tool will also generate documentation for non-public members - NoPublic: bool option + /// The tool will also generate documentation for non-public members + NoPublic: bool option - /// Do not copy default content styles, javascript or use default templates - NoDefaultContent: bool option + /// Do not copy default content styles, javascript or use default templates + NoDefaultContent: bool option - /// Clean the output directory - Clean: bool option + /// Clean the output directory + Clean: bool option - /// Display version information - Version: bool option + /// Display version information + Version: bool option - /// Provide properties to dotnet msbuild, e.g. --properties Configuration=Release Version=3.4 - Properties: string option + /// Provide properties to dotnet msbuild, e.g. --properties Configuration=Release Version=3.4 + Properties: string option - /// Additional arguments passed down as otherflags to the F# compiler when the API is being generated. - /// Note that these arguments are trimmed, this is to overcome a limitation in the command line argument - /// processing. A typical use-case would be to pass an addition assembly reference. - /// Example --fscoptions " -r:MyAssembly.dll" - FscOptions: string option + /// Additional arguments passed down as otherflags to the F# compiler when the API is being generated. + /// Note that these arguments are trimmed, this is to overcome a limitation in the command line argument + /// processing. A typical use-case would be to pass an addition assembly reference. + /// Example --fscoptions " -r:MyAssembly.dll" + FscOptions: string option - /// Fail if docs are missing or can't be generated - Strict: bool option + /// Fail if docs are missing or can't be generated + Strict: bool option - /// Source folder at time of component build (<FsDocsSourceFolder>) - SourceFolder: string option + /// Source folder at time of component build (<FsDocsSourceFolder>) + SourceFolder: string option - /// Source repository for github links (<FsDocsSourceRepository>) - SourceRepository: string option + /// Source repository for github links (<FsDocsSourceRepository>) + SourceRepository: string option - /// Assume comments in F# code are markdown (<UsesMarkdownComments>) - MdComments: bool option - } + /// Assume comments in F# code are markdown (<UsesMarkdownComments>) + MdComments: bool option + } with /// Parameter default values. static member Default = { @@ -107,23 +106,22 @@ module Fsdocs = /// /// Fsdocs watch command parameters and options /// - type WatchCommandParams = - { - /// Do not serve content when watching. - NoServer: bool option + type WatchCommandParams = { + /// Do not serve content when watching. + NoServer: bool option - /// Do not launch a browser window. - NoLaunch: bool option + /// Do not launch a browser window. + NoLaunch: bool option - /// URL extension to launch http://localhost:/%s. - Open: string option + /// URL extension to launch http://localhost:/%s. + Open: string option - /// Port to serve content for http://localhost serving. - Port: int option + /// Port to serve content for http://localhost serving. + Port: int option - /// Build Commands - BuildCommandParams: BuildCommandParams option - } + /// Build Commands + BuildCommandParams: BuildCommandParams option + } with /// Parameter default values. static member Default = { diff --git a/Content/Library/build/build.fs b/Content/Library/build/build.fs index 5c0c5840..080bdbfc 100644 --- a/Content/Library/build/build.fs +++ b/Content/Library/build/build.fs @@ -170,7 +170,7 @@ let failOnBadExitAndPrint (p: ProcessResult) = let isCI = lazy environVarAsBoolOrDefault "CI" false -// CI Servers can have bizzare failures that have nothing to do with your code +// CI Servers can have bizarre failures that have nothing to do with your code let rec retryIfInCI times fn = match isCI.Value with | true -> @@ -228,13 +228,13 @@ module FSharpAnalyzers = module DocsTool = let quoted s = $"\"%s{s}\"" - let fsDocsDotnetOptions (o: DotNet.Options) = - { o with + let fsDocsDotnetOptions (o: DotNet.Options) = { + o with WorkingDirectory = rootDirectory - } + } - let fsDocsBuildParams configuration (p: Fsdocs.BuildCommandParams) = - { p with + let fsDocsBuildParams configuration (p: Fsdocs.BuildCommandParams) = { + p with Clean = Some true Input = Some(quoted docsSrcDir) Output = Some(quoted docsDir) @@ -252,7 +252,7 @@ module DocsTool = "fsdocs-release-notes-link", quoted (CHANGELOGlink.ToString()) ] Strict = Some true - } + } let cleanDocsCache () = Fsdocs.cleanCache rootDirectory @@ -267,18 +267,18 @@ module DocsTool = Option.defaultValue Fsdocs.BuildCommandParams.Default bp |> fsDocsBuildParams configuration - { bp with - Output = Some watchDocsDir - Strict = None + { + bp with + Output = Some watchDocsDir + Strict = None } Fsdocs.watch fsDocsDotnetOptions - (fun p -> - { p with + (fun p -> { + p with BuildCommandParams = Some(buildParams p.BuildCommandParams) - } - ) + }) let allReleaseChecks () = failOnWrongBranch () @@ -337,13 +337,12 @@ let dotnetRestore _ = |> String.concat " " DotNet.restore - (fun c -> - { c with + (fun c -> { + c with Common = c.Common |> DotNet.Options.withCustomParams (Some(args)) - } - ) + }) dir ) |> Seq.iter (retryIfInCI 10) @@ -368,15 +367,14 @@ let dotnetBuild ctx = ] DotNet.build - (fun c -> - { c with + (fun c -> { + c with Configuration = configuration (ctx.Context.AllExecutingTargets) Common = c.Common |> DotNet.Options.withAdditionalArgs args - } - ) + }) sln let fsharpAnalyzers _ = @@ -407,14 +405,20 @@ let dotnetTest ctx = |> Seq.map IO.Path.GetFileNameWithoutExtension |> String.concat "|" - let isGenerateCoverageReport = ctx.Context.TryFindTarget("GenerateCoverageReport").IsSome + let isGenerateCoverageReport = + ctx.Context.TryFindTarget("GenerateCoverageReport").IsSome let args = [ "--no-build" - if enableCodeCoverage || isGenerateCoverageReport then + if + enableCodeCoverage + || isGenerateCoverageReport + then sprintf "/p:AltCover=true" + if not isGenerateCoverageReport then sprintf "/p:AltCoverThreshold=%d" coverageThresholdPercent + sprintf "/p:AltCoverAssemblyExcludeFilter=%s" excludeCoverage "/p:AltCoverLocalSource=true" ] @@ -422,13 +426,13 @@ let dotnetTest ctx = DotNet.test (fun c -> - { c with - Configuration = configuration (ctx.Context.AllExecutingTargets) - Common = - c.Common - |> DotNet.Options.withAdditionalArgs args - } - ) + { + c with + Configuration = configuration (ctx.Context.AllExecutingTargets) + Common = + c.Common + |> DotNet.Options.withAdditionalArgs args + }) sln let generateCoverageReport _ = @@ -459,7 +463,9 @@ let generateCoverageReport _ = let showCoverageReport _ = failOnCIBuild () - coverageReportDir "index.html" + + coverageReportDir + "index.html" |> Command.ShellCommand |> CreateProcess.fromCommand |> Proc.start @@ -554,8 +560,7 @@ let generateAssemblyInfo _ = let dotnetPack ctx = // Get release notes with properly-linked version number - let releaseNotes = - Changelog.mkReleaseNotes changelog latestEntry gitHubRepoUrl + let releaseNotes = Changelog.mkReleaseNotes changelog latestEntry gitHubRepoUrl let args = [ $"/p:PackageVersion={latestEntry.NuGetVersion}" @@ -563,15 +568,14 @@ let dotnetPack ctx = ] DotNet.pack - (fun c -> - { c with + (fun c -> { + c with Configuration = configuration (ctx.Context.AllExecutingTargets) OutputPath = Some distDir Common = c.Common |> DotNet.Options.withAdditionalArgs args - } - ) + }) sln let sourceLinkTest _ = @@ -581,8 +585,8 @@ let sourceLinkTest _ = let publishToNuget _ = allPublishChecks () - Paket.push (fun c -> - { c with + Paket.push (fun c -> { + c with ToolType = ToolType.CreateLocalTool() PublishUrl = publishUrl WorkingDir = "dist" @@ -590,8 +594,7 @@ let publishToNuget _ = match nugetToken with | Some s -> s | _ -> c.ApiKey // assume paket-config was set properly - } - ) + }) let gitRelease _ = allReleaseChecks () @@ -601,14 +604,18 @@ let gitRelease _ = Git.Staging.stageFile "" "CHANGELOG.md" |> ignore - !!(rootDirectory "src/**/AssemblyInfo.fs") - ++ (rootDirectory "tests/**/AssemblyInfo.fs") + !!(rootDirectory + "src/**/AssemblyInfo.fs") + ++ (rootDirectory + "tests/**/AssemblyInfo.fs") |> Seq.iter ( Git.Staging.stageFile "" >> ignore ) - let msg = sprintf "Bump version to %s\n\n%s" latestEntry.NuGetVersion releaseNotesGitCommitFormat + let msg = + sprintf "Bump version to %s\n\n%s" latestEntry.NuGetVersion releaseNotesGitCommitFormat + Git.Commit.exec "" msg Target.deactivateBuildFailure "RevertChangelog" @@ -633,8 +640,7 @@ let githubRelease _ = let files = !!distGlob // Get release notes with properly-linked version number - let releaseNotes = - Changelog.mkReleaseNotes changelog latestEntry gitHubRepoUrl + let releaseNotes = Changelog.mkReleaseNotes changelog latestEntry gitHubRepoUrl GitHub.createClientWithToken token |> GitHub.draftNewRelease @@ -650,45 +656,24 @@ let githubRelease _ = |> Async.RunSynchronously let formatCode _ = - let result = - [ - srcCodeGlob - testsCodeGlob - ] - |> Seq.collect id - // Ignore AssemblyInfo - |> Seq.filter (fun f -> - f.EndsWith("AssemblyInfo.fs") - |> not - ) - |> String.concat " " - |> dotnet.fantomas + let result = dotnet.fantomas $"{rootDirectory}" if not result.OK then printfn "Errors while formatting all files: %A" result.Messages -let checkFormatCode _ = - let result = - [ - srcCodeGlob - testsCodeGlob - ] - |> Seq.collect id - // Ignore AssemblyInfo - |> Seq.filter (fun f -> - f.EndsWith("AssemblyInfo.fs") - |> not - ) - |> String.concat " " - |> sprintf "%s --check" - |> dotnet.fantomas +let checkFormatCode ctx = + if isCI.Value then + let result = dotnet.fantomas $"{rootDirectory} --check" - 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" + 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 else - Trace.logf "Errors while formatting: %A" result.Errors + // Only verify in CI, otherwise format all files + formatCode ctx let cleanDocsCache _ = DocsTool.cleanDocsCache () diff --git a/Directory.Build.targets b/Directory.Build.targets index 2800462b..4e382e02 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -7,6 +7,7 @@ See https://learn.microsoft.com/en-us/visualstudio/msbuild/customize-by-director <_DotnetToolManifestFile>$(MSBuildThisFileDirectory).config\dotnet-tools.json <_DotnetToolRestoreOutputFile>$(MSBuildThisFileDirectory)build\obj\dotnet-tool-restore-$(NETCoreSdkVersion) + <_DotnetFantomasOutputFile>$(BaseIntermediateOutputPath)dotnet-fantomas-msbuild @@ -15,4 +16,11 @@ See https://learn.microsoft.com/en-us/visualstudio/msbuild/customize-by-director + + + + + + + diff --git a/build/build.fs b/build/build.fs index f0dedc71..144f24e0 100644 --- a/build/build.fs +++ b/build/build.fs @@ -465,39 +465,24 @@ let githubRelease _ = |> Async.RunSynchronously let formatCode _ = - let result = - [ testsCodeGlob ] - |> Seq.collect id - // Ignore AssemblyInfo - |> Seq.filter (fun f -> - f.EndsWith("AssemblyInfo.fs") - |> not - ) - |> String.concat " " - |> dotnet.fantomas + let result = dotnet.fantomas $"{rootDirectory}" if not result.OK then printfn "Errors while formatting all files: %A" result.Messages -let checkFormatCode _ = - let result = - [ testsCodeGlob ] - |> Seq.collect id - // Ignore AssemblyInfo - |> Seq.filter (fun f -> - f.EndsWith("AssemblyInfo.fs") - |> not - ) - |> String.concat " " - |> sprintf "%s --check" - |> dotnet.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" +let checkFormatCode ctx = + if isCI.Value then + let result = dotnet.fantomas $"{rootDirectory} --check" + + 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 else - Trace.logf "Errors while formatting: %A" result.Errors + // Only verify in CI, otherwise format all files + formatCode ctx let cleanDocsCache _ = DocsTool.cleanDocsCache ()