From 72338b27867c9d0fb9f6bbab3cfdef6fe9d07b39 Mon Sep 17 00:00:00 2001 From: Trond Danielsen Date: Thu, 21 Jul 2016 14:22:54 +0200 Subject: [PATCH] Add GitVersionHelper (take 2) --- src/app/FakeLib/FakeLib.fsproj | 3 +- src/app/FakeLib/GitVersionHelper.fs | 50 +++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/app/FakeLib/GitVersionHelper.fs diff --git a/src/app/FakeLib/FakeLib.fsproj b/src/app/FakeLib/FakeLib.fsproj index 3c51013273d..5bca892ba9c 100644 --- a/src/app/FakeLib/FakeLib.fsproj +++ b/src/app/FakeLib/FakeLib.fsproj @@ -186,6 +186,7 @@ + @@ -505,4 +506,4 @@ - \ No newline at end of file + diff --git a/src/app/FakeLib/GitVersionHelper.fs b/src/app/FakeLib/GitVersionHelper.fs new file mode 100644 index 00000000000..7f591a2d1ab --- /dev/null +++ b/src/app/FakeLib/GitVersionHelper.fs @@ -0,0 +1,50 @@ +module Fake.GitVersionHelper + +open FSharp.Data +open Newtonsoft.Json +open System + +type GitVersionProperties = { + Major : int; + Minor : int; + Patch : int; + PreReleaseTag : string; + PreReleaseTagWithDash : string; + PreReleaseLabel : string; + PreReleaseNumber : int; + BuildMetaData : string; + BuildMetaDataPadded : string; + FullBuildMetaData : string; + MajorMinorPatch : string; + SemVer : string; + LegacySemVer : string; + LegacySemVerPadded : string; + AssemblySemVer : string; + FullSemVer : string; + InformationalVersion : string; + BranchName : string; + Sha : string; + NuGetVersionV2 : string; + NuGetVersion : string; + CommitsSinceVersionSource : int; + CommitsSinceVersionSourcePadded : string; + CommitDate : string; + } + + +let GitVersion () = + let dirs = [ (environVar "ProgramData") @@ "chocolatey" @@ "bin" ] + let file = "GitVersion.exe" + let timespan = TimeSpan.FromMinutes 1. + let usage = "To install GitVersion.exe, start PowerShell as Administrator and run choco install gitversion.portable -s https://chocolatey.org/api/v2" + + let run executable = + let result = ExecProcessAndReturnMessages (fun info -> + info.FileName <- executable ) timespan + if result.ExitCode <> 0 then failwithf "%s failed with exit code %i" executable result.ExitCode + result.Messages |> String.concat "" + + + match tryFindFile dirs file with + | Some executable -> run executable |> fun j -> JsonConvert.DeserializeObject(j) + | None -> failwithf "%s is not installed. %s" file usage