Skip to content

Commit

Permalink
Fixing build script to use DotNet cli publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
ivelten authored and xperiandri committed Oct 21, 2022
1 parent b5c61bb commit cb1c806
Showing 1 changed file with 118 additions and 60 deletions.
178 changes: 118 additions & 60 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@
#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
Expand All @@ -25,8 +21,6 @@ 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"`
Expand All @@ -50,28 +44,33 @@ 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 [<Literal>] DotNetMoniker = "net6.0"
[<Literal>]
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"

// --------------------------------------------------------------------------------------
// 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" ]
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
Expand All @@ -88,10 +87,18 @@ let startGraphQLServer (project : string) (streamRef : DataRef<Stream>) =

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)

Expand All @@ -113,30 +120,50 @@ let runTests (project : string) =

let starWarsServerStream = StreamRef.Empty

Target.create "StartStarWarsServer" <| fun _ ->
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
Target.createFinal "StopStarWarsServer"
<| fun _ ->
try
starWarsServerStream.Value.Write ([| 0uy |], 0, 1)
with e ->
printfn "%s" e.Message


let integrationServerStream = StreamRef.Empty

Target.create "StartIntegrationServer" <| fun _ ->
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
Target.createFinal "StopIntegrationServer"
<| fun _ ->
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"
Expand All @@ -149,51 +176,82 @@ let prepareDocGen () =

Shell.cleanDir ".fsdocs"

Target.create "GenerateDocs" <| fun _ ->
Target.create "GenerateDocs"
<| fun _ ->
prepareDocGen ()
DotNet.exec id "fsdocs" "build --clean" |> ignore

Target.create "GenerateDocsWatch" <| fun _ ->
Target.create "GenerateDocsWatch"
<| fun _ ->
prepareDocGen ()
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

projectPath
|> DotNet.publish (fun p -> { p with Common = { p.Common with WorkingDirectory = packageDir } })

Target.create "PublishServer"
<| fun _ -> publishPackage "Server"

Target.create "PublishServer" <| fun _ -> publishPackage "Server"
Target.create "PublishClient"
<| fun _ -> publishPackage "Client"

Target.create "PublishClient" <| fun _ -> publishPackage "Client"
Target.create "PublishMiddleware"
<| fun _ -> publishPackage "Server.Middleware"

Target.create "PublishMiddleware" <| fun _ -> publishPackage "Server.Middleware"
Target.create "PublishShared"
<| fun _ -> publishPackage "Shared"

Target.create "PackShared" <| fun _ -> pack "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"


// --------------------------------------------------------------------------------------
Expand All @@ -203,22 +261,22 @@ Target.create "All" ignore
Target.create "PackAll" ignore

"Clean"
==> "Restore"
==> "Build"
==> "RunUnitTests"
==> "StartStarWarsServer"
==> "StartIntegrationServer"
==> "RunIntegrationTests"
==> "All"
=?> ("GenerateDocs", Environment.environVar "APPVEYOR" = "True")
==> "Restore"
==> "Build"
==> "RunUnitTests"
==> "StartStarWarsServer"
==> "StartIntegrationServer"
==> "RunIntegrationTests"
==> "All"
=?> ("GenerateDocs", Environment.environVar "APPVEYOR" = "True")

"CleanDocs" ==> "GenerateDocs"

"PackShared"
==> "PackServer"
==> "PackClient"
==> "PackMiddleware"
==> "PackAll"
==> "PackServer"
==> "PackClient"
==> "PackMiddleware"
==> "PackAll"

Target.runOrDefaultWithArguments "All"

Expand Down

0 comments on commit cb1c806

Please sign in to comment.