Hyperion/build.fsx

404 строки
15 KiB
Plaintext
Исходник Обычный вид История

2017-01-24 08:46:20 +03:00
#I @"tools/FAKE/tools"
2016-11-24 13:52:29 +03:00
#r "FakeLib.dll"
open System
open System.IO
open System.Text
2017-01-24 08:46:20 +03:00
open Fake
open Fake.DotNetCli
open Fake.DocFxHelper
2021-03-24 22:49:14 +03:00
open Fake.NuGet.Install
2016-11-24 13:52:29 +03:00
// Information about the project for Nuget and Assembly info files
let product = "Hyperion"
2016-11-24 13:52:29 +03:00
let configuration = "Release"
// Metadata used when signing packages and DLLs
let signingName = "Hyperion"
let signingDescription = "A high performance polymorphic serializer for the .NET framework"
let signingUrl = ""
2021-03-24 22:49:14 +03:00
// Directories
let toolsDir = __SOURCE_DIRECTORY__ @@ "tools"
let output = __SOURCE_DIRECTORY__ @@ "bin"
let outputTests = __SOURCE_DIRECTORY__ @@ "TestResults"
let outputPerfTests = __SOURCE_DIRECTORY__ @@ "PerfResults"
let outputBinaries = output @@ "binaries"
let outputBinariesNet461 = outputBinaries @@ "net471"
2021-03-24 22:49:14 +03:00
let outputBinariesNetStandard = outputBinaries @@ "netstandard2.0"
let outputBinariesNet = outputBinaries @@ "net5.0"
let outputNuGet = output @@ "nuget"
// Read release notes and version
let solutionFile = FindFirstMatchingFile "*.sln" __SOURCE_DIRECTORY__ // dynamically look up the solution
let buildNumber = environVarOrDefault "BUILD_NUMBER" "0"
let hasTeamCity = (not (buildNumber = "0")) // check if we have the TeamCity environment variable for build # set
let preReleaseVersionSuffix = "beta" + (if (not (buildNumber = "0")) then (buildNumber) else DateTime.UtcNow.Ticks.ToString())
let releaseNotes =
2021-03-24 22:49:14 +03:00
File.ReadLines (__SOURCE_DIRECTORY__ @@ "RELEASE_NOTES.md")
|> ReleaseNotesHelper.parseReleaseNotes
2021-03-24 22:49:14 +03:00
let versionFromReleaseNotes =
match releaseNotes.SemVer.PreRelease with
| Some r -> r.Origin
| None -> ""
let versionSuffix =
match (getBuildParam "nugetprerelease") with
| "dev" -> preReleaseVersionSuffix
| "" -> versionFromReleaseNotes
| str -> str
// Configuration values for tests
let testNetFrameworkVersion = "net471"
2021-03-24 22:49:14 +03:00
let testNetCoreVersion = "netcoreapp3.1"
let testNetVersion = "net5.0"
2017-01-24 08:46:20 +03:00
Target "Clean" (fun _ ->
ActivateFinalTarget "KillCreatedProcesses"
2017-01-24 08:46:20 +03:00
CleanDir output
CleanDir outputTests
CleanDir outputPerfTests
2021-03-24 22:49:14 +03:00
CleanDir outputBinaries
2017-01-24 08:46:20 +03:00
CleanDir outputNuGet
2021-03-24 22:49:14 +03:00
CleanDir outputBinariesNet461
CleanDir outputBinariesNetStandard
CleanDir outputBinariesNet
CleanDir "docs/_site"
2021-03-24 22:49:14 +03:00
CleanDirs !! "./**/bin"
CleanDirs !! "./**/obj"
CreateDir "bin/nuget"
2017-01-24 08:46:20 +03:00
)
2016-11-24 13:52:29 +03:00
Target "AssemblyInfo" (fun _ ->
XmlPokeInnerText "./src/common.props" "//Project/PropertyGroup/VersionPrefix" releaseNotes.AssemblyVersion
XmlPokeInnerText "./src/common.props" "//Project/PropertyGroup/PackageReleaseNotes" (releaseNotes.Notes |> String.concat "\n")
)
Target "Build" (fun _ ->
2021-03-24 22:49:14 +03:00
let additionalArgs = if versionSuffix.Length > 0 then [sprintf "/p:VersionSuffix=%s" versionSuffix] else []
DotNetCli.Build
2017-01-24 08:46:20 +03:00
(fun p ->
{ p with
Project = solutionFile
2021-03-24 22:49:14 +03:00
Configuration = configuration
AdditionalArgs = additionalArgs }) // "Rebuild"
2016-11-24 13:52:29 +03:00
)
//--------------------------------------------------------------------------------
// Tests targets
//--------------------------------------------------------------------------------
2021-03-24 22:49:14 +03:00
module internal ResultHandling =
let (|OK|Failure|) = function
| 0 -> OK
| x -> Failure x
2016-11-24 13:52:29 +03:00
let buildErrorMessage = function
| OK -> None
| Failure errorCode ->
Some (sprintf "xUnit2 reported an error (Error Code %d)" errorCode)
2016-11-24 13:52:29 +03:00
let failBuildWithMessage = function
| DontFailBuild -> traceError
| _ -> (fun m -> raise(FailedTestsException m))
2016-11-24 22:27:14 +03:00
let failBuildIfXUnitReportedError errorLevel =
buildErrorMessage
>> Option.iter (failBuildWithMessage errorLevel)
2017-01-24 08:46:20 +03:00
Target "RunTests" (fun _ ->
let projects =
match (isWindows) with
| true -> !! "./src/**/*.Tests.csproj"
| _ -> !! "./src/**/*.Tests.csproj"
-- "./src/**/*.API.Tests.csproj" // if you need to filter specs for Linux vs. Windows, do it here
let runSingleProject project =
let arguments =
match (hasTeamCity) with
2021-03-24 22:49:14 +03:00
| true -> (sprintf "test -c Release --no-build --logger:trx --logger:\"console;verbosity=normal\" --framework %s --results-directory \"%s\" -- -parallel none -teamcity" testNetFrameworkVersion outputTests)
| false -> (sprintf "test -c Release --no-build --logger:trx --logger:\"console;verbosity=normal\" --framework %s --results-directory \"%s\" -- -parallel none" testNetFrameworkVersion outputTests)
let result = ExecProcess(fun info ->
info.FileName <- "dotnet"
info.WorkingDirectory <- (Directory.GetParent project).FullName
info.Arguments <- arguments) (TimeSpan.FromMinutes 30.0)
ResultHandling.failBuildIfXUnitReportedError TestRunnerErrorLevel.Error result
CreateDir outputTests
projects |> Seq.iter (log)
projects |> Seq.iter (runSingleProject)
)
Target "RunTestsNetCore" (fun _ ->
let projects =
match (isWindows) with
| true -> !! "./src/**/*.Tests.csproj"
| _ -> !! "./src/**/*.Tests.csproj" // if you need to filter specs for Linux vs. Windows, do it here
let runSingleProject project =
let arguments =
match (hasTeamCity) with
| true -> (sprintf "test -c Release --no-build --logger:trx --logger:\"console;verbosity=normal\" --framework %s --results-directory \"%s\" -- -parallel none -teamcity" testNetCoreVersion outputTests)
| false -> (sprintf "test -c Release --no-build --logger:trx --logger:\"console;verbosity=normal\" --framework %s --results-directory \"%s\" -- -parallel none" testNetCoreVersion outputTests)
let result = ExecProcess(fun info ->
info.FileName <- "dotnet"
info.WorkingDirectory <- (Directory.GetParent project).FullName
info.Arguments <- arguments) (TimeSpan.FromMinutes 30.0)
ResultHandling.failBuildIfXUnitReportedError TestRunnerErrorLevel.Error result
2021-03-24 22:49:14 +03:00
CreateDir outputTests
projects |> Seq.iter (log)
projects |> Seq.iter (runSingleProject)
)
Target "RunTestsNet" (fun _ ->
let projects =
match (isWindows) with
| true -> !! "./src/**/*.Tests.csproj"
| _ -> !! "./src/**/*.Tests.csproj" // if you need to filter specs for Linux vs. Windows, do it here
let runSingleProject project =
let arguments =
match (hasTeamCity) with
| true -> (sprintf "test -c Release --no-build --logger:trx --logger:\"console;verbosity=normal\" --framework %s --results-directory \"%s\" -- -parallel none -teamcity" testNetVersion outputTests)
| false -> (sprintf "test -c Release --no-build --logger:trx --logger:\"console;verbosity=normal\" --framework %s --results-directory \"%s\" -- -parallel none" testNetVersion outputTests)
let result = ExecProcess(fun info ->
info.FileName <- "dotnet"
info.WorkingDirectory <- (Directory.GetParent project).FullName
info.Arguments <- arguments) (TimeSpan.FromMinutes 30.0)
ResultHandling.failBuildIfXUnitReportedError TestRunnerErrorLevel.Error result
CreateDir outputTests
projects |> Seq.iter (log)
projects |> Seq.iter (runSingleProject)
2017-01-24 08:46:20 +03:00
)
2016-11-24 22:27:14 +03:00
Target "NBench" <| fun _ ->
2021-03-24 22:49:14 +03:00
ensureDirectory outputPerfTests
let projects =
match (isWindows) with
| true -> !! "./src/**/*Tests.Performance.csproj"
| _ -> !! "./src/**/*Tests.Performance.csproj" // if you need to filter specs for Linux vs. Windows, do it here
projects |> Seq.iter(fun project ->
let args = new StringBuilder()
|> append "run"
|> append "--no-build"
|> append "-c"
|> append configuration
|> append " -- "
|> append "--output"
|> append outputPerfTests
|> append "--concurrent"
|> append "true"
|> append "--trace"
|> append "true"
|> append "--diagnostic"
2016-11-24 22:27:14 +03:00
|> toText
2021-03-24 22:49:14 +03:00
let result = ExecProcess(fun info ->
info.FileName <- "dotnet"
info.WorkingDirectory <- (Directory.GetParent project).FullName
info.Arguments <- args) (System.TimeSpan.FromMinutes 15.0) (* Reasonably long-running task. *)
if result <> 0 then failwithf "NBench.Runner failed. %s %s" "dotnet" args
)
2016-11-24 13:52:29 +03:00
//--------------------------------------------------------------------------------
// Code signing targets
//--------------------------------------------------------------------------------
Target "SignPackages" (fun _ ->
let canSign = hasBuildParam "SignClientSecret" && hasBuildParam "SignClientUser"
if(false) then
log "Signing information is available."
let assemblies = !! (outputNuGet @@ "*.nupkg")
let signPath =
let globalTool = tryFindFileOnPath "SignClient.exe"
match globalTool with
| Some t -> t
| None -> if isWindows then findToolInSubPath "SignClient.exe" "tools/signclient"
elif isMacOS then findToolInSubPath "SignClient" "tools/signclient"
else findToolInSubPath "SignClient" "tools/signclient"
let signAssembly assembly =
let args = StringBuilder()
|> append "sign"
|> append "--config"
|> append (__SOURCE_DIRECTORY__ @@ "appsettings.json")
|> append "-i"
|> append assembly
|> append "-r"
|> append (getBuildParam "SignClientUser")
|> append "-s"
|> append (getBuildParam "SignClientSecret")
|> append "-n"
|> append signingName
|> append "-d"
|> append signingDescription
|> append "-u"
|> append signingUrl
|> toText
let result = ExecProcess(fun info ->
info.FileName <- signPath
info.WorkingDirectory <- __SOURCE_DIRECTORY__
info.Arguments <- args) (System.TimeSpan.FromMinutes 5.0) (* Reasonably long-running task. *)
if result <> 0 then failwithf "SignClient failed.%s" args
assemblies |> Seq.iter (signAssembly)
else
log "SignClientSecret not available. Skipping signing"
)
2017-01-31 11:47:19 +03:00
//--------------------------------------------------------------------------------
// Nuget targets
//--------------------------------------------------------------------------------
let overrideVersionSuffix (project:string) =
match project with
| _ -> versionSuffix // add additional matches to publish different versions for different projects in solution
Target "CreateNuget" (fun _ ->
let projects = !! "src/**/*.csproj"
-- "src/**/*Tests.csproj" // Don't publish unit tests
-- "src/**/*Tests*.csproj"
let runSingleProject project =
DotNetCli.Pack
(fun p ->
{ p with
Project = project
Configuration = configuration
AdditionalArgs = ["--include-symbols --no-build"]
VersionSuffix = overrideVersionSuffix project
OutputPath = outputNuGet })
projects |> Seq.iter (runSingleProject)
2017-01-24 08:46:20 +03:00
)
2016-11-24 13:52:29 +03:00
2017-01-30 19:55:29 +03:00
Target "PublishNuget" (fun _ ->
let projects = !! "./bin/nuget/*.nupkg" -- "./bin/nuget/*.symbols.nupkg"
2017-01-30 19:55:29 +03:00
let apiKey = getBuildParamOrDefault "nugetkey" ""
let source = getBuildParamOrDefault "nugetpublishurl" ""
let symbolSource = getBuildParamOrDefault "symbolspublishurl" ""
let shouldPublishSymbolsPackages = not (symbolSource = "")
2017-01-30 19:55:29 +03:00
if (not (source = "") && not (apiKey = "") && shouldPublishSymbolsPackages) then
let runSingleProject project =
DotNetCli.RunCommand
(fun p ->
{ p with
TimeOut = TimeSpan.FromMinutes 10. })
(sprintf "nuget push %s --api-key %s --source %s --symbol-source %s" project apiKey source symbolSource)
projects |> Seq.iter (runSingleProject)
else if (not (source = "") && not (apiKey = "") && not shouldPublishSymbolsPackages) then
let runSingleProject project =
DotNetCli.RunCommand
(fun p ->
{ p with
TimeOut = TimeSpan.FromMinutes 10. })
(sprintf "nuget push %s --api-key %s --source %s" project apiKey source)
2017-01-30 19:55:29 +03:00
projects |> Seq.iter (runSingleProject)
2017-01-30 19:55:29 +03:00
)
//--------------------------------------------------------------------------------
// Documentation
//--------------------------------------------------------------------------------
Target "DocFx" (fun _ ->
DotNetCli.Restore (fun p -> { p with Project = solutionFile })
DotNetCli.Build (fun p -> { p with Project = solutionFile; Configuration = configuration })
let docsPath = "./docs"
DocFx (fun p ->
{ p with
Timeout = TimeSpan.FromMinutes 30.0;
WorkingDirectory = docsPath;
DocFxJson = docsPath @@ "docfx.json" })
)
//--------------------------------------------------------------------------------
// Cleanup
//--------------------------------------------------------------------------------
FinalTarget "KillCreatedProcesses" (fun _ ->
log "Shutting down dotnet build-server"
let result = ExecProcess(fun info ->
info.FileName <- "dotnet"
info.WorkingDirectory <- __SOURCE_DIRECTORY__
info.Arguments <- "build-server shutdown") (System.TimeSpan.FromMinutes 2.0)
if result <> 0 then failwithf "dotnet build-server shutdown failed"
)
2016-11-24 13:52:29 +03:00
//--------------------------------------------------------------------------------
// Help
//--------------------------------------------------------------------------------
Target "Help" <| fun _ ->
List.iter printfn [
"usage:"
"./build.ps1 [target]"
2016-11-24 13:52:29 +03:00
""
" Targets for building:"
" * Build Builds"
" * Nuget Create and optionally publish nugets packages"
" * SignPackages Signs all NuGet packages, provided that the following arguments are passed into the script: SignClientSecret={secret} and SignClientUser={username}"
" * RunTests Runs tests"
" * All Builds, run tests, creates and optionally publish nuget packages"
" * DocFx Creates a DocFx-based website for this solution"
2016-11-24 13:52:29 +03:00
""
" Other Targets"
" * Help Display this help"
""]
//--------------------------------------------------------------------------------
// Target dependencies
//--------------------------------------------------------------------------------
2017-01-24 08:46:20 +03:00
Target "BuildRelease" DoNothing
Target "All" DoNothing
2017-01-31 11:47:19 +03:00
Target "Nuget" DoNothing
2021-03-24 22:49:14 +03:00
Target "RunTestsFull" DoNothing
Target "RunTestsNetCoreFull" DoNothing
2017-01-24 08:46:20 +03:00
2016-11-24 13:52:29 +03:00
// build dependencies
"Clean" ==> "AssemblyInfo" ==> "Build" ==> "BuildRelease"
2016-11-24 13:52:29 +03:00
// tests dependencies
"Build" ==> "RunTests"
2021-03-24 22:49:14 +03:00
"Build" ==> "RunTestsNetCore"
"Build" ==> "RunTestsNet"
"Build" ==> "NBench"
2016-11-24 22:27:14 +03:00
2016-11-24 13:52:29 +03:00
// nuget dependencies
2021-03-24 22:49:14 +03:00
"BuildRelease" ==> "CreateNuget"
"CreateNuget" ==> "SignPackages" ==> "PublishNuget" ==> "Nuget"
// docs
2021-03-24 22:49:14 +03:00
"BuildRelease" ==> "Docfx"
2016-11-24 13:52:29 +03:00
2017-01-24 08:46:20 +03:00
// all
2016-11-24 13:52:29 +03:00
"BuildRelease" ==> "All"
"RunTests" ==> "All"
2021-03-24 22:49:14 +03:00
"RunTestsNetCore" ==> "All"
"RunTestsNet" ==> "All"
"NBench" ==> "All"
2017-08-17 23:18:27 +03:00
"Nuget" ==> "All"
2016-11-24 13:52:29 +03:00
RunTargetOrDefault "Help"