<commit_before>/// Helpers for FAKE scripts for the standard WebSharper extensions.
/// Check the sources for usage.
(**
Uses the following environment variables (some of which are overridden by WSTargets options):
  * BUILD_NUMBER: the build number to use (last component of the version).
    Automatically set by Jenkins.
  * BuildBranch: the name of the branch to switch to before building, and to push to on success.
    Default: current branch
  * PushRemote: the name of the git or hg remote to push to
    Default: origin
  * NuGetPublishUrl: the URL of the NuGet server
    Default: https://nuget.intellifactory.com/nuget
  * NugetApiKey: the API key of the NuGet server.

Versioning policy (as implemented in ComputeVersion):
  * Major, minor and pre are taken from baseVersion.
  * Patch is set based on the latest tag:
    * If the tag's major/minor is different from baseVersion, then patch = 0.
    * If the major/minor is the same and the latest tag is on HEAD, then this is a rebuild
      of the same code: use the tag's patch number (they will be differenciated by ther Build).
    * Otherwise, increment from the tag's patch number.
  * Build is set to $(BUILD_NUMBER) if that is defined, baseVersion.Build + 1 otherwise.
*)
module WebSharper.Fake

#nowarn "211" // Don't warn about nonexistent #I
#nowarn "20"  // Ignore string result of ==>
#I "../packages/build/FAKE/tools"
#I "../../../../../packages/build/FAKE/tools"
#I "../packages/build/Paket.Core/lib/net45"
#I "../packages/build/Chessie/lib/net40"
#I "../../../../../packages/build/Paket.Core/lib/net45"
#I "../../../../../packages/build/Chessie/lib/net40"
#r "Chessie"
#r "Paket.Core"
#r "FakeLib"
#nowarn "49"

open System
open System.IO
open System.Text.RegularExpressions
open Fake
open Fake.AssemblyInfoFile

let private depsFile = Paket.DependenciesFile.ReadFromFile "./paket.dependencies"

let private mainGroupName = Paket.Domain.GroupName "Main"
let private mainGroup = depsFile.GetGroup mainGroupName

let GetSemVerOf pkgName =
    match Paket.PackageResolver.GetPackageVersionsParameters.ofParams
            mainGroup.Sources mainGroupName (Paket.Domain.PackageName pkgName)
        |> Paket.NuGet.GetVersions true None "."
        |> Async.RunSynchronously
        |> List.map fst with
    | [] -> None
    | l -> Some (List.max l)

let shell program cmd =
    Printf.kprintf (fun cmd ->
        shellExec {
            Program = program
            WorkingDirectory = "."
            CommandLine = cmd
            Args = []
        }
        |> function
            | 0 -> ()
            | n -> failwithf "%s %s failed with code %i" program cmd n
    ) cmd

let shellOut program cmd =
    Printf.kprintf (fun cmd ->
        let psi =
            System.Diagnostics.ProcessStartInfo(
                FileName = program,
                Arguments = cmd,
                RedirectStandardOutput = true,
                UseShellExecute = false
            )
        let proc = System.Diagnostics.Process.Start(psi)
        let out = proc.StandardOutput.ReadToEnd()
        proc.WaitForExit()
        match proc.ExitCode with
        | 0 -> out
        | n -> failwithf "%s %s failed with code %i" program cmd n
    ) cmd

let git cmd =
    Printf.kprintf (fun s ->
        logfn "> git %s" s
        Git.CommandHelper.directRunGitCommandAndFail "." s
    ) cmd

let hg cmd = shell "hg" cmd
let hg' cmd = shellOut "hg" cmd

let private splitLines (s: string) =
    s.Split([| "\r\n"; "\n" |], StringSplitOptions.None)

module Hg =
    let getBookmarks() =
        hg' """bookmark -T "{bookmark} {node|short}\n" """
        |> splitLines
        |> Array.map (fun s -> s.Split(' ').[0])

    let getCurrentCommitId() =
        (hg' "id -i").Trim()

    let commitIdForBookmark (b: string) =
        hg' """bookmark -T "{bookmark} {node|short}\n" """
        |> splitLines
        |> Array.pick (fun s ->
            let a = s.Split(' ')
            if a.[0] = b then Some a.[1] else None
        )

    let branchExists (b: string) =
        hg' "branches -T {branch}"
        |> splitLines
        |> Array.contains b

    let isAncestorOfCurrent (ref: string) =
        let currentRef = getCurrentCommitId()
        let o = hg' """log --rev "ancestors(.) and %s" """ ref
        not (String.IsNullOrWhiteSpace o)

module VC =
    let isGit = Directory.Exists ".git"

    let getTags() =
        if isGit then
            let ok, out, err = Git.CommandHelper.runGitCommand "." "tag --merged"<commit_msg>[CI] Build script: fix getting hg branches<commit_after>/// Helpers for FAKE scripts for the standard WebSharper extensions.
/// Check the sources for usage.
(**
Uses the following environment variables (some of which are overridden by WSTargets options):
  * BUILD_NUMBER: the build number to use (last component of the version).
    Automatically set by Jenkins.
  * BuildBranch: the name of the branch to switch to before building, and to push to on success.
    Default: current branch
  * PushRemote: the name of the git or hg remote to push to
    Default: origin
  * NuGetPublishUrl: the URL of the NuGet server
    Default: https://nuget.intellifactory.com/nuget
  * NugetApiKey: the API key of the NuGet server.

Versioning policy (as implemented in ComputeVersion):
  * Major, minor and pre are taken from baseVersion.
  * Patch is set based on the latest tag:
    * If the tag's major/minor is different from baseVersion, then patch = 0.
    * If the major/minor is the same and the latest tag is on HEAD, then this is a rebuild
      of the same code: use the tag's patch number (they will be differenciated by ther Build).
    * Otherwise, increment from the tag's patch number.
  * Build is set to $(BUILD_NUMBER) if that is defined, baseVersion.Build + 1 otherwise.
*)
module WebSharper.Fake

#nowarn "211" // Don't warn about nonexistent #I
#nowarn "20"  // Ignore string result of ==>
#I "../packages/build/FAKE/tools"
#I "../../../../../packages/build/FAKE/tools"
#I "../packages/build/Paket.Core/lib/net45"
#I "../packages/build/Chessie/lib/net40"
#I "../../../../../packages/build/Paket.Core/lib/net45"
#I "../../../../../packages/build/Chessie/lib/net40"
#r "Chessie"
#r "Paket.Core"
#r "FakeLib"
#nowarn "49"

open System
open System.IO
open System.Text.RegularExpressions
open Fake
open Fake.AssemblyInfoFile

let private depsFile = Paket.DependenciesFile.ReadFromFile "./paket.dependencies"

let private mainGroupName = Paket.Domain.GroupName "Main"
let private mainGroup = depsFile.GetGroup mainGroupName

let GetSemVerOf pkgName =
    match Paket.PackageResolver.GetPackageVersionsParameters.ofParams
            mainGroup.Sources mainGroupName (Paket.Domain.PackageName pkgName)
        |> Paket.NuGet.GetVersions true None "."
        |> Async.RunSynchronously
        |> List.map fst with
    | [] -> None
    | l -> Some (List.max l)

let shell program cmd =
    Printf.kprintf (fun cmd ->
        shellExec {
            Program = program
            WorkingDirectory = "."
            CommandLine = cmd
            Args = []
        }
        |> function
            | 0 -> ()
            | n -> failwithf "%s %s failed with code %i" program cmd n
    ) cmd

let shellOut program cmd =
    Printf.kprintf (fun cmd ->
        let psi =
            System.Diagnostics.ProcessStartInfo(
                FileName = program,
                Arguments = cmd,
                RedirectStandardOutput = true,
                UseShellExecute = false
            )
        let proc = System.Diagnostics.Process.Start(psi)
        let out = proc.StandardOutput.ReadToEnd()
        proc.WaitForExit()
        match proc.ExitCode with
        | 0 -> out
        | n -> failwithf "%s %s failed with code %i" program cmd n
    ) cmd

let git cmd =
    Printf.kprintf (fun s ->
        logfn "> git %s" s
        Git.CommandHelper.directRunGitCommandAndFail "." s
    ) cmd

let hg cmd = shell "hg" cmd
let hg' cmd = shellOut "hg" cmd

let private splitLines (s: string) =
    s.Split([| "\r\n"; "\n" |], StringSplitOptions.None)

module Hg =
    let getBookmarks() =
        hg' """bookmark -T "{bookmark} {node|short}\n" """
        |> splitLines
        |> Array.map (fun s -> s.Split(' ').[0])

    let getCurrentCommitId() =
        (hg' "id -i").Trim()

    let commitIdForBookmark (b: string) =
        hg' """bookmark -T "{bookmark} {node|short}\n" """
        |> splitLines
        |> Array.pick (fun s ->
            let a = s.Split(' ')
            if a.[0] = b then Some a.[1] else None
        )

    let branchExists (b: string) =
        hg' """branches -T "{branch}\n" """
        |> splitLines
        |> Array.contains b

    let isAncestorOfCurrent (ref: string) =
        let currentRef = getCurrentCommitId()
        let o = hg' """log --rev "ancestors(.) and %s" """ ref
        not (String.IsNullOrWhiteSpace o)

module VC =
    let isGit = Directory.Exists ".git"

    let getTags() =
        if isGit then
            let ok, out, err = Git.CommandHelper.runGitCommand "." "tag --merged"
{'fraction_non_alphanumeric': 0.11823425022182786, 'fraction_numerical': 0.0048802129547471165, 'mean_word_length': 2.370841121495327, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 49, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3276845', 'n_tokens_mistral': 2828, 'n_tokens_neox': 2690, 'n_words': 919}