Last active
March 17, 2020 14:09
-
-
Save Karamell/0b3e5bb249b0bb4d158fea2676290a79 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // paket outdated / update -> git commit | |
| open System | |
| open System.Diagnostics | |
| open System.IO | |
| open System.Threading | |
| let info format = | |
| printf "%s " (DateTime.Now.ToString("g")) | |
| printfn format | |
| let run filename arg = | |
| let p = new ProcessStartInfo() | |
| p.Arguments <- arg | |
| p.FileName <- filename | |
| p.RedirectStandardOutput <- true | |
| p.UseShellExecute <- false | |
| info "kjøyr %s" arg | |
| p |> Process.Start | |
| let dotnet arg = | |
| run "dotnet" arg | |
| let waitForProcess proc = | |
| let rec pwait (p:Process) lines = | |
| if (p.HasExited || p.StandardOutput.EndOfStream) |> not then | |
| let mutable l = [] | |
| while p.StandardOutput.EndOfStream |> not do | |
| let s = p.StandardOutput.ReadLine() | |
| l <- l @ [s] | |
| s |> printfn "%s" | |
| Thread.Sleep 50 | |
| pwait p lines @ l | |
| else | |
| lines | |
| let r = pwait proc [] | |
| proc.WaitForExit() | |
| r | |
| let outdated = | |
| dotnet "paket outdated" | |
| |> waitForProcess | |
| |> List.skipWhile(fun l -> l <> "Outdated packages found:") | |
| |> List.takeWhile(fun l -> l <> "Performance:") | |
| |> List.map(fun s -> s.Trim()) | |
| let kjørOppdatering() = | |
| let msg = Path.GetTempFileName() | |
| let headline = DateTime.Now.ToString() |> sprintf "Oppdateringer %s" | |
| File.WriteAllLines(msg, headline :: (outdated |> List.skip 1)) | |
| info "Wrote %d lines to '%s'." outdated.Length msg | |
| dotnet "paket update" |> waitForProcess |> ignore | |
| info "Lag git greier" | |
| sprintf "commit -a -F %s" msg | |
| |> run "git" | |
| |> waitForProcess | |
| |> ignore | |
| if outdated |> List.isEmpty then | |
| info "Ingenting å oppdatere!" | |
| else | |
| kjørOppdatering() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment