From dcaa0319326b35030af98a9798246b474cde6e4a Mon Sep 17 00:00:00 2001 From: Jimmy Byrd Date: Fri, 17 May 2019 20:21:58 -0400 Subject: [PATCH 1/6] reorganize Content/build.fsx --- Content/Library/build.fsx | 168 +++++++++++++++++++++++--------------- 1 file changed, 100 insertions(+), 68 deletions(-) diff --git a/Content/Library/build.fsx b/Content/Library/build.fsx index 1e415a05..25088149 100644 --- a/Content/Library/build.fsx +++ b/Content/Library/build.fsx @@ -20,8 +20,10 @@ BuildServer.install [ Travis.Installer ] +//----------------------------------------------------------------------------- +// Metadata and Configuration +//----------------------------------------------------------------------------- -let release = Fake.Core.ReleaseNotes.load "RELEASE_NOTES.md" let productName = "MyLib.1" let sln = "MyLib.1.sln" let srcGlob =__SOURCE_DIRECTORY__ @@ "src/**/*.??proj" @@ -40,11 +42,23 @@ let coverageReportDir = __SOURCE_DIRECTORY__ @@ "docs" @@ "coverage" let gitOwner = "MyGithubUsername" let gitRepoName = "MyLib.1" +let releaseBranch = "master" +let releaseNotes = Fake.Core.ReleaseNotes.load "RELEASE_NOTES.md" + +let publishUrl = "https://www.nuget.org" + +let paketToolPath = __SOURCE_DIRECTORY__ ".paket" (if Environment.isWindows then "paket.exe" else "paket") + +//----------------------------------------------------------------------------- +// Helpers +//----------------------------------------------------------------------------- let isRelease (targets : Target list) = targets |> Seq.map(fun t -> t.Name) |> Seq.exists ((=)"Release") +let invokeAsync f = async { f () } + let configuration (targets : Target list) = let defaultVal = if isRelease targets then "Release" else "Debug" match Environment.environVarOrDefault "CONFIGURATION" defaultVal with @@ -69,6 +83,10 @@ let rec retryIfInCI times fn = fn() | _ -> fn() +let isReleaseBranchCheck () = + if Git.Information.getBranchName "" <> releaseBranch then failwithf "Not on %s. If you want to release please switch to this branch." releaseBranch + + module dotnet = let watch cmdParam program args = DotNet.exec cmdParam (sprintf "watch %s" program) args @@ -86,9 +104,11 @@ module dotnet = let sourcelink optionConfig args = tool optionConfig "sourcelink" args +//----------------------------------------------------------------------------- +// Target Implementations +//----------------------------------------------------------------------------- - -Target.create "Clean" <| fun _ -> +let clean _ = ["bin"; "temp" ; distDir; coverageReportDir] |> Shell.cleanDirs @@ -106,15 +126,15 @@ Target.create "Clean" <| fun _ -> ] |> Seq.iter Shell.rm -Target.create "DotnetRestore" <| fun _ -> +let dotnetRestore _ = Paket.restore(fun p -> - {p with ToolPath = __SOURCE_DIRECTORY__ ".paket" (if Environment.isWindows then "paket.exe" else "paket")}) + {p with ToolPath = paketToolPath}) [sln ; toolsDir] |> Seq.map(fun dir -> fun () -> let args = [ - sprintf "/p:PackageVersion=%s" release.NugetVersion + sprintf "/p:PackageVersion=%s" releaseNotes.NugetVersion ] |> String.concat " " DotNet.restore(fun c -> { c with @@ -125,50 +145,45 @@ Target.create "DotnetRestore" <| fun _ -> }) dir) |> Seq.iter(retryIfInCI 10) -Target.create "DotnetBuild" <| fun ctx -> +let dotnetBuild ctx = let args = [ - sprintf "/p:PackageVersion=%s" release.NugetVersion + sprintf "/p:PackageVersion=%s" releaseNotes.NugetVersion "--no-restore" - ] |> String.concat " " + ] DotNet.build(fun c -> { c with Configuration = configuration (ctx.Context.AllExecutingTargets) Common = c.Common - |> DotNet.Options.withCustomParams - (Some(args)) - }) sln + |> DotNet.Options.withAdditionalArgs args + }) sln -let invokeAsync f = async { f () } - -let coverageThresholdPercent = 80 - -Target.create "DotnetTest" <| fun ctx -> +let dotnetTest ctx = + let coverageThresholdPercent = 80 let excludeCoverage = !! testsGlob |> Seq.map IO.Path.GetFileNameWithoutExtension |> String.concat "|" + let args = + [ + "--no-build" + "/p:AltCover=true" + sprintf "/p:AltCoverThreshold=%d" coverageThresholdPercent + sprintf "/p:AltCoverAssemblyExcludeFilter=%s" excludeCoverage + ] DotNet.test(fun c -> - let args = - [ - "--no-build" - "/p:AltCover=true" - sprintf "/p:AltCoverThreshold=%d" coverageThresholdPercent - sprintf "/p:AltCoverAssemblyExcludeFilter=%s" excludeCoverage - ] |> String.concat " " + { c with Configuration = configuration (ctx.Context.AllExecutingTargets) Common = c.Common - |> DotNet.Options.withCustomParams - (Some(args)) + |> DotNet.Options.withAdditionalArgs args }) sln - -Target.create "GenerateCoverageReport" <| fun _ -> +let generateCoverageReport _ = let coverageReports = !!"tests/**/coverage.*.xml" |> String.concat ";" @@ -191,8 +206,7 @@ Target.create "GenerateCoverageReport" <| fun _ -> |> String.concat " " dotnet.reportgenerator id args - -Target.create "WatchTests" <| fun _ -> +let watchTests _ = !! testsGlob |> Seq.map(fun proj -> fun () -> dotnet.watch @@ -208,26 +222,26 @@ Target.create "WatchTests" <| fun _ -> let cancelEvent = Console.CancelKeyPress |> Async.AwaitEvent |> Async.RunSynchronously cancelEvent.Cancel <- true -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) +let generateAssemblyInfo _ = + 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) -Target.create "AssemblyInfo" <| fun _ -> let releaseChannel = - match release.SemVer.PreRelease with + match releaseNotes.SemVer.PreRelease with | Some pr -> pr.Name | _ -> "release" let getAssemblyInfoAttributes projectName = [ AssemblyInfo.Title (projectName) AssemblyInfo.Product productName - AssemblyInfo.Version release.AssemblyVersion - AssemblyInfo.Metadata("ReleaseDate", release.Date.Value.ToString("o")) - AssemblyInfo.FileVersion release.AssemblyVersion - AssemblyInfo.InformationalVersion release.AssemblyVersion + AssemblyInfo.Version releaseNotes.AssemblyVersion + AssemblyInfo.Metadata("ReleaseDate", releaseNotes.Date.Value.ToString("o")) + AssemblyInfo.FileVersion releaseNotes.AssemblyVersion + AssemblyInfo.InformationalVersion releaseNotes.AssemblyVersion AssemblyInfo.Metadata("ReleaseChannel", releaseChannel) AssemblyInfo.Metadata("GitHash", Git.Information.getCurrentSHA1(null)) ] @@ -249,58 +263,51 @@ Target.create "AssemblyInfo" <| fun _ -> | Vbproj -> AssemblyInfoFile.createVisualBasic ((folderName @@ "My Project") @@ "AssemblyInfo.vb") attributes ) - -Target.create "DotnetPack" <| fun ctx -> +let dotnetPack ctx = let args = [ - sprintf "/p:PackageVersion=%s" release.NugetVersion - sprintf "/p:PackageReleaseNotes=\"%s\"" (release.Notes |> String.concat "\n") - ] |> String.concat " " + sprintf "/p:PackageVersion=%s" releaseNotes.NugetVersion + sprintf "/p:PackageReleaseNotes=\"%s\"" (releaseNotes.Notes |> String.concat "\n") + ] DotNet.pack (fun c -> { c with Configuration = configuration (ctx.Context.AllExecutingTargets) OutputPath = Some distDir Common = c.Common - |> DotNet.Options.withCustomParams (Some args) + |> DotNet.Options.withAdditionalArgs args }) sln - - -Target.create "SourcelinkTest" <| fun _ -> +let sourceLinkTest _ = !! distGlob |> Seq.iter (fun nupkg -> dotnet.sourcelink id (sprintf "test %s" nupkg) ) - -let isReleaseBranchCheck () = - let releaseBranch = "master" - if Git.Information.getBranchName "" <> releaseBranch then failwithf "Not on %s. If you want to release please switch to this branch." releaseBranch - -Target.create "Publish" <| fun _ -> +let publishToNuget _ = isReleaseBranchCheck () Paket.push(fun c -> { c with - PublishUrl = "https://www.nuget.org" + ToolPath = paketToolPath + PublishUrl = publishUrl WorkingDir = "dist" } ) -Target.create "GitRelease" <| fun _ -> +let gitRelease _ = isReleaseBranchCheck () - let releaseNotesGitCommitFormat = release.Notes |> Seq.map(sprintf "* %s\n") |> String.concat "" + let releaseNotesGitCommitFormat = releaseNotes.Notes |> Seq.map(sprintf "* %s\n") |> String.concat "" Git.Staging.stageAll "" - Git.Commit.exec "" (sprintf "Bump version to %s \n%s" release.NugetVersion releaseNotesGitCommitFormat) + Git.Commit.exec "" (sprintf "Bump version to %s \n%s" releaseNotes.NugetVersion releaseNotesGitCommitFormat) Git.Branches.push "" - Git.Branches.tag "" release.NugetVersion - Git.Branches.pushTag "" "origin" release.NugetVersion + Git.Branches.tag "" releaseNotes.NugetVersion + Git.Branches.pushTag "" "origin" releaseNotes.NugetVersion -Target.create "GitHubRelease" <| fun _ -> +let githubRelease _ = let token = match Environment.environVarOrDefault "GITHUB_TOKEN" "" with | s when not (String.IsNullOrWhiteSpace s) -> s @@ -309,27 +316,49 @@ Target.create "GitHubRelease" <| fun _ -> let files = !! distGlob GitHub.createClientWithToken token - |> GitHub.draftNewRelease gitOwner gitRepoName release.NugetVersion (release.SemVer.PreRelease <> None) release.Notes + |> GitHub.draftNewRelease gitOwner gitRepoName releaseNotes.NugetVersion (releaseNotes.SemVer.PreRelease <> None) releaseNotes.Notes |> GitHub.uploadFiles files |> GitHub.publishDraft |> Async.RunSynchronously -Target.create "FormatCode" <| fun _ -> +let formatCode _ = srcAndTest |> Seq.map (IO.Path.GetDirectoryName) |> Seq.iter (fun projDir -> dotnet.fantomas id (sprintf "--recurse %s" projDir) ) +//----------------------------------------------------------------------------- +// Target Declaration +//----------------------------------------------------------------------------- + +Target.create "Clean" clean +Target.create "DotnetRestore" dotnetRestore +Target.create "DotnetBuild" dotnetBuild +Target.create "DotnetTest" dotnetTest +Target.create "GenerateCoverageReport" generateCoverageReport +Target.create "WatchTests" watchTests +Target.create "AssemblyInfo" generateAssemblyInfo +Target.create "DotnetPack" dotnetPack +Target.create "SourcelinkTest" sourceLinkTest +Target.create "Publish" publishToNuget +Target.create "GitRelease" gitRelease +Target.create "GitHubRelease" githubRelease +Target.create "FormatCode" formatCode Target.create "Release" ignore + +//----------------------------------------------------------------------------- +// Target Dependencies +//----------------------------------------------------------------------------- + // Only call Clean if DotnetPack was in the call chain // Ensure Clean is called before DotnetRestore "Clean" ?=> "DotnetRestore" "Clean" ==> "DotnetPack" -// // Only call AssemblyInfo if Publish was in the call chain -// // Ensure AssemblyInfo is called after DotnetRestore and before DotnetBuild +// Only call AssemblyInfo if Publish was in the call chain +// Ensure AssemblyInfo is called after DotnetRestore and before DotnetBuild "DotnetRestore" ?=> "AssemblyInfo" "AssemblyInfo" ?=> "DotnetBuild" "AssemblyInfo" ==> "Publish" @@ -348,5 +377,8 @@ Target.create "Release" ignore "DotnetRestore" ==> "WatchTests" +//----------------------------------------------------------------------------- +// Target Start +//----------------------------------------------------------------------------- Target.runOrDefaultWithArguments "DotnetPack" From e9674a46ee0f682a0ed1e3eb946735d1adffe400 Mon Sep 17 00:00:00 2001 From: Jimmy Byrd Date: Mon, 20 May 2019 15:53:22 -0400 Subject: [PATCH 2/6] Target name changes --- Content/Library/build.fsx | 88 +++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/Content/Library/build.fsx b/Content/Library/build.fsx index 25088149..f04dc47d 100644 --- a/Content/Library/build.fsx +++ b/Content/Library/build.fsx @@ -62,9 +62,9 @@ let invokeAsync f = async { f () } let configuration (targets : Target list) = let defaultVal = if isRelease targets then "Release" else "Debug" match Environment.environVarOrDefault "CONFIGURATION" defaultVal with - | "Debug" -> DotNet.BuildConfiguration.Debug - | "Release" -> DotNet.BuildConfiguration.Release - | config -> DotNet.BuildConfiguration.Custom config + | "Debug" -> DotNet.BuildConfiguration.Debug + | "Release" -> DotNet.BuildConfiguration.Release + | config -> DotNet.BuildConfiguration.Custom config let failOnBadExitAndPrint (p : ProcessResult) = if p.ExitCode <> 0 then @@ -116,9 +116,7 @@ let clean _ = ++ testsGlob |> Seq.collect(fun p -> ["bin";"obj"] - |> Seq.map(fun sp -> - IO.Path.GetDirectoryName p @@ sp) - ) + |> Seq.map(fun sp -> IO.Path.GetDirectoryName p @@ sp )) |> Shell.cleanDirs [ @@ -138,7 +136,7 @@ let dotnetRestore _ = ] |> String.concat " " DotNet.restore(fun c -> { c with - Common = + Common = c.Common |> DotNet.Options.withCustomParams (Some(args)) @@ -236,22 +234,24 @@ let generateAssemblyInfo _ = | Some pr -> pr.Name | _ -> "release" let getAssemblyInfoAttributes projectName = - [ AssemblyInfo.Title (projectName) - AssemblyInfo.Product productName - AssemblyInfo.Version releaseNotes.AssemblyVersion - AssemblyInfo.Metadata("ReleaseDate", releaseNotes.Date.Value.ToString("o")) - AssemblyInfo.FileVersion releaseNotes.AssemblyVersion - AssemblyInfo.InformationalVersion releaseNotes.AssemblyVersion - AssemblyInfo.Metadata("ReleaseChannel", releaseChannel) - AssemblyInfo.Metadata("GitHash", Git.Information.getCurrentSHA1(null)) + [ + AssemblyInfo.Title (projectName) + AssemblyInfo.Product productName + AssemblyInfo.Version releaseNotes.AssemblyVersion + AssemblyInfo.Metadata("ReleaseDate", releaseNotes.Date.Value.ToString("o")) + AssemblyInfo.FileVersion releaseNotes.AssemblyVersion + AssemblyInfo.InformationalVersion releaseNotes.AssemblyVersion + AssemblyInfo.Metadata("ReleaseChannel", releaseChannel) + AssemblyInfo.Metadata("GitHash", Git.Information.getCurrentSHA1(null)) ] let getProjectDetails projectPath = let projectName = IO.Path.GetFileNameWithoutExtension(projectPath) - ( projectPath, - projectName, - IO.Path.GetDirectoryName(projectPath), - (getAssemblyInfoAttributes projectName) + ( + projectPath, + projectName, + IO.Path.GetDirectoryName(projectPath), + (getAssemblyInfoAttributes projectName) ) srcAndTest @@ -308,18 +308,18 @@ let gitRelease _ = Git.Branches.pushTag "" "origin" releaseNotes.NugetVersion let githubRelease _ = - let token = - match Environment.environVarOrDefault "GITHUB_TOKEN" "" with - | s when not (String.IsNullOrWhiteSpace s) -> s - | _ -> failwith "please set the github_token environment variable to a github personal access token with repro access." + let token = + match Environment.environVarOrDefault "GITHUB_TOKEN" "" with + | s when not (String.IsNullOrWhiteSpace s) -> s + | _ -> failwith "please set the github_token environment variable to a github personal access token with repro access." - let files = !! distGlob + let files = !! distGlob - GitHub.createClientWithToken token - |> GitHub.draftNewRelease gitOwner gitRepoName releaseNotes.NugetVersion (releaseNotes.SemVer.PreRelease <> None) releaseNotes.Notes - |> GitHub.uploadFiles files - |> GitHub.publishDraft - |> Async.RunSynchronously + GitHub.createClientWithToken token + |> GitHub.draftNewRelease gitOwner gitRepoName releaseNotes.NugetVersion (releaseNotes.SemVer.PreRelease <> None) releaseNotes.Notes + |> GitHub.uploadFiles files + |> GitHub.publishDraft + |> Async.RunSynchronously let formatCode _ = srcAndTest @@ -338,10 +338,10 @@ Target.create "DotnetBuild" dotnetBuild Target.create "DotnetTest" dotnetTest Target.create "GenerateCoverageReport" generateCoverageReport Target.create "WatchTests" watchTests -Target.create "AssemblyInfo" generateAssemblyInfo +Target.create "GenerateAssemblyInfo" generateAssemblyInfo Target.create "DotnetPack" dotnetPack Target.create "SourcelinkTest" sourceLinkTest -Target.create "Publish" publishToNuget +Target.create "PublishToNuget" publishToNuget Target.create "GitRelease" gitRelease Target.create "GitHubRelease" githubRelease Target.create "FormatCode" formatCode @@ -359,23 +359,23 @@ Target.create "Release" ignore // Only call AssemblyInfo if Publish was in the call chain // Ensure AssemblyInfo is called after DotnetRestore and before DotnetBuild -"DotnetRestore" ?=> "AssemblyInfo" -"AssemblyInfo" ?=> "DotnetBuild" -"AssemblyInfo" ==> "Publish" +"DotnetRestore" ?=> "GenerateAssemblyInfo" +"GenerateAssemblyInfo" ?=> "DotnetBuild" +"GenerateAssemblyInfo" ==> "PublishToNuget" "DotnetRestore" - ==> "DotnetBuild" - ==> "DotnetTest" - ==> "GenerateCoverageReport" - ==> "DotnetPack" - ==> "SourcelinkTest" - ==> "Publish" - ==> "GitRelease" - ==> "GitHubRelease" - ==> "Release" + ==> "DotnetBuild" + ==> "DotnetTest" + ==> "GenerateCoverageReport" + ==> "DotnetPack" + ==> "SourcelinkTest" + ==> "PublishToNuget" + ==> "GitRelease" + ==> "GitHubRelease" + ==> "Release" "DotnetRestore" - ==> "WatchTests" + ==> "WatchTests" //----------------------------------------------------------------------------- // Target Start From b16dac3efe6ceff46702b663492a7b2fdf0280a2 Mon Sep 17 00:00:00 2001 From: Jimmy Byrd Date: Mon, 20 May 2019 17:07:22 -0400 Subject: [PATCH 3/6] Reorganize Console build.fsx --- Content/Console/build.fsx | 149 +++++++++++++++++++++++--------------- Content/Library/build.fsx | 6 +- 2 files changed, 96 insertions(+), 59 deletions(-) diff --git a/Content/Console/build.fsx b/Content/Console/build.fsx index a4af91d9..5b03b756 100644 --- a/Content/Console/build.fsx +++ b/Content/Console/build.fsx @@ -20,8 +20,10 @@ BuildServer.install [ Travis.Installer ] +//----------------------------------------------------------------------------- +// Metadata and Configuration +//----------------------------------------------------------------------------- -let release = Fake.Core.ReleaseNotes.load "RELEASE_NOTES.md" let productName = "MyLib.1" let sln = "MyLib.1.sln" @@ -40,16 +42,42 @@ let distDir = __SOURCE_DIRECTORY__ @@ "dist" let distGlob = distDir @@ "*.nupkg" let toolsDir = __SOURCE_DIRECTORY__ @@ "tools" + +let coverageThresholdPercent = 1 let coverageReportDir = __SOURCE_DIRECTORY__ @@ "docs" @@ "coverage" let gitOwner = "MyGithubUsername" let gitRepoName = "MyLib.1" +let releaseBranch = "master" +let releaseNotes = Fake.Core.ReleaseNotes.load "RELEASE_NOTES.md" + +let targetFramework = "netcoreapp2.2" + +// RuntimeIdentifiers: https://docs.microsoft.com/en-us/dotnet/core/rid-catalog +// dotnet-packaging Tasks: https://github.com/qmfrederik/dotnet-packaging/blob/0c8e063ada5ba0de2b194cd3fad8308671b48092/Packaging.Targets/build/Packaging.Targets.targets +let runtimes = [ + "linux-x64", "CreateTarball" + "osx-x64", "CreateTarball" + "win-x64", "CreateZip" +] + +let paketToolPath = __SOURCE_DIRECTORY__ ".paket" (if Environment.isWindows then "paket.exe" else "paket") + +//----------------------------------------------------------------------------- +// Helpers +//----------------------------------------------------------------------------- +let invokeAsync f = async { f () } + let isRelease (targets : Target list) = targets |> Seq.map(fun t -> t.Name) |> Seq.exists ((=)"Release") + +let isReleaseBranchCheck () = + if Git.Information.getBranchName "" <> releaseBranch then failwithf "Not on %s. If you want to release please switch to this branch." releaseBranch + let configuration (targets : Target list) = let defaultVal = if isRelease targets then "Release" else "Debug" match Environment.environVarOrDefault "CONFIGURATION" defaultVal with @@ -89,7 +117,11 @@ module dotnet = tool optionConfig "reportgenerator" args -Target.create "Clean" <| fun _ -> +//----------------------------------------------------------------------------- +// Target Implementations +//----------------------------------------------------------------------------- + +let clean _ = ["bin"; "temp" ; distDir; coverageReportDir] |> Shell.cleanDirs @@ -107,15 +139,15 @@ Target.create "Clean" <| fun _ -> ] |> Seq.iter Shell.rm -Target.create "DotnetRestore" <| fun _ -> +let dotnetRestore _ = Paket.restore(fun p -> - {p with ToolPath = __SOURCE_DIRECTORY__ ".paket" (if Environment.isWindows then "paket.exe" else "paket")}) + {p with ToolPath = paketToolPath}) [sln ; toolsDir] |> Seq.map(fun dir -> fun () -> let args = [ - sprintf "/p:PackageVersion=%s" release.NugetVersion + sprintf "/p:PackageVersion=%s" releaseNotes.NugetVersion ] |> String.concat " " DotNet.restore(fun c -> { c with @@ -126,11 +158,10 @@ Target.create "DotnetRestore" <| fun _ -> }) dir) |> Seq.iter(retryIfInCI 10) -Target.create "DotnetBuild" <| fun ctx -> - +let dotnetBuild ctx = let args = [ - sprintf "/p:PackageVersion=%s" release.NugetVersion + sprintf "/p:PackageVersion=%s" releaseNotes.NugetVersion "--no-restore" ] |> String.concat " " DotNet.build(fun c -> @@ -142,12 +173,7 @@ Target.create "DotnetBuild" <| fun ctx -> (Some(args)) }) sln - -let invokeAsync f = async { f () } - -let coverageThresholdPercent = 1 - -Target.create "DotnetTest" <| fun ctx -> +let dotnetTest ctx = let excludeCoverage = !! testsGlob |> Seq.map IO.Path.GetFileNameWithoutExtension @@ -168,8 +194,7 @@ Target.create "DotnetTest" <| fun ctx -> (Some(args)) }) sln - -Target.create "GenerateCoverageReport" <| fun _ -> +let generateCoverageReport _ = let coverageReports = !!"tests/**/coverage.*.xml" |> String.concat ";" @@ -192,8 +217,8 @@ Target.create "GenerateCoverageReport" <| fun _ -> |> String.concat " " dotnet.reportgenerator id args +let watchApp _ = -Target.create "WatchApp" <| fun _ -> let appArgs = [ "World" @@ -205,8 +230,7 @@ Target.create "WatchApp" <| fun _ -> appArgs |> ignore - -Target.create "WatchTests" <| fun _ -> +let watchTests _ = !! testsGlob |> Seq.map(fun proj -> fun () -> dotnet.watch @@ -222,26 +246,26 @@ Target.create "WatchTests" <| fun _ -> let cancelEvent = Console.CancelKeyPress |> Async.AwaitEvent |> Async.RunSynchronously cancelEvent.Cancel <- true -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) +let generateAssemblyInfo _ = + 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) -Target.create "AssemblyInfo" <| fun _ -> let releaseChannel = - match release.SemVer.PreRelease with + match releaseNotes.SemVer.PreRelease with | Some pr -> pr.Name | _ -> "release" let getAssemblyInfoAttributes projectName = [ AssemblyInfo.Title (projectName) AssemblyInfo.Product productName - AssemblyInfo.Version release.AssemblyVersion - AssemblyInfo.Metadata("ReleaseDate", release.Date.Value.ToString("o")) - AssemblyInfo.FileVersion release.AssemblyVersion - AssemblyInfo.InformationalVersion release.AssemblyVersion + AssemblyInfo.Version releaseNotes.AssemblyVersion + AssemblyInfo.Metadata("ReleaseDate", releaseNotes.Date.Value.ToString("o")) + AssemblyInfo.FileVersion releaseNotes.AssemblyVersion + AssemblyInfo.InformationalVersion releaseNotes.AssemblyVersion AssemblyInfo.Metadata("ReleaseChannel", releaseChannel) AssemblyInfo.Metadata("GitHash", Git.Information.getCurrentSHA1(null)) ] @@ -263,15 +287,7 @@ Target.create "AssemblyInfo" <| fun _ -> | Vbproj -> AssemblyInfoFile.createVisualBasic ((folderName @@ "My Project") @@ "AssemblyInfo.vb") attributes ) -let runtimes = [ - "linux-x64", "CreateTarball" - "osx-x64", "CreateTarball" - "win-x64", "CreateZip" -] - -Target.create "CreatePackages" <| fun _ -> - - let targetFramework = "netcoreapp2.2" +let createPackages _ = runtimes |> Seq.iter(fun (runtime, packageType) -> let args = @@ -281,8 +297,8 @@ Target.create "CreatePackages" <| fun _ -> sprintf "/p:CustomTarget=%s" packageType sprintf "/p:RuntimeIdentifier=%s" runtime sprintf "/p:Configuration=%s" "Release" - sprintf "/p:PackageVersion=%s" release.NugetVersion - sprintf "/p:PackagePath=%s" (distDir @@ (sprintf "%s-%s-%s" productName release.NugetVersion runtime )) + sprintf "/p:PackageVersion=%s" releaseNotes.NugetVersion + sprintf "/p:PackagePath=%s" (distDir @@ (sprintf "%s-%s-%s" productName releaseNotes.NugetVersion runtime )) ] |> String.concat " " let result = DotNet.exec (fun opt -> @@ -294,25 +310,19 @@ Target.create "CreatePackages" <| fun _ -> failwith "package creation failed" ) - -let isReleaseBranchCheck () = - let releaseBranch = "master" - if Git.Information.getBranchName "" <> releaseBranch then failwithf "Not on %s. If you want to release please switch to this branch." releaseBranch - - -Target.create "GitRelease" <| fun _ -> +let gitRelease _ = isReleaseBranchCheck () - let releaseNotesGitCommitFormat = release.Notes |> Seq.map(sprintf "* %s\n") |> String.concat "" + let releaseNotesGitCommitFormat = releaseNotes.Notes |> Seq.map(sprintf "* %s\n") |> String.concat "" Git.Staging.stageAll "" - Git.Commit.exec "" (sprintf "Bump version to %s \n%s" release.NugetVersion releaseNotesGitCommitFormat) + Git.Commit.exec "" (sprintf "Bump version to %s \n%s" releaseNotes.NugetVersion releaseNotesGitCommitFormat) Git.Branches.push "" - Git.Branches.tag "" release.NugetVersion - Git.Branches.pushTag "" "origin" release.NugetVersion + Git.Branches.tag "" releaseNotes.NugetVersion + Git.Branches.pushTag "" "origin" releaseNotes.NugetVersion -Target.create "GitHubRelease" <| fun _ -> +let githubRelease _ = let token = match Environment.environVarOrDefault "GITHUB_TOKEN" "" with | s when not (String.IsNullOrWhiteSpace s) -> s @@ -321,27 +331,47 @@ Target.create "GitHubRelease" <| fun _ -> let files = !! distGlob GitHub.createClientWithToken token - |> GitHub.draftNewRelease gitOwner gitRepoName release.NugetVersion (release.SemVer.PreRelease <> None) release.Notes + |> GitHub.draftNewRelease gitOwner gitRepoName releaseNotes.NugetVersion (releaseNotes.SemVer.PreRelease <> None) releaseNotes.Notes |> GitHub.uploadFiles files |> GitHub.publishDraft |> Async.RunSynchronously -Target.create "FormatCode" <| fun _ -> +let formatCode _ = srcAndTest |> Seq.map (IO.Path.GetDirectoryName) |> Seq.iter (fun projDir -> dotnet.fantomas id (sprintf "--recurse %s" projDir) ) +//----------------------------------------------------------------------------- +// Target Declaration +//----------------------------------------------------------------------------- + +Target.create "Clean" clean +Target.create "DotnetRestore" dotnetRestore +Target.create "DotnetBuild" dotnetBuild +Target.create "DotnetTest" dotnetTest +Target.create "GenerateCoverageReport" generateCoverageReport +Target.create "WatchApp" watchApp +Target.create "WatchTests" watchTests +Target.create "AssemblyInfo" generateAssemblyInfo +Target.create "CreatePackages" createPackages +Target.create "GitRelease" gitRelease +Target.create "GitHubRelease" githubRelease +Target.create "FormatCode" formatCode Target.create "Release" ignore +//----------------------------------------------------------------------------- +// Target Dependencies +//----------------------------------------------------------------------------- + // Only call Clean if DotnetPack was in the call chain // Ensure Clean is called before DotnetRestore "Clean" ?=> "DotnetRestore" "Clean" ==> "CreatePackages" -// // Only call AssemblyInfo if Publish was in the call chain -// // Ensure AssemblyInfo is called after DotnetRestore and before DotnetBuild +// Only call AssemblyInfo if Publish was in the call chain +// Ensure AssemblyInfo is called after DotnetRestore and before DotnetBuild "DotnetRestore" ?=> "AssemblyInfo" "AssemblyInfo" ?=> "DotnetBuild" "AssemblyInfo" ==> "GitRelease" @@ -358,5 +388,8 @@ Target.create "Release" ignore "DotnetRestore" ==> "WatchTests" +//----------------------------------------------------------------------------- +// Target Start +//----------------------------------------------------------------------------- Target.runOrDefaultWithArguments "CreatePackages" diff --git a/Content/Library/build.fsx b/Content/Library/build.fsx index f04dc47d..852eae68 100644 --- a/Content/Library/build.fsx +++ b/Content/Library/build.fsx @@ -26,6 +26,7 @@ BuildServer.install [ let productName = "MyLib.1" let sln = "MyLib.1.sln" + let srcGlob =__SOURCE_DIRECTORY__ @@ "src/**/*.??proj" let testsGlob = __SOURCE_DIRECTORY__ @@ "tests/**/*.??proj" @@ -37,6 +38,8 @@ let distDir = __SOURCE_DIRECTORY__ @@ "dist" let distGlob = distDir @@ "*.nupkg" let toolsDir = __SOURCE_DIRECTORY__ @@ "tools" + +let coverageThresholdPercent = 80 let coverageReportDir = __SOURCE_DIRECTORY__ @@ "docs" @@ "coverage" let gitOwner = "MyGithubUsername" @@ -52,6 +55,7 @@ let paketToolPath = __SOURCE_DIRECTORY__ ".paket" (if Environment.isWind //----------------------------------------------------------------------------- // Helpers //----------------------------------------------------------------------------- + let isRelease (targets : Target list) = targets |> Seq.map(fun t -> t.Name) @@ -71,6 +75,7 @@ let failOnBadExitAndPrint (p : ProcessResult) = p.Errors |> Seq.iter Trace.traceError failwithf "failed with exitcode %d" p.ExitCode +// CI Servers can have bizzare failures that have nothing to do with your code let rec retryIfInCI times fn = match Environment.environVarOrNone "CI" with | Some _ -> @@ -160,7 +165,6 @@ let dotnetBuild ctx = }) sln let dotnetTest ctx = - let coverageThresholdPercent = 80 let excludeCoverage = !! testsGlob |> Seq.map IO.Path.GetFileNameWithoutExtension From d040a1a0031b4ca914f75ff9fb6f106fb84b1b56 Mon Sep 17 00:00:00 2001 From: Jimmy Byrd Date: Mon, 20 May 2019 17:09:41 -0400 Subject: [PATCH 4/6] Fix console app dist glob --- Content/Console/build.fsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Content/Console/build.fsx b/Content/Console/build.fsx index 5b03b756..9ec50d65 100644 --- a/Content/Console/build.fsx +++ b/Content/Console/build.fsx @@ -39,9 +39,12 @@ let srcAndTest = ++ testsGlob let distDir = __SOURCE_DIRECTORY__ @@ "dist" -let distGlob = distDir @@ "*.nupkg" -let toolsDir = __SOURCE_DIRECTORY__ @@ "tools" +let distGlob = + !! (distDir @@ "*.zip") + ++ (distDir @@ "*.tgz") + ++ (distDir @@ "*.tar.gz") +let toolsDir = __SOURCE_DIRECTORY__ @@ "tools" let coverageThresholdPercent = 1 let coverageReportDir = __SOURCE_DIRECTORY__ @@ "docs" @@ "coverage" @@ -328,7 +331,7 @@ let githubRelease _ = | s when not (String.IsNullOrWhiteSpace s) -> s | _ -> failwith "please set the github_token environment variable to a github personal access token with repro access." - let files = !! distGlob + let files = distGlob GitHub.createClientWithToken token |> GitHub.draftNewRelease gitOwner gitRepoName releaseNotes.NugetVersion (releaseNotes.SemVer.PreRelease <> None) releaseNotes.Notes From 60c7caa8576df57929eeee8cca70240ae48f28f6 Mon Sep 17 00:00:00 2001 From: Jimmy Byrd Date: Mon, 20 May 2019 17:39:12 -0400 Subject: [PATCH 5/6] change dotnet args options --- Content/Console/build.fsx | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/Content/Console/build.fsx b/Content/Console/build.fsx index 9ec50d65..285b457a 100644 --- a/Content/Console/build.fsx +++ b/Content/Console/build.fsx @@ -151,13 +151,12 @@ let dotnetRestore _ = let args = [ sprintf "/p:PackageVersion=%s" releaseNotes.NugetVersion - ] |> String.concat " " + ] DotNet.restore(fun c -> { c with Common = c.Common - |> DotNet.Options.withCustomParams - (Some(args)) + |> DotNet.Options.withAdditionalArgs args }) dir) |> Seq.iter(retryIfInCI 10) @@ -166,14 +165,13 @@ let dotnetBuild ctx = [ sprintf "/p:PackageVersion=%s" releaseNotes.NugetVersion "--no-restore" - ] |> String.concat " " + ] DotNet.build(fun c -> { c with Configuration = configuration (ctx.Context.AllExecutingTargets) Common = c.Common - |> DotNet.Options.withCustomParams - (Some(args)) + |> DotNet.Options.withAdditionalArgs args }) sln let dotnetTest ctx = @@ -188,13 +186,12 @@ let dotnetTest ctx = "/p:AltCover=true" sprintf "/p:AltCoverThreshold=%d" coverageThresholdPercent sprintf "/p:AltCoverAssemblyExcludeFilter=%s" excludeCoverage - ] |> String.concat " " + ] { c with Configuration = configuration (ctx.Context.AllExecutingTargets) Common = c.Common - |> DotNet.Options.withCustomParams - (Some(args)) + |> DotNet.Options.withAdditionalArgs args }) sln let generateCoverageReport _ = From 32ab44b0ddd1a3a16778ea2ae99f4b3fe8cba228 Mon Sep 17 00:00:00 2001 From: Jimmy Byrd Date: Mon, 20 May 2019 17:44:39 -0400 Subject: [PATCH 6/6] code formatting --- Content/Console/build.fsx | 57 +++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/Content/Console/build.fsx b/Content/Console/build.fsx index 285b457a..da400eee 100644 --- a/Content/Console/build.fsx +++ b/Content/Console/build.fsx @@ -84,9 +84,9 @@ let isReleaseBranchCheck () = let configuration (targets : Target list) = let defaultVal = if isRelease targets then "Release" else "Debug" match Environment.environVarOrDefault "CONFIGURATION" defaultVal with - | "Debug" -> DotNet.BuildConfiguration.Debug - | "Release" -> DotNet.BuildConfiguration.Release - | config -> DotNet.BuildConfiguration.Custom config + | "Debug" -> DotNet.BuildConfiguration.Debug + | "Release" -> DotNet.BuildConfiguration.Release + | config -> DotNet.BuildConfiguration.Custom config let failOnBadExitAndPrint (p : ProcessResult) = if p.ExitCode <> 0 then @@ -133,7 +133,7 @@ let clean _ = |> Seq.collect(fun p -> ["bin";"obj"] |> Seq.map(fun sp -> - IO.Path.GetDirectoryName p @@ sp) + IO.Path.GetDirectoryName p @@ sp) ) |> Shell.cleanDirs @@ -154,7 +154,7 @@ let dotnetRestore _ = ] DotNet.restore(fun c -> { c with - Common = + Common = c.Common |> DotNet.Options.withAdditionalArgs args }) dir) @@ -272,10 +272,11 @@ let generateAssemblyInfo _ = let getProjectDetails projectPath = let projectName = IO.Path.GetFileNameWithoutExtension(projectPath) - ( projectPath, - projectName, - IO.Path.GetDirectoryName(projectPath), - (getAssemblyInfoAttributes projectName) + ( + projectPath, + projectName, + IO.Path.GetDirectoryName(projectPath), + (getAssemblyInfoAttributes projectName) ) srcAndTest @@ -300,14 +301,12 @@ let createPackages _ = sprintf "/p:PackageVersion=%s" releaseNotes.NugetVersion sprintf "/p:PackagePath=%s" (distDir @@ (sprintf "%s-%s-%s" productName releaseNotes.NugetVersion runtime )) ] |> String.concat " " - let result = - DotNet.exec (fun opt -> - { opt with - WorkingDirectory = mainApp } - ) "msbuild" args - if result.OK |> not then - result.Errors |> Seq.iter Trace.traceError - failwith "package creation failed" + + DotNet.exec (fun opt -> + { opt with + WorkingDirectory = mainApp } + ) "msbuild" args + |> failOnBadExitAndPrint ) let gitRelease _ = @@ -323,18 +322,18 @@ let gitRelease _ = Git.Branches.pushTag "" "origin" releaseNotes.NugetVersion let githubRelease _ = - let token = - match Environment.environVarOrDefault "GITHUB_TOKEN" "" with - | s when not (String.IsNullOrWhiteSpace s) -> s - | _ -> failwith "please set the github_token environment variable to a github personal access token with repro access." - - let files = distGlob - - GitHub.createClientWithToken token - |> GitHub.draftNewRelease gitOwner gitRepoName releaseNotes.NugetVersion (releaseNotes.SemVer.PreRelease <> None) releaseNotes.Notes - |> GitHub.uploadFiles files - |> GitHub.publishDraft - |> Async.RunSynchronously + let token = + match Environment.environVarOrDefault "GITHUB_TOKEN" "" with + | s when not (String.IsNullOrWhiteSpace s) -> s + | _ -> failwith "please set the github_token environment variable to a github personal access token with repro access." + + let files = distGlob + + GitHub.createClientWithToken token + |> GitHub.draftNewRelease gitOwner gitRepoName releaseNotes.NugetVersion (releaseNotes.SemVer.PreRelease <> None) releaseNotes.Notes + |> GitHub.uploadFiles files + |> GitHub.publishDraft + |> Async.RunSynchronously let formatCode _ = srcAndTest