<commit_before>jobs:
- job: Meta
  pool:
    vmImage: 'ubuntu-latest'

  steps:
  - pwsh: Write-Host "##vso[build.addbuildtag]$(BuildTag)"
    displayName: "Add Build Tag"

  - pwsh: >
      $path = "$(Build.Repository.LocalPath)/build/version.txt";
      Write-Host "Grabbing version from: $path";

      if(![System.IO.File]::Exists($path)){
          Write-Error "File not found!";
      }

      $version = (Get-Content $path).Trim() + "$(VersionSuffix)";
      Write-Host "Version found: $version";

      try
      {
          [System.Management.Automation.SemanticVersion]::Parse($version);
      }
      catch
      {
          Write-Error "'$version' is an invalid SemVer version"
      }

      Write-Host "##vso[task.setvariable variable=COALESCE_VERSION;isOutput=true]$version";

      $version > $(Build.ArtifactStagingDirectory)/coalesce-version.txt

      Write-Host "##vso[build.addbuildtag]$version"
    failOnStderr: true
    name: buildBaseVersion
    displayName: "Verify and set COALESCE_VERSION variable"

  - task: PublishBuildArtifacts@1
    displayName: 'Publish Artifact: coalesce-version.txt'
    inputs:
      PathtoPublish: '$(Build.ArtifactStagingDirectory)'
      ArtifactName: coalesce-version

- job: 
  displayName: IntelliTect.Coalesce.*
  dependsOn: Meta
  pool:
    vmImage: 'ubuntu-latest'

  variables:
    COALESCE_VERSION: $[ dependencies.Meta.outputs['buildBaseVersion.COALESCE_VERSION'] ]
    
  steps:
  - task: NodeTool@0
    displayName: 'Use Node 10.x'
    inputs:
      versionSpec: 10.x

  # Install both 2.2 (for the cli, last version that supports DotnetCliToolReference) and 3.1 (everything else)
  - task: UseDotNet@2
    inputs:
      packageType: 'sdk'
      version: '3.1.x'

  - task: UseDotNet@2
    inputs:
      packageType: 'sdk'
      version: '2.2.x'


  - task: DotNetCoreCLI@2
    displayName: 'dotnet restore'
    inputs:
      command: restore
      verbosityRestore: normal
      projects: '**/*.csproj'

  - task: DotNetCoreCLI@2
    displayName: 'dotnet build'
    inputs:
      projects: 'src/IntelliTect.Coalesce*/*.csproj'
      arguments: '--configuration $(BuildConfiguration)'

  - task: DotNetCoreCLI@2
    displayName: 'dotnet test'
    inputs:
      command: test
      projects: 'src/IntelliTect.Coalesce*Test*/*.csproj'
      arguments: '--configuration $(BuildConfiguration)'

  - task: DotNetCoreCLI@2
    displayName: 'dotnet publish CLI'
    inputs:
      command: publish
      publishWebProjects: false
      projects: 'src/IntelliTect.Coalesce.Cli/*.csproj'
      arguments: '--configuration $(BuildConfiguration) --output $(build.artifactstagingdirectory)/dotnet-coalesce'
      zipAfterPublish: false
      modifyOutputPath: false

  - task: PublishBuildArtifacts@1
    displayName: 'Publish Artifact: dotnet-coalesce'
    inputs:
      PathtoPublish: '$(Build.ArtifactStagingDirectory)/dotnet-coalesce'
      ArtifactName: 'dotnet-coalesce'

  - task: DotNetCoreCLI@2
    displayName: 'dotnet pack'
    inputs:
      command: pack
      packDirectory: '$(Build.ArtifactStagingDirectory)/packages'
      nobuild: true
      versioningScheme: byEnvVar
      versionEnvVar: COALESCE_VERSION

  - task: PublishBuildArtifacts@1
    displayName: 'Publish Artifact: NuGet Packages'
    inputs:
      PathtoPublish: '$(Build.ArtifactStagingDirectory)/packages'
      ArtifactName: packages

  - script: npm ci
    displayName: 'Coalesce.Web: npm ci'
    workingDirectory: src/Coalesce.Web

  - task: DotNetCoreCLI@2
    displayName: 'Coalesce.Web: dotnet dotnet-coalesce.dll '
    inputs:
      command: custom
      custom: '$(build.artifactstagingdirectory)/dotnet-coalesce/dotnet-coalesce.dll'
      arguments: 'coalesce-ko.json'

  - script: npx gulp copyAll
    displayName: 'Coalesce.Web: npx gulp copyAll'
    workingDirectory: src/Coalesce.Web

  # Commented these out because they're a bit slow, and because Coalesce.Web.Vue hasn't been touched in a long long time,
  # so they really aren't providing much value.
  
  # - script: npm run build-lib
  #   displayName: 'Coalesce.Web.Vue: npm run build-lib'
  #   workingDirectory: src/Coalesce.Web.Vue

  # - script: npm ci
  #   displayName: 'Coalesce.Web.Vue: npm ci'
  #   workingDirectory: src/Coalesce.Web.Vue

  # - task: DotNetCoreCLI@2
  #   displayName: 'Coalesce.Web.Vue: dotnet dotnet-coalesce.dll '
  #   inputs:
  #     command: custom
  #     custom: '$(build.artifactstagingdirectory)/dotnet-coalesce/dotnet-coalesce.dll'
  #     arguments: 'coalesce-vue.json'<commit_msg>Split Coalesce.Web into its own job in the build.<commit_after>jobs:
- job: Meta
  pool:
    vmImage: 'ubuntu-latest'

  steps:
  - pwsh: Write-Host "##vso[build.addbuildtag]$(BuildTag)"
    displayName: "Add Build Tag"

  - pwsh: >
      $path = "$(Build.Repository.LocalPath)/build/version.txt";
      Write-Host "Grabbing version from: $path";

      if(![System.IO.File]::Exists($path)){
          Write-Error "File not found!";
      }

      $version = (Get-Content $path).Trim() + "$(VersionSuffix)";
      Write-Host "Version found: $version";

      try
      {
          [System.Management.Automation.SemanticVersion]::Parse($version);
      }
      catch
      {
          Write-Error "'$version' is an invalid SemVer version"
      }

      Write-Host "##vso[task.setvariable variable=COALESCE_VERSION;isOutput=true]$version";

      $version > $(Build.ArtifactStagingDirectory)/coalesce-version.txt

      Write-Host "##vso[build.addbuildtag]$version"
    failOnStderr: true
    name: buildBaseVersion
    displayName: "Verify and set COALESCE_VERSION variable"

  - task: PublishBuildArtifacts@1
    displayName: 'Publish Artifact: coalesce-version.txt'
    inputs:
      PathtoPublish: '$(Build.ArtifactStagingDirectory)'
      ArtifactName: coalesce-version

- job: 
  displayName: IntelliTect.Coalesce.*
  dependsOn: Meta
  pool:
    vmImage: 'ubuntu-latest'

  variables:
    COALESCE_VERSION: $[ dependencies.Meta.outputs['buildBaseVersion.COALESCE_VERSION'] ]
    
  steps:
  - task: NodeTool@0
    displayName: 'Use Node 10.x'
    inputs:
      versionSpec: 10.x

  # Install both 2.2 (for the cli, last version that supports DotnetCliToolReference) and 3.1 (everything else)
  - task: UseDotNet@2
    inputs:
      packageType: 'sdk'
      version: '3.1.x'

  - task: UseDotNet@2
    inputs:
      packageType: 'sdk'
      version: '2.2.x'


  - task: DotNetCoreCLI@2
    displayName: 'dotnet restore'
    inputs:
      command: restore
      verbosityRestore: normal
      projects: '**/*.csproj'

  - task: DotNetCoreCLI@2
    displayName: 'dotnet build'
    inputs:
      projects: 'src/IntelliTect.Coalesce*/*.csproj'
      arguments: '--configuration $(BuildConfiguration)'

  - task: DotNetCoreCLI@2
    displayName: 'dotnet test'
    inputs:
      command: test
      projects: 'src/IntelliTect.Coalesce*Test*/*.csproj'
      arguments: '--configuration $(BuildConfiguration)'

  - task: DotNetCoreCLI@2
    displayName: 'dotnet publish CLI'
    inputs:
      command: publish
      publishWebProjects: false
      projects: 'src/IntelliTect.Coalesce.Cli/*.csproj'
      arguments: '--configuration $(BuildConfiguration) --output $(build.artifactstagingdirectory)/dotnet-coalesce'
      zipAfterPublish: false
      modifyOutputPath: false

  - task: PublishBuildArtifacts@1
    displayName: 'Publish Artifact: dotnet-coalesce'
    inputs:
      PathtoPublish: '$(Build.ArtifactStagingDirectory)/dotnet-coalesce'
      ArtifactName: 'dotnet-coalesce'

  - task: DotNetCoreCLI@2
    displayName: 'dotnet pack'
    inputs:
      command: pack
      packDirectory: '$(Build.ArtifactStagingDirectory)/packages'
      nobuild: true
      versioningScheme: byEnvVar
      versionEnvVar: COALESCE_VERSION

  - task: PublishBuildArtifacts@1
    displayName: 'Publish Artifact: NuGet Packages'
    inputs:
      PathtoPublish: '$(Build.ArtifactStagingDirectory)/packages'
      ArtifactName: packages



- job: 
  displayName: Coalesce.Web (Knockout Demo)
  dependsOn: Meta
  pool:
    vmImage: 'ubuntu-latest'

  variables:
    COALESCE_VERSION: $[ dependencies.Meta.outputs['buildBaseVersion.COALESCE_VERSION'] ]
    dir: src/Coalesce.Web
    csproj: src/Coalesce.Web/Coalesce.Web.csproj
    
  steps:
  - task: NodeTool@0
    displayName: 'Use Node 10.x'
    inputs:
      versionSpec: 10.x

  - task: UseDotNet@2
    inputs:
      packageType: 'sdk'
      version: '3.1.x'

  - script: npm ci
    displayName: 'Coalesce.Web: npm ci'
    workingDirectory: $(dir)

  - script: npx gulp coalesceKoGen
    displayName: 'Coalesce.Web: npx gulp copyAll'
    workingDirectory: $(dir)

  - script: npx gulp copyAll
    displayName: 'Coalesce.Web: npx gulp copyAll'
    workingDirectory: $(dir)

  - task: DotNetCoreCLI@2
    displayName: 'dotnet build'
    inputs:
      projects: '$(csproj)'
      arguments: '--configuration $(BuildConfiguration)'

  # Commented these out because they're a bit slow, and because Coalesce.Web.Vue hasn't been touched in a long long time,
  # so they really aren't providing much value.
  
  # - script: npm run build-lib
  #   displayName: 'Coalesce.Web.Vue: npm run build-lib'
  #   workingDirectory: src/Coalesce.Web.Vue

  # - script: npm ci
  #   displayName: 'Coalesce.Web.Vue: npm ci'
  #   workingDirectory: src/Coalesce.Web.Vue

  # - task: DotNetCoreCLI@2
  #   displayName: 'Coalesce.Web.Vue: dotnet dotnet-coalesce.dll '
  #   inputs:
  #     command: custom
  #     custom: '$(build.artifactstagingdirectory)/dotnet-coalesce/dotnet-coalesce.dll'
  #     arguments: 'coalesce-vue.json'
{'fraction_non_alphanumeric': 0.1156135770234987, 'fraction_numerical': 0.006057441253263708, 'mean_word_length': 3.115169746454663, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '299243', 'n_tokens_mistral': 3314, 'n_tokens_neox': 3159, 'n_words': 674}