Skip to content

Commit

Permalink
Fix CI cancellation issues
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAngryByrd committed Jan 31, 2024
1 parent f6fd013 commit aef49b7
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 deletions build/build.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,30 @@ open System.IO
open Fake.BuildServer
open FsToolkit.Build

let environVarAsBoolOrDefault varName defaultValue =
let truthyConsts = [
"1"
"Y"
"YES"
"T"
"TRUE"
]

try
let envvar = (Environment.environVar varName).ToUpper()

truthyConsts
|> List.exists ((=) envvar)
with _ ->
defaultValue

let project = "FsToolkit.ErrorHandling"

let summary =
"FsToolkit.ErrorHandling is a utility library to work with the Result type in F#, and allows you to do clear, simple and powerful error handling."

let isCI = lazy (environVarAsBoolOrDefault "CI" false)

let isRelease (targets: Target list) =
targets
|> Seq.map (fun t -> t.Name)
Expand Down Expand Up @@ -93,6 +112,18 @@ let failOnBadExitAndPrint (p: ProcessResult) =

failwithf "failed with exitcode %d" p.ExitCode

// github actions are terrible and will cancel runner operations if using too much CPU
// https://github.com/actions/runner-images/discussions/7188#discussioncomment-6672934
let maxCpuCount = lazy (if isCI.Value then Some(Some 2) else None)

/// MaxCpu not used on unix https://github.com/fsprojects/FAKE/blob/82e38df01e4b31e5daa3623abff57e6462430395/src/app/Fake.DotNet.MSBuild/MSBuild.fs#L858-L861
let maxCpuMsBuild =
lazy
(match maxCpuCount.Value with
| None -> ""
| Some None -> "/m"
| Some(Some x) -> $"/m:%d{x}")

module dotnet =
let watch cmdParam program args =
DotNet.exec cmdParam (sprintf "watch %s" program) args
Expand Down Expand Up @@ -144,10 +175,16 @@ let clean _ =


let build ctx =
let setParams (defaults: DotNet.BuildOptions) = {
defaults with

let args = [ maxCpuMsBuild.Value ]

let setParams (c: DotNet.BuildOptions) = {
c with
NoRestore = true
Configuration = (configuration ctx.Context.AllExecutingTargets)
Common =
c.Common
|> DotNet.Options.withAdditionalArgs args
}

DotNet.build setParams solutionFile
Expand All @@ -166,7 +203,10 @@ let npmRestore _ = Npm.install id

let dotnetTest ctx =

let args = [ "--no-build" ]
let args = [
"--no-build"
maxCpuMsBuild.Value
]

DotNet.test
(fun c ->
Expand Down

0 comments on commit aef49b7

Please sign in to comment.