From 72338b27867c9d0fb9f6bbab3cfdef6fe9d07b39 Mon Sep 17 00:00:00 2001 From: Trond Danielsen Date: Thu, 21 Jul 2016 14:22:54 +0200 Subject: [PATCH 1/2] 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 From 892c756a9212c9b768bbd0083869025aaa4238c9 Mon Sep 17 00:00:00 2001 From: Trond Danielsen Date: Wed, 3 Aug 2016 07:11:25 +0200 Subject: [PATCH 2/2] Expand tool search path and add documentation --- src/app/FakeLib/GitVersionHelper.fs | 43 +++++++++++++++++++---------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/src/app/FakeLib/GitVersionHelper.fs b/src/app/FakeLib/GitVersionHelper.fs index 7f591a2d1ab..97ed1e7b838 100644 --- a/src/app/FakeLib/GitVersionHelper.fs +++ b/src/app/FakeLib/GitVersionHelper.fs @@ -1,9 +1,22 @@ +/// 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; @@ -31,20 +44,20 @@ type GitVersionProperties = { CommitDate : string; } - -let GitVersion () = - let dirs = [ (environVar "ProgramData") @@ "chocolatey" @@ "bin" ] - let file = "GitVersion.exe" +/// 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 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 + 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(j)