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 a3f45ca
Showing 1 changed file with 86 additions and 44 deletions.
130 changes: 86 additions & 44 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -50,28 +43,29 @@ 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" ]

// --------------------------------------------------------------------------------------
// 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 +82,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 @@ -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"
Expand All @@ -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

Expand All @@ -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"


// --------------------------------------------------------------------------------------
Expand All @@ -212,7 +253,8 @@ Target.create "PackAll" ignore
==> "All"
=?> ("GenerateDocs", Environment.environVar "APPVEYOR" = "True")

"CleanDocs" ==> "GenerateDocs"
"CleanDocs"
==> "GenerateDocs"

"PackShared"
==> "PackServer"
Expand Down

0 comments on commit a3f45ca

Please sign in to comment.