Skip to content

Commit

Permalink
update build script, use Fake 5
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianAuinger committed Feb 1, 2021
1 parent 995900c commit 341e06d
Show file tree
Hide file tree
Showing 3 changed files with 331 additions and 70 deletions.
5 changes: 1 addition & 4 deletions build.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
REM If GitVersion is not available then run
REM cinst GitVersion.Portable
REM to install it
GitVersion.exe /output buildserver /exec scripts\lib\FAKE\tools\Fake.exe /execArgs "scripts\build.fsx %1 %2 %3 %4 %5 %6 %7 %8 %9 " /l console
dotnet fake run .\scripts\build.fsx
161 changes: 95 additions & 66 deletions scripts/build.fsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,44 @@
#I @"lib"
#r @"Fake\tools\FakeLib.dll"

open Fake
open Fake.MSBuildHelper
open Fake.Testing
open Fake.DotNetCli

let nugetApiKey = getBuildParam "NuGetApiKey"
let outputPath = @".\artifacts" |> FullName
let buildOutputPath = @"bin\Release"

Target "Clean" (fun _ ->
CleanDir outputPath
)


Target "BuildSolution" (fun () ->

//RestoreMSSolutionPackages (fun p->p) "Weingartner.Json.Migration.sln"

let slnPath = @".\Weingartner.Json.Migration.sln"
let setParams defaults = {
#r "paket:
nuget FSharp.Core 4.7.2
nuget Fake.Core.Target
nuget Fake.IO.FileSystem
nuget Fake.DotNet.Cli
nuget Fake.DotNet.MSBuild
nuget Fake.DotNet.NuGet
nuget Fake.Tools.GitVersion //"
#load @".\.fake\build.fsx\intellisense.fsx"

open System.IO
open Fake.Core
open Fake.Core.TargetOperators
open Fake.DotNet
open Fake.IO.Globbing.Operators
open Fake.IO.FileSystemOperators
open Fake.DotNet.NuGet

Target.initEnvironment()

// Properties
let baseDir = __SOURCE_DIRECTORY__ @@ ".."
let buildOutputPath = @".\bin\Release"
let artifactPath = baseDir @@ "artifacts"
let slnPath = @".\Weingartner.Json.Migration.sln"
let nugetVersion = if BuildServer.isLocalBuild
then (
let gitVersion = Fake.Tools.GitVersion.generateProperties (fun paras -> {
paras with
ToolPath = Environment.environVarOrFail "ChocolateyInstall" @@ @"lib\GitVersion.Portable\tools\gitversion.exe"
})
gitVersion.SemVer
)
else BuildServer.buildVersion

let msbuild target = (
let setParams (defaults:MSBuildParams) = {
defaults with
Targets = [ "Rebuild" ]
Verbosity = Some(MSBuildVerbosity.Minimal)
ToolsVersion = (Some "Current")
Targets = [ target ]
Properties =
[
"Optimize", "True"
Expand All @@ -33,78 +49,91 @@ Target "BuildSolution" (fun () ->
"DebugSymbols", "True"
"OutputPath", buildOutputPath
]
Verbosity = Some(MSBuildVerbosity.Normal)
NodeReuse = false
}
build setParams slnPath
MSBuild.build setParams slnPath
)

Target "RunTests" (fun () ->

let projects = !! @"**\*.Spec.csproj"
for project in projects do
let setParams (p: TestParams) = { p with Project = project }
(DotNetCli.Test setParams)
// Targets
Target.create "Clean" (fun _ ->
Trace.trace "########################################### clean outputdir ###########################################"
Fake.IO.Shell.cleanDir buildOutputPath
Fake.IO.Shell.cleanDir artifactPath
)

let nugetVersion = if buildVersion = "LocalBuild" then ( environVarOrFail "GitVersion_SemVer" ) else buildVersion
Target.create "BuildSolution" (fun _ ->
Trace.trace "########################################### msbuild restore ###########################################"
msbuild "restore"
Trace.trace "########################################### msbuild rebuild ###########################################"
msbuild "rebuild"
)

Target "NugetMigration" (fun()->
let dotnet cmd workingDir =
let result = DotNet.exec (DotNet.Options.withWorkingDirectory workingDir) cmd ""
if result.ExitCode <> 0 then failwithf "'dotnet %s' failed in %s" cmd workingDir

let buildDir = "Weingartner.Json.Migration" @@ buildOutputPath
Target.create "RunTests" (fun _ ->
Trace.trace "########################################### run tests ###########################################"
!! @"**\*.Spec.csproj"
|> Seq.map Fake.IO.Path.getDirectory
|> Seq.iter (fun dir -> dotnet "test" dir)
)

NuGet (fun p ->
{p with
Authors = ["Weingartner Maschinenbau GmbH"]
Project = "Weingartner.Json.Migration"
Description = "Assists in migrating serialized JSON.Net objects"
OutputPath = "./artifacts"
Dependencies =
[ "Newtonsoft.Json", "12.0.3"]
Files = [ ("Weingartner*.dll", Some "lib/netstandard2.0", None )]
Summary = "Assists in migrating serialized JSON.Net objects"
Version = nugetVersion
WorkingDir = buildDir
AccessKey = nugetApiKey
Publish = false })
Target.create "PackNugetMigration" (fun _ ->

let workingDir = @".\Weingartner.Json.Migration" @@ buildOutputPath
NuGet.NuGetPack (fun p -> {
p with
Authors = ["Weingartner Maschinenbau GmbH"]
Project = "Weingartner.Json.Migration"
Description = "Assists in migrating serialized JSON.Net objects"
OutputPath = artifactPath
Dependencies = [ "Newtonsoft.Json", "12.0.3" ]
Files = [ ("Weingartner*.dll", Some("lib/netstandard2.0"), None )]
Summary = "Assists in migrating serialized JSON.Net objects"
Version = nugetVersion
WorkingDir = workingDir
Publish = false
})
"./base.nuspec"
)

Target "NugetAnalyzer" (fun()->
Target.create "PackNugetAnalyzer" (fun _ ->

let buildDir = "Weingartner.Json.Migration.Roslyn" @@ buildOutputPath
let workingDir = @".\Weingartner.Json.Migration.Roslyn" @@ buildOutputPath

NuGet (fun p ->
NuGet.NuGetPack (fun p ->
{p with
Authors = ["Weingartner Maschinenbau GMBH"]
Project = "Weingartner.Json.Migration.Analyzer"
Description = "Assists in migrating serialized JSON.Net objects"
OutputPath = "./artifacts"
OutputPath = artifactPath
Dependencies =
[ "Weingartner.Json.Migration", nugetVersion
"Newtonsoft.Json", "12.0.3"
]
Summary = "Assists in migrating serialized JSON.Net objects"
Version = nugetVersion
AccessKey = nugetApiKey
WorkingDir = buildDir
WorkingDir = workingDir
Files = [ ( "Weingartner.Json.Migration.Roslyn.dll", Some "analyzers/dotnet/cs", Some "**/Microsoft.*;**/System.*")
( "tools/**/*.*", None, None)
]
Publish = false })
Publish = false
})
"./base.nuspec"
)

Target "NugetPack" DoNothing
Target "Default" DoNothing

"NugetMigration" <== [ "BuildSolution" ]
"NugetAnalyzer" <== [ "BuildSolution" ]
"NugetPack" <== [ "NugetMigration"; "NugetAnalyzer" ]
"NugetPack" <== [ "BuildSolution" ]
"RunTests" <== [ "BuildSolution" ]
Target.create "Default" (fun _ ->
Trace.trace "Finished"
)

"Default" <== [ "Clean"; "NugetPack"; "RunTests" ]

// Dependencies
"Clean"
==> "BuildSolution"
==> "RunTests"
==> "PackNugetMigration"
==> "PackNugetAnalyzer"
==> "Default"

RunTargetOrDefault "Default"
Target.runOrDefault "Default"
Loading

0 comments on commit 341e06d

Please sign in to comment.