Skip to content

Commit

Permalink
Add GitVersionHelper (take 2)
Browse files Browse the repository at this point in the history
  • Loading branch information
trondd committed Jul 21, 2016
1 parent f4024fd commit 72338b2
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/app/FakeLib/FakeLib.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@
<Compile Include="SonarQubeHelper.fs" />
<Compile Include="AzureKudu.fs" />
<Compile Include="DocFxHelper.fs" />
<Compile Include="GitVersionHelper.fs" />
</ItemGroup>
<ItemGroup>
<Reference Include="ICSharpCode.SharpZipLib">
Expand Down Expand Up @@ -505,4 +506,4 @@
</ItemGroup>
</When>
</Choose>
</Project>
</Project>
50 changes: 50 additions & 0 deletions src/app/FakeLib/GitVersionHelper.fs
Original file line number Diff line number Diff line change
@@ -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<GitVersionProperties>(j)
| None -> failwithf "%s is not installed. %s" file usage

0 comments on commit 72338b2

Please sign in to comment.