Skip to content

Commit

Permalink
Merge pull request #1319 from trondd/master
Browse files Browse the repository at this point in the history
Add GitVersionHelper (take 2)
  • Loading branch information
forki authored Aug 9, 2016
2 parents 06092e9 + 892c756 commit ca4b512
Show file tree
Hide file tree
Showing 2 changed files with 65 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 @@ -187,6 +187,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 @@ -506,4 +507,4 @@
</ItemGroup>
</When>
</Choose>
</Project>
</Project>
63 changes: 63 additions & 0 deletions src/app/FakeLib/GitVersionHelper.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/// Containts helper function for GitVersion - a tool to help you achieve Semantic Versioning on your project.
///
/// To install GitVersion.exe on Windows, start PowerShell as Administrator and run choco install gitversion.portable -s https://chocolatey.org/api/v2"
/// For Mac and Unix, install the NuGet version.
module Fake.GitVersionHelper

open FSharp.Data
open Newtonsoft.Json
open System

type GitversionParams = {
ToolPath : string
}

let GitversionDefaults = {
ToolPath = findToolInSubPath "GitVersion.exe" (environVarOrDefault "ChocolateyInstall" currentDirectory)
}

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;
}

/// Runs [GitVersion](https://gitversion.readthedocs.io/en/latest/) on a .NET project file.
/// ## Parameters
///
/// - `setParams` - Function used to manipulate the GitversionDefaults value.
///
/// ## Sample
///
/// GitVersion id // Use Defaults
/// GitVersion (fun p -> { p with ToolPath = currentDirectory @@ "tools" }
let GitVersion (setParams : GitversionParams -> GitversionParams) =
let parameters = GitversionDefaults |> setParams
let timespan = TimeSpan.FromMinutes 1.

let result = ExecProcessAndReturnMessages (fun info ->
info.FileName <- parameters.ToolPath) timespan
if result.ExitCode <> 0 then failwithf "GitVersion.exe failed with exit code %i" result.ExitCode
result.Messages |> String.concat "" |> fun j -> JsonConvert.DeserializeObject<GitVersionProperties>(j)

0 comments on commit ca4b512

Please sign in to comment.