Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - Converted GitVersionHelper to FAKE 5 module #1988

Merged
merged 5 commits into from
Jun 9, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Fake.sln
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fake.DotNet.Mage", "src/app
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fake.Tools.Pickles", "src/app/Fake.Tools.Pickles/Fake.Tools.Pickles.fsproj", "{2EC1798B-3AD5-42FE-9406-F358B995ACC3}"
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fake.Tools.GitVersion", "src/app/Fake.Tools.GitVersion/Fake.Tools.GitVersion.fsproj", "{2EC1798B-3AD5-42FE-9406-F358B995ACC3}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Files", "Solution Files", "{03CB61B6-EBB8-4C4A-B6A3-0D84D1F78A92}"
ProjectSection(SolutionItems) = preProject
.gitlab-ci.yml = .gitlab-ci.yml
Expand Down
1 change: 1 addition & 0 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ let dotnetAssemblyInfos =
"Fake.Testing.SonarQube", "Analyzing your project with SonarQube"
"Fake.Tools.Git", "Running git commands"
"Fake.Tools.Pickles", "Convert Gherkin to HTML"
"Fake.Tools.GitVersion", "GitVersion helper"
"Fake.Tracing.NAntXml", "NAntXml"
"Fake.Windows.Chocolatey", "Running and packaging with Chocolatey"
"Fake.Windows.Registry", "CRUD functionality for Windows registry" ]
Expand Down
17 changes: 17 additions & 0 deletions src/app/Fake.Tools.GitVersion/AssemblyInfo.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Auto-Generated by FAKE; do not edit
namespace System
open System.Reflection

[<assembly: AssemblyTitleAttribute("FAKE - F# Make GitVersion")>]
[<assembly: AssemblyProductAttribute("FAKE - F# Make")>]
[<assembly: AssemblyVersionAttribute("5.0.0")>]
[<assembly: AssemblyInformationalVersionAttribute("5.0.0")>]
[<assembly: AssemblyFileVersionAttribute("5.0.0")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "FAKE - F# Make GitVersion"
let [<Literal>] AssemblyProduct = "FAKE - F# Make"
let [<Literal>] AssemblyVersion = "5.0.0"
let [<Literal>] AssemblyInformationalVersion = "5.0.0"
let [<Literal>] AssemblyFileVersion = "5.0.0"
24 changes: 24 additions & 0 deletions src/app/Fake.Tools.GitVersion/Fake.Tools.GitVersion.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TargetFrameworks>net46;netstandard1.6;netstandard2.0</TargetFrameworks>
<DefineConstants>$(DefineConstants);NO_DOTNETCORE_BOOTSTRAP</DefineConstants>
<AssemblyName>Fake.Tools.GitVersion</AssemblyName>
<OutputType>Library</OutputType>
</PropertyGroup>
<PropertyGroup>
<DefineConstants>$(DefineConstants);NETSTANDARD</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.fs" />
<Compile Include="GitVersion.fs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Fake.Core.Environment\Fake.Core.Environment.fsproj" />
<ProjectReference Include="..\Fake.Core.Process\Fake.Core.Process.fsproj" />
<ProjectReference Include="..\Fake.IO.FileSystem\Fake.IO.FileSystem.fsproj" />
</ItemGroup>
<Import Project="..\..\..\.paket\Paket.Restore.targets" />
</Project>
62 changes: 62 additions & 0 deletions src/app/Fake.Tools.GitVersion/GitVersion.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
[<RequireQualifiedAccess>]
module Fake.Tools.GitVersion

open Newtonsoft.Json
open System
open System.IO
open Fake.IO.Globbing
open Fake.Core

[<CLIMutable>]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the CLIMutable.

type GitversionParams = {
ToolPath : string
}

let GitversionDefaults = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably make this private (or internal)

ToolPath = Tools.findToolInSubPath "GitVersion.exe" (Environment.environVarOrDefault "ChocolateyInstall" (Directory.GetCurrentDirectory()))
}

type GitVersionProperties = {
Major : int;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change the formatting to be less intended and remove the ;?

Minor : int;
Patch : int;
PreReleaseTag : string;
PreReleaseTagWithDash : string;
PreReleaseLabel : string;
PreReleaseNumber : Nullable<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
///
/// generateProperties id // Use Defaults
/// generateProperties (fun p -> { p with ToolPath = "/path/to/directory" }
let generateProperties (setParams : GitversionParams -> GitversionParams) =
let parameters = GitversionDefaults |> setParams
let timespan = TimeSpan.FromMinutes 1.

let result = Process.execWithResult (fun info ->
{info with FileName = parameters.ToolPath} ) timespan
if result.ExitCode <> 0 then failwithf "GitVersion.exe failed with exit code %i and message %s" result.ExitCode (String.concat "" result.Messages)
result.Messages |> String.concat "" |> fun j -> JsonConvert.DeserializeObject<GitVersionProperties>(j)
1 change: 1 addition & 0 deletions src/app/Fake.Tools.GitVersion/paket.references
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Newtonsoft.Json
3 changes: 3 additions & 0 deletions src/legacy/FakeLib/FakeLib.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,9 @@
<Compile Include="..\..\app\Fake.Tools.Git\Commit.fs">
<Link>Fake.Tools.Git/Commit.fs</Link>
</Compile>
<Compile Include="..\..\app\Fake.Tools.GitVersion\GitVersion.fs">
<Link>Fake.Tools.GitVersion/GitVersion.fs</Link>
</Compile>
<Compile Include="..\..\app\Fake.Testing.SonarQube\SonarQube.fs">
<Link>Fake.Testing.SonarQube/SonarQube.fs</Link>
</Compile>
Expand Down
10 changes: 5 additions & 5 deletions src/legacy/FakeLib/GitVersionHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
/// 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.

[<System.Obsolete("This API is obsolete. There is no alternative in FAKE 5 yet. You can help by porting this module.")>]
[<System.Obsolete("FAKE0001 Use the Fake.Tools.GitVersion module instead")>]
module Fake.GitVersionHelper

open FSharp.Data
open Newtonsoft.Json
open System

[<CLIMutable>]
[<System.Obsolete("This API is obsolete. There is no alternative in FAKE 5 yet. You can help by porting this module.")>]
[<System.Obsolete("FAKE0001 Use the Fake.Tools.GitVersion module instead")>]
type GitversionParams = {
ToolPath : string
}

[<System.Obsolete("This API is obsolete. There is no alternative in FAKE 5 yet. You can help by porting this module.")>]
[<System.Obsolete("FAKE0001 Use the Fake.Tools.GitVersion module instead")>]
let GitversionDefaults = {
ToolPath = findToolInSubPath "GitVersion.exe" (environVarOrDefault "ChocolateyInstall" currentDirectory)
}

[<System.Obsolete("This API is obsolete. There is no alternative in FAKE 5 yet. You can help by porting this module.")>]
[<System.Obsolete("FAKE0001 Use the Fake.Tools.GitVersion module instead")>]
type GitVersionProperties = {
Major : int;
Minor : int;
Expand Down Expand Up @@ -58,7 +58,7 @@ type GitVersionProperties = {
///
/// GitVersion id // Use Defaults
/// GitVersion (fun p -> { p with ToolPath = currentDirectory @@ "tools" }
[<System.Obsolete("This API is obsolete. There is no alternative in FAKE 5 yet. You can help by porting this module.")>]
[<System.Obsolete("FAKE0001 Use the Fake.Tools.GitVersion module instead. Function GitVersion.generateProperties")>]
let GitVersion (setParams : GitversionParams -> GitversionParams) =
let parameters = GitversionDefaults |> setParams
let timespan = TimeSpan.FromMinutes 1.
Expand Down