diff --git a/Build.fsx b/Build.fsx index 164f2811..069c357e 100644 --- a/Build.fsx +++ b/Build.fsx @@ -1,6 +1,7 @@ #r "paket: groupref FakeBuild //" #load "./.fake/build.fsx/intellisense.fsx" +open System.Text.RegularExpressions open Fake.IO open Fake.BuildServer open Fake.IO.Globbing.Operators @@ -15,6 +16,20 @@ BuildServer.install [ let isAppveyor = AppVeyor.detect() let gitVersion = GitVersion.generateProperties id +let replacementVersion, fullSemver = + if (Git.Information.getBranchName(Shell.pwd()) = "master") then + CreateProcess.fromRawCommandLine "node" (sprintf "%s\\npm\\node_modules\\commit-analyzer-cli\\bin\\index.js" (Environment.environVarOrFail "APPDATA")) + |> CreateProcess.redirectOutput + |> CreateProcess.map (fun t -> + Trace.log t.Result.Error + t.Result.Output.Trim() + |> function + | x when String.isNullOrWhiteSpace(x) -> None, gitVersion.FullSemVer + | x -> Some(x), x + ) + |> Proc.run + else None, gitVersion.FullSemVer + Target.create "Clean" (fun _ -> ["reports" ; "build" ; "src/common"] |> Seq.iter Directory.delete @@ -22,7 +37,7 @@ Target.create "Clean" (fun _ -> let configuration: (DotNet.Options -> DotNet.Options) = (fun t -> {t with Verbosity = Some DotNet.Verbosity.Minimal}) - + DotNet.exec configuration "clean" "SonOfPicasso.sln" |> ignore ) @@ -32,6 +47,20 @@ Target.create "Build" (fun _ -> |> Proc.run |> ignore + match replacementVersion with + | None -> () + | Some version -> + let sha = Git.Information.getCurrentSHA1(Shell.pwd()) + + Fake.IO.File.readAsString "./src/common/SharedAssemblyInfo.cs" + |> (fun t -> Regex.Replace(t, "AssemblyFileVersion\\(\"(.*?)\"\\)", sprintf "AssemblyFileVersion(\"%s.0\")" version)) + |> (fun t -> Regex.Replace(t, "AssemblyVersion\\(\"(.*?)\"\\)", sprintf "AssemblyVersion(\"%s.0\")" version)) + |> (fun t -> Regex.Replace(t, "AssemblyInformationalVersion\\(\"(.*?)\"\\)", sprintf "AssemblyInformationalVersion(\"%s+Branch.master.Sha.%s\")" version sha)) + |> Fake.IO.File.writeString false "./src/common/SharedAssemblyInfo.cs" + + if isAppveyor then + AppVeyor.updateBuild (fun t -> {t with Version = (sprintf "%s" version)}) + let configuration: (DotNet.BuildOptions -> DotNet.BuildOptions) = (fun t -> {t with Configuration = DotNet.BuildConfiguration.Release}) @@ -92,7 +121,7 @@ Target.create "TestData" (fun _ -> ) Target.create "Package" (fun _ -> - let packagePath = (sprintf "build/son-of-picasso-%s.zip" gitVersion.FullSemVer) + let packagePath = (sprintf "build/son-of-picasso-%s.zip" fullSemver) Directory.ensure "build" diff --git a/appveyor.yml b/appveyor.yml index 66aeb615..40d2583b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -7,7 +7,7 @@ install: - choco install dotnetcore-sdk --version 3.0.100-preview9-014004 --pre - choco install codecov --no-progress --confirm - choco install gitversion.portable --no-progress --confirm - - npm install -g semantic-release @semantic-release/changelog @semantic-release/git + - npm install -g semantic-release @semantic-release/changelog @semantic-release/git commit-analyzer-cli cache: - '%LOCALAPPDATA%\Temp\Chocolatey -> appveyor.yml' - '.fake -> Build.fsx' diff --git a/paket.dependencies b/paket.dependencies index 53b36ef5..da5798e2 100644 --- a/paket.dependencies +++ b/paket.dependencies @@ -12,6 +12,7 @@ group FakeBuild nuget Fake.BuildServer.AppVeyor nuget Fake.DotNet.Cli nuget Fake.IO.Zip + nuget Fake.Tools.Git nuget Fake.Tools.GitVersion groupref FakeBuildResources diff --git a/paket.lock b/paket.lock index af042d82..c7113c44 100644 --- a/paket.lock +++ b/paket.lock @@ -122,6 +122,14 @@ NUGET Fake.Core.Trace (>= 5.16.1) FSharp.Core (>= 4.7) System.Net.Http (>= 4.3.4) + Fake.Tools.Git (5.16.1) + Fake.Core.Environment (>= 5.16.1) + Fake.Core.Process (>= 5.16.1) + Fake.Core.SemVer (>= 5.16.1) + Fake.Core.String (>= 5.16.1) + Fake.Core.Trace (>= 5.16.1) + Fake.IO.FileSystem (>= 5.16.1) + FSharp.Core (>= 4.7) Fake.Tools.GitVersion (5.16.1) Fake.Core.Environment (>= 5.16.1) Fake.Core.Process (>= 5.16.1)