<commit_before>parameters:
  rootFolder: '$(Build.SourcesDirectory)'
  runProxy: true
  targetVersion: ''

steps:
  - pwsh: |
        $(Build.SourcesDirectory)/eng/common/scripts/trust-proxy-certificate.ps1
    displayName: 'Language Specific Certificate Trust'

  - pwsh: |
      $version = $(Get-Content "$(Build.SourcesDirectory)/eng/common/testproxy/target_version.txt" -Raw).Trim()
      $overrideVersion = "${{ parameters.targetVersion }}"
      
      if($overrideVersion) {
        Write-Host "Overriding default target proxy version of '$version' with override $overrideVersion."
        $version = $overrideVersion
      }

      dotnet tool install azure.sdk.tools.testproxy `
        --tool-path $(Build.BinariesDirectory)/test-proxy `
        --add-source https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json `
        --version $version
    displayName: "Install test-proxy"

  - pwsh: |
      Write-Host "##vso[task.prependpath]$(Build.BinariesDirectory)/test-proxy"
    displayName: "Prepend path with test-proxy tool install location"

  - ${{ if eq(parameters.runProxy, 'true') }}:
    - pwsh: |
        Write-Host "##vso[task.setvariable variable=ASPNETCORE_Kestrel__Certificates__Default__Path]$(Build.SourcesDirectory)/eng/common/testproxy/dotnet-devcert.pfx"
        Write-Host "##vso[task.setvariable variable=ASPNETCORE_Kestrel__Certificates__Default__Password]password"
        Write-Host "##vso[task.setvariable variable=PROXY_MANUAL_START]true"
      displayName: 'Configure Kestrel and PROXY_MANUAL_START Variables'

    - pwsh: |
        Start-Process $(Build.BinariesDirectory)/test-proxy/test-proxy.exe `
          -ArgumentList "--storage-location ${{ parameters.rootFolder }}" `
          -NoNewWindow -PassThru -RedirectStandardOutput $(Build.SourcesDirectory)/test-proxy.log
      displayName: 'Run the testproxy - windows'
      condition: and(succeeded(), eq(variables['Agent.OS'],'Windows_NT'))

    # nohup does NOT continue beyond the current session if you use it within powershell
    - bash: |
        nohup $(Build.BinariesDirectory)/test-proxy/test-proxy > $(Build.SourcesDirectory)/test-proxy.log &
      displayName: "Run the testproxy - linux/mac"
      condition: and(succeeded(), ne(variables['Agent.OS'],'Windows_NT'))
      workingDirectory: "${{ parameters.rootFolder }}"<commit_msg>Wait for test proxy startup (#23889)<commit_after>parameters:
  rootFolder: '$(Build.SourcesDirectory)'
  runProxy: true
  targetVersion: ''

steps:
  - pwsh: |
        $(Build.SourcesDirectory)/eng/common/scripts/trust-proxy-certificate.ps1
    displayName: 'Language Specific Certificate Trust'

  - pwsh: |
      $version = $(Get-Content "$(Build.SourcesDirectory)/eng/common/testproxy/target_version.txt" -Raw).Trim()
      $overrideVersion = "${{ parameters.targetVersion }}"

      if($overrideVersion) {
        Write-Host "Overriding default target proxy version of '$version' with override $overrideVersion."
        $version = $overrideVersion
      }

      dotnet tool install azure.sdk.tools.testproxy `
        --tool-path $(Build.BinariesDirectory)/test-proxy `
        --add-source https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json `
        --version $version
    displayName: "Install test-proxy"

  - pwsh: |
      Write-Host "##vso[task.prependpath]$(Build.BinariesDirectory)/test-proxy"
    displayName: "Prepend path with test-proxy tool install location"

  - ${{ if eq(parameters.runProxy, 'true') }}:
    - pwsh: |
        Write-Host "##vso[task.setvariable variable=ASPNETCORE_Kestrel__Certificates__Default__Path]$(Build.SourcesDirectory)/eng/common/testproxy/dotnet-devcert.pfx"
        Write-Host "##vso[task.setvariable variable=ASPNETCORE_Kestrel__Certificates__Default__Password]password"
        Write-Host "##vso[task.setvariable variable=PROXY_MANUAL_START]true"
      displayName: 'Configure Kestrel and PROXY_MANUAL_START Variables'

    - pwsh: |
        Start-Process $(Build.BinariesDirectory)/test-proxy/test-proxy.exe `
          -ArgumentList "--storage-location ${{ parameters.rootFolder }}" `
          -NoNewWindow -PassThru -RedirectStandardOutput $(Build.SourcesDirectory)/test-proxy.log
      displayName: 'Run the testproxy - windows'
      condition: and(succeeded(), eq(variables['Agent.OS'],'Windows_NT'))

    # nohup does NOT continue beyond the current session if you use it within powershell
    - bash: |
        nohup $(Build.BinariesDirectory)/test-proxy/test-proxy > $(Build.SourcesDirectory)/test-proxy.log &
      displayName: "Run the testproxy - linux/mac"
      condition: and(succeeded(), ne(variables['Agent.OS'],'Windows_NT'))
      workingDirectory: "${{ parameters.rootFolder }}"

    - pwsh: |
        for ($i = 0; $i -lt 10; $i++) {
            try {
                Invoke-WebRequest -Uri "http://localhost:5000/Admin/IsAlive" | Out-Null
                exit 0
            } catch {
                Write-Warning "Failed to successfully connect to test proxy. Retrying..."
                Start-Sleep 6
            }
        }
        Write-Error "Could not connect to test proxy."
        exit 1
      displayName: Test Proxy IsAlive

{'fraction_non_alphanumeric': 0.12815608263198164, 'fraction_numerical': 0.0036342769701606732, 'mean_word_length': 3.247766043866775, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4139377', 'n_tokens_mistral': 1590, 'n_tokens_neox': 1528, 'n_words': 293}