Create preview NuGet version using FAKE and Mercurial branch names
Create preview versions of NuGet packages is a very useful thing when multiple projects depends on it. If your are using FAKE to script your builds, you can increment automatically your NuGets versions. see
I recently modified a build script to automate alpha or beta NuGet versionning with a small module:
open Fake
open System
open System.Text.RegularExpressions
module Mercurial =
type BranchInfo =
| Default
| Pre of name:string
let getBranch () =
let (|PrevName|_|) (s:string) =
let regex = new Regex("^(alpha|beta)\d*$")
if regex.IsMatch s
then Some s
else None
let (|Branch|_|) = function
| [{IsError=_;Message="default";Timestamp=_}] -> Some Default
| [{IsError=_;Message=(PrevName name);Timestamp=_}] -> Some (Pre name)
| _ -> None
let success,result =
ExecProcessRedirected
(fun info ->
info.FileName <- "hg"
info.Arguments <- "branch"
info.WorkingDirectory <- __SOURCE_DIRECTORY__)
(TimeSpan.FromSeconds 2.)
match success, (List.ofSeq result) with
| true, Branch branch -> branch
| _ -> Default
Mercurial.getBranch()
So, when the branch name is like “alpha”, “beta”, “alpha1”, “beta10”, etc … I can concat it with the next NuGet version number.
let nugetsVersions name =
let v =
NuGetVersion.nextVersion <|
fun arg ->
{ arg
with
PackageName=name
DefaultVersion="0.1.0"
Increment=NuGetVersion.IncPatch
Server=(nugetPublishUrl + "api/v2")
}
match Mercurial.getBranch() with
| Mercurial.BranchInfo.Default -> v
| Mercurial.BranchInfo.Pre name -> sprintf "%s-%s" v name
nugetsVersions "scrapysharp"
// val version : string = "1.0.1-alpha"
100%