Skip to content

Instantly share code, notes, and snippets.

@orient-man
Last active April 30, 2020 20:34
Show Gist options
  • Save orient-man/33dc672aeb4eed5767b3a80de93d5045 to your computer and use it in GitHub Desktop.
Save orient-man/33dc672aeb4eed5767b3a80de93d5045 to your computer and use it in GitHub Desktop.
Check exit code!
module OutdatedPackages
#r "paket:
nuget FSharp.Core
nuget Fake.Core.Process
"
open Fake.Core
open System.Text.RegularExpressions
let (|Regex|_|) pattern input =
let m = Regex.Match(input, pattern)
if m.Success then Some (List.tail [ for g in m.Groups -> g.Value ])
else None
let parse trace (packageRegex: string) (messages: string seq) =
messages
|> Seq.fold (fun finished line ->
match finished, line.Trim() with
| (false, list), Regex "^Outdated packages found:$" _ -> true, list
| (true, list), Regex "^Performance:$" _ -> false, list
| (true, list), Regex "^\s*\* (.*)$" [line] -> true, line :: list
| state, _ -> state) (false, [])
|> snd
|> List.rev
|> List.filter (function Regex packageRegex _ -> true | package -> trace package; false)
|> function [] -> () | any -> failwithf "Outdated packages found: %A" any
let parseResult packageRegex (result: ProcessResult) =
if result.ExitCode <> 0 then failwithf "Command failed with exit code: %d" result.ExitCode
parse Trace.log packageRegex result.Messages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment