<commit_before>
function Get-RepoRoot {
    (Resolve-Path "$PSScriptRoot\..\..\").Path
}
function Test-ReleaseBuild {
    $env:APPVEYOR_REPO_TAG_NAME -eq (Get-Content "$(Get-RepoRoot)/VERSION") -and (!$env:APPVEYOR_REPO_TAG_NAME.EndsWith("dev"))
}

function Test-ComponentChanged ($path) {
    $component = $path -replace 'components/(\w+-*\w*)/.*$', '$1'
    ($env:HAB_COMPONENTS -split ';') -contains $component
}

function Test-PullRequest() {
    ($env:APPVEYOR_REPO_BRANCH -like 'master') -and
        (test-path env:/APPVEYOR_PULL_REQUEST_NUMBER) -and
        (-not [string]::IsNullOrEmpty($env:APPVEYOR_PULL_REQUEST_NUMBER))
}

function Test-SentinelBuild() {
    $env:APPVEYOR_REPO_BRANCH -like 'sentinel*'
}

function Get-ChangedFiles {
    $sha = (git rev-parse HEAD)
    $lastMerge = (git log --merges --max-count=1 --pretty=format:%H)
    
    if($sha -eq $lastMerge) {
        $lastMerge=(git log --merges --max-count=1 --skip=1 --pretty=format:%H)
    }

    git diff master --name-only $lastMerge
}

function Test-SourceChanged {
    $BuildFiles = "appveyor.yml", "build.ps1", "support/ci/appveyor.ps1", "support/ci/appveyor.bat",
                  "Cargo.toml", "Cargo.lock"
    (Get-ChangedFiles |
        where-object {
            ($BuildFiles -contains $_ ) -or
            (($_ -like 'components/*') -and
                (Test-ComponentChanged $_))
        }
    ).count -ge 1
}

function Test-DocsOnlyChanged {
    (Get-ChangedFiles |
        Where-Object {
            !($_ -like '*.md') -and !($_ -like 'docs\*.md')
        }
    ).count -eq 0
}

$ErrorActionPreference="stop"

pushd (Get-RepoRoot)
Write-Host "Configuring build environment"
./build.ps1 -Configure -SkipBuild
$version = $(Get-Content VERSION)

write-host "TAG: $env:APPVEYOR_REPO_TAG_NAME"
Write-Host "VERSION: $version"

if(Test-DocsOnlyChanged -and !(Test-ReleaseBuild)) {
    Write-Host "Test-ReleaseBuild: $(Test-ReleaseBuild)"
    Write-Host "!Test-ReleaseBuild: $(!(Test-ReleaseBuild))"
    Write-Host "This is a DOCS only change. Exiting build."
} elseif (($env:APPVEYOR_REPO_TAG_NAME -eq $version) -or (Test-SourceChanged) -or (test-path env:HAB_FORCE_TEST)) {
    if(Test-ReleaseBuild -and $env:hab_components -ne "launcher") {
        $channel = "rc-$version"
    }
    else {
        $channel = "unstable"
    }

    foreach ($BuildAction in ($env:hab_build_action -split ';')) {
        if ($BuildAction -like 'build') {

            Write-Host "Building hab..."
            Write-Host ""

            ./build.ps1 -Path "components/hab" -Release
            if ($LASTEXITCODE -ne 0) {exit $LASTEXITCODE}
            ./target/release/hab.exe --version
            if ($LASTEXITCODE -ne 0) {exit $LASTEXITCODE}

        }<commit_msg>adjusting boolean logic in appveyor script<commit_after>
function Get-RepoRoot {
    (Resolve-Path "$PSScriptRoot\..\..\").Path
}
function Test-ReleaseBuild {
    $env:APPVEYOR_REPO_TAG_NAME -eq (Get-Content "$(Get-RepoRoot)/VERSION") -and (!$env:APPVEYOR_REPO_TAG_NAME.EndsWith("dev"))
}

function Test-ComponentChanged ($path) {
    $component = $path -replace 'components/(\w+-*\w*)/.*$', '$1'
    ($env:HAB_COMPONENTS -split ';') -contains $component
}

function Test-PullRequest() {
    ($env:APPVEYOR_REPO_BRANCH -like 'master') -and
        (test-path env:/APPVEYOR_PULL_REQUEST_NUMBER) -and
        (-not [string]::IsNullOrEmpty($env:APPVEYOR_PULL_REQUEST_NUMBER))
}

function Test-SentinelBuild() {
    $env:APPVEYOR_REPO_BRANCH -like 'sentinel*'
}

function Get-ChangedFiles {
    $sha = (git rev-parse HEAD)
    $lastMerge = (git log --merges --max-count=1 --pretty=format:%H)
    
    if($sha -eq $lastMerge) {
        $lastMerge=(git log --merges --max-count=1 --skip=1 --pretty=format:%H)
    }

    git diff master --name-only $lastMerge
}

function Test-SourceChanged {
    $BuildFiles = "appveyor.yml", "build.ps1", "support/ci/appveyor.ps1", "support/ci/appveyor.bat",
                  "Cargo.toml", "Cargo.lock"
    (Get-ChangedFiles |
        where-object {
            ($BuildFiles -contains $_ ) -or
            (($_ -like 'components/*') -and
                (Test-ComponentChanged $_))
        }
    ).count -ge 1
}

function Test-DocsOnlyChanged {
    (Get-ChangedFiles |
        Where-Object {
            !($_ -like '*.md') -and !($_ -like 'docs\*.md')
        }
    ).count -eq 0
}

$ErrorActionPreference="stop"

pushd (Get-RepoRoot)
Write-Host "Configuring build environment"
./build.ps1 -Configure -SkipBuild
$version = $(Get-Content VERSION)

write-host "TAG: $env:APPVEYOR_REPO_TAG_NAME"
Write-Host "VERSION: $version"

if((Test-DocsOnlyChanged -eq $true) -and (Test-ReleaseBuild -eq $false)) {
    Write-Host "This is a DOCS only change. Exiting build."
} elseif (($env:APPVEYOR_REPO_TAG_NAME -eq $version) -or (Test-SourceChanged) -or (test-path env:HAB_FORCE_TEST)) {
    if(Test-ReleaseBuild -and $env:hab_components -ne "launcher") {
        $channel = "rc-$version"
    }
    else {
        $channel = "unstable"
    }

    foreach ($BuildAction in ($env:hab_build_action -split ';')) {
        if ($BuildAction -like 'build') {

            Write-Host "Building hab..."
            Write-Host ""

            ./build.ps1 -Path "components/hab" -Release
            if ($LASTEXITCODE -ne 0) {exit $LASTEXITCODE}
            ./target/release/hab.exe --version
            if ($LASTEXITCODE -ne 0) {exit $LASTEXITCODE}

        }
{'fraction_non_alphanumeric': 0.16015552675430475, 'fraction_numerical': 0.004443621551564525, 'mean_word_length': 2.7461858529819696, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '4976276', 'n_tokens_mistral': 1891, 'n_tokens_neox': 1876, 'n_words': 377}