Created
May 6, 2020 09:58
-
-
Save orient-man/0766d626b24963f5e8579725c2ec6644 to your computer and use it in GitHub Desktop.
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 PackagesPolicy | |
#r "paket: | |
nuget FSharp.Core | |
nuget Fake.Core.Process | |
nuget Fake.DotNet.Cli | |
" | |
open System.Text.RegularExpressions | |
open Fake.Core | |
open Fake.DotNet | |
let private (|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 private parseOutdated 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 private parseBeta trace (packageRegex: string) (messages: string seq) = | |
messages | |
|> Seq.choose (function Regex ".* (.*) - (.*-beta)" [package; version] -> Some (package, version) | _ -> None) | |
|> Seq.filter (fst >> function Regex packageRegex _ -> true | package -> trace package; false) | |
|> List.ofSeq | |
|> function [] -> () | any -> failwithf "Beta packages found: %A" any | |
let checkOutdated packageRegex = | |
let result = DotNet.exec (DotNet.Options.withRedirectOutput true) "paket" "outdated" | |
if result.ExitCode <> 0 then failwithf "Command failed with exit code: %d" result.ExitCode | |
parseOutdated Trace.log packageRegex result.Messages | |
let checkBeta packageRegex = | |
let result = DotNet.exec (DotNet.Options.withRedirectOutput true) "paket" "show-installed-packages" | |
if result.ExitCode <> 0 then failwithf "Command failed with exit code: %d" result.ExitCode | |
parseBeta Trace.log packageRegex result.Messages |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment