Last active
April 30, 2020 20:34
-
-
Save orient-man/33dc672aeb4eed5767b3a80de93d5045 to your computer and use it in GitHub Desktop.
Check exit code!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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