From a3f45caf6882e983ab689cd939791ddae77d096c Mon Sep 17 00:00:00 2001 From: ivelten Date: Tue, 20 Sep 2022 22:29:44 -0300 Subject: [PATCH] Fixing build script to use DotNet cli publishing --- build.fsx | 130 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 86 insertions(+), 44 deletions(-) diff --git a/build.fsx b/build.fsx index 17e89ae2d..eb32e84d2 100644 --- a/build.fsx +++ b/build.fsx @@ -11,22 +11,15 @@ #r "nuget: System.Reactive" #r "nuget: Octokit" -open System open System.IO -open System.Collections.Generic -open System.Threading open Fake -open Fake.Tools.Git open Fake.DotNet -open Fake.DotNet.NuGet open Fake.IO open Fake.IO.FileSystemOperators open Fake.IO.Globbing.Operators open Fake.Core.TargetOperators open Fake.Tools open Fake.Core -open Fake.Api -open Octokit // https://github.com/fsprojects/FAKE/issues/2517 // Regular header and `#load ".fake/build.fsx/intellisense.fsx"` @@ -50,7 +43,9 @@ execContext // - to run tests and to publish documentation on GitHub gh-pages // - for documentation, you also need to edit info in "docs/tools/generate.fsx" -let [] DotNetMoniker = "net6.0" +[] +let DotNetMoniker = "net6.0" + let project = "FSharp.Data.GraphQL" let release = ReleaseNotes.load "RELEASE_NOTES.md" let projectRepo = "https://github.com/fsprojects/FSharp.Data.GraphQL.git" @@ -58,20 +53,19 @@ let projectRepo = "https://github.com/fsprojects/FSharp.Data.GraphQL.git" // -------------------------------------------------------------------------------------- // Clean build results -Target.create "Clean" <| fun _ -> Shell.cleanDirs [ "bin"; "temp" ] +Target.create "Clean" <| fun _ -> Shell.cleanDirs [ "bin"; "temp" ] Target.create "CleanDocs" <| fun _ -> Shell.cleanDirs [ "docs/output" ] // -------------------------------------------------------------------------------------- // Build library & test project -Target.create "Restore" <| fun _ -> - !! "src/**/*.??proj" - -- "src/**/*.shproj" +Target.create "Restore" <| fun _ -> + !! "src/**/*.??proj" -- "src/**/*.shproj" |> Seq.iter (fun pattern -> DotNet.restore id pattern) -Target.create "Build" <| fun _ -> +Target.create "Build" <| fun _ -> "FSharp.Data.GraphQL.sln" |> DotNet.build (fun o -> { o with @@ -88,10 +82,18 @@ let startGraphQLServer (project : string) (streamRef : DataRef) = let projectName = Path.GetFileNameWithoutExtension (project) let projectPath = Path.GetDirectoryName (project) - let serverExe = projectPath "bin" "Release" DotNetMoniker (projectName + ".dll") + + let serverExe = + projectPath + "bin" + "Release" + DotNetMoniker + (projectName + ".dll") CreateProcess.fromRawCommandLine "dotnet" serverExe - |> CreateProcess.withStandardInput (CreatePipe streamRef) |> Proc.start |> ignore + |> CreateProcess.withStandardInput (CreatePipe streamRef) + |> Proc.start + |> ignore System.Threading.Thread.Sleep (2000) @@ -115,28 +117,43 @@ let starWarsServerStream = StreamRef.Empty Target.create "StartStarWarsServer" <| fun _ -> Target.activateFinal "StopStarWarsServer" - let project = "samples" "star-wars-api" "FSharp.Data.GraphQL.Samples.StarWarsApi.fsproj" + + let project = + "samples" + "star-wars-api" + "FSharp.Data.GraphQL.Samples.StarWarsApi.fsproj" + startGraphQLServer project starWarsServerStream Target.createFinal "StopStarWarsServer" <| fun _ -> - try starWarsServerStream.Value.Write ([| 0uy |], 0, 1) - with e -> printfn "%s" e.Message - + try + starWarsServerStream.Value.Write ([| 0uy |], 0, 1) + with e -> + printfn "%s" e.Message let integrationServerStream = StreamRef.Empty Target.create "StartIntegrationServer" <| fun _ -> Target.activateFinal "StopIntegrationServer" - let project = "tests" "FSharp.Data.GraphQL.IntegrationTests.Server" "FSharp.Data.GraphQL.IntegrationTests.Server.fsproj" + + let project = + "tests" + "FSharp.Data.GraphQL.IntegrationTests.Server" + "FSharp.Data.GraphQL.IntegrationTests.Server.fsproj" + startGraphQLServer project integrationServerStream Target.createFinal "StopIntegrationServer" <| fun _ -> - try integrationServerStream.Value.Write ([| 0uy |], 0, 1) - with e -> printfn "%s" e.Message + try + integrationServerStream.Value.Write ([| 0uy |], 0, 1) + with e -> + printfn "%s" e.Message -Target.create "RunUnitTests" <| fun _ -> runTests "tests/FSharp.Data.GraphQL.Tests/FSharp.Data.GraphQL.Tests.fsproj" +Target.create "RunUnitTests" <| fun _ -> + runTests "tests/FSharp.Data.GraphQL.Tests/FSharp.Data.GraphQL.Tests.fsproj" -Target.create "RunIntegrationTests" <| fun _ -> runTests "tests/FSharp.Data.GraphQL.IntegrationTests/FSharp.Data.GraphQL.IntegrationTests.fsproj" +Target.create "RunIntegrationTests" <| fun _ -> + runTests "tests/FSharp.Data.GraphQL.IntegrationTests/FSharp.Data.GraphQL.IntegrationTests.fsproj" let prepareDocGen () = Shell.rm "docs/release-notes.md" @@ -149,7 +166,7 @@ let prepareDocGen () = Shell.cleanDir ".fsdocs" -Target.create "GenerateDocs" <| fun _ -> +Target.create "GenerateDocs" <| fun _ -> prepareDocGen () DotNet.exec id "fsdocs" "build --clean" |> ignore @@ -158,42 +175,66 @@ Target.create "GenerateDocsWatch" <| fun _ -> DotNet.exec id "fsdocs" "watch --clean" |> ignore System.Console.ReadKey () |> ignore -Target.create "ReleaseDocs" <| fun _ -> +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" + + 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.CommandHelper.runSimpleGitCommand "temp/gh-pages" cmd + |> printfn "%s" + Git.Branches.push "temp/gh-pages" +let getPackageName id = sprintf "%s.%s" project id + +let getPackageDir packageName = sprintf "nuget/%s" packageName + +let getProjectPath packageName = sprintf "src/%s/%s.fsproj" packageName packageName + let pack id = - Shell.cleanDir <| sprintf "nuget/%s.%s" project id - id |> NuGet.NuGetPack (fun p -> + let packageName = getPackageName id + let packageDir = getPackageDir packageName + let projectPath = getProjectPath packageName + + Shell.cleanDir packageDir + + projectPath + |> DotNet.pack (fun p -> { p with - Version = release.NugetVersion - OutputPath = sprintf "nuget/%s.%s" project id - //IncludeReferencedProjects = false - }) + Common = { p.Common with Version = Some release.NugetVersion } + OutputPath = Some packageDir }) let publishPackage id = - pack id - NuGet.NuGetPublish <| fun p -> { p with WorkingDir = sprintf "nuget/%s.%s" project id } + let packageName = getPackageName id + let packageDir = getPackageDir packageName + let projectPath = getProjectPath packageName -Target.create "PublishServer" <| fun _ -> publishPackage "Server" + projectPath + |> DotNet.publish (fun p -> + { p with Common = { p.Common with WorkingDirectory = packageDir } }) -Target.create "PublishClient" <| fun _ -> publishPackage "Client" +Target.create "PublishServer" <| fun _ -> publishPackage "Server" + +Target.create "PublishClient" <| fun _ -> publishPackage "Client" Target.create "PublishMiddleware" <| fun _ -> publishPackage "Server.Middleware" -Target.create "PackShared" <| fun _ -> pack "Shared" +Target.create "PublishShared" <| fun _ -> publishPackage "Shared" + +Target.create "PackServer" <| fun _ -> pack "Server" -Target.create "PackServer" <| fun _ -> pack "Server" +Target.create "PackClient" <| fun _ -> pack "Client" -Target.create "PackClient" <| fun _ -> pack "Client" +Target.create "PackMiddleware" <| fun _ -> pack "Server.Middleware" -Target.create "PackMiddleware" <| fun _ -> pack "Server.Middleware" +Target.create "PackShared" <| fun _ -> pack "Shared" // -------------------------------------------------------------------------------------- @@ -212,7 +253,8 @@ Target.create "PackAll" ignore ==> "All" =?> ("GenerateDocs", Environment.environVar "APPVEYOR" = "True") -"CleanDocs" ==> "GenerateDocs" +"CleanDocs" + ==> "GenerateDocs" "PackShared" ==> "PackServer"