<commit_before># Azure DevOps
# CI pipeline for PSDocs

variables:
  version: '0.10.0'
  buildConfiguration: 'Release'
  disable.coverage.autogenerate: 'true'
  imageName: 'ubuntu-18.04'

 # Use build number format, i.e. 0.10.0-B2004001
name: $(version)-B$(date:yyMM)$(rev:rrr)

trigger:
  branches:
    include:
    - 'main'
  tags:
    include:
    - 'v0.*'

pr:
  branches:
    include:
    - 'main'

stages:

# Build pipeline
- stage: Build
  displayName: Build
  dependsOn: []
  jobs:
  - job:
    pool:
      vmImage: $(imageName)
    displayName: 'Module'
    steps:

    # Install pipeline dependencies
    - powershell: ./.azure-pipelines/pipeline-deps.ps1
      displayName: 'Install dependencies'

    # Build module
    - powershell: Invoke-Build -Configuration $(buildConfiguration) -Build $(Build.BuildNumber)
      displayName: 'Build module'

    # DotNet test results
    - task: PublishTestResults@2
      displayName: 'Publish unit test results'
      inputs:
        testRunTitle: 'DotNet on $(imageName)'
        testRunner: VSTest
        testResultsFiles: 'reports/*.trx'
        mergeTestResults: true
        platform: $(imageName)
        configuration: $(buildConfiguration)
        publishRunAttachments: true
      condition: succeededOrFailed()

    # PSRule results
    - task: PublishTestResults@2
      displayName: 'Publish PSRule results'
      inputs:
        testRunTitle: 'PSRule on $(imageName)'
        testRunner: NUnit
        testResultsFiles: 'reports/ps-rule*.xml'
        mergeTestResults: true
        platform: $(imageName)
        configuration: $(buildConfiguration)
        publishRunAttachments: true
      condition: succeededOrFailed()

    # Generate artifacts
    - publish: out/modules/PSDocs
      displayName: 'Publish module'
      artifact: PSDocs

# Analysis pipeline
- stage: Analysis
  displayName: Analysis
  dependsOn: []
  jobs:
  - job:
    pool:
      vmImage: $(imageName)
    displayName: 'SonarCloud'
    condition: not(eq(variables['Build.Reason'], 'PullRequest'))
    steps:

    - script: |
        echo "##vso[task.setvariable variable=JAVA_HOME]$(JAVA_HOME_11_X64)"
        echo "##vso[task.setvariable variable=PATH]$(JAVA_HOME_11_X64)\bin;$(PATH)"
      displayName: 'Set Java version'

    # Run SonarCloud analysis
    - script: dotnet tool install --global dotnet-sonarscanner
      displayName: 'Install Sonar scanner'

    - script: $HOME/.dotnet/tools/dotnet-sonarscanner begin /k:"BernieWhite_PSDocs" /o:"berniewhite-github" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.login=$(sonarQubeToken) /v:"$(Build.BuildNumber)" /d:sonar.cs.vscoveragexml.reportsPaths="reports/" /d:sonar.cs.xunit.reportsPaths="reports/"
      displayName: 'Prepare SonarCloud'

    - script: dotnet build
      displayName: 'Build solution for analysis'

    - script: $HOME/.dotnet/tools/dotnet-sonarscanner end /d:sonar.login=$(sonarQubeToken)
      displayName: 'Complete SonarCloud'

  - job: Secret_Scan
    pool: 'Hosted VS2017'
    displayName: Secret scan
    steps:
    - task: securedevelopmentteam.vss-secure-development-tools.build-task-credscan.CredScan@2
      displayName: 'Scan for secrets'
      inputs:
        debugMode: false
        toolMajorVersion: V2

    - task: securedevelopmentteam.vss-secure-development-tools.build-task-publishsecurityanalysislogs.PublishSecurityAnalysisLogs@2
      displayName: 'Publish scan logs'
      continueOnError: true

    - task: securedevelopmentteam.vss-secure-development-tools.build-task-postanalysis.PostAnalysis@1
      displayName: 'Check for failures'
      inputs:
        CredScan: true
        ToolLogsNotFoundAction: Error

# Test pipeline
- stage: Test
  dependsOn: Build
  jobs:

  - template: jobs/test.yaml
    parameters:
      name: ubuntu_18_04_coverage
      imageName: 'ubuntu-18.04'
      displayName: 'PowerShell coverage'
      coverage: 'true'
      publishResults: 'false'

  - template: jobs/test.yaml
    parameters:
      name: macOS_10_15
      displayName: 'PowerShell 7.1 - macOS-10.15'
      imageName: 'macOS-10.15'

  - template: jobs/test.yaml
    parameters:
      name: windows_2016
      displayName: 'PowerShell 5.1 - Windows 2016'
      imageName: 'vs2017-win2016'
      pwsh: 'false'

  - template: jobs/test.yaml
    parameters:
      name: windows_2019
      displayName: 'PowerShell 7.1 - Windows 2019'
      imageName: 'windows-2019'

  - template: jobs/testContainer.yaml
    parameters:
      name: alpine_3_10
      displayName: 'PowerShell 7.1 - alpine-3.10'
      imageName: mcr.microsoft.com/powershell/test-deps
      imageTag: alpine-3.10

  - template: jobs/testContainer.yaml
    parameters:
      name: ps_7_0_ubuntu_18_04
      displayName: 'PowerShell 7.0 - ubuntu-18.04'
      imageName: mcr.microsoft.com/powershell
      imageTag: 7.0.3-ubuntu-18.04

  - template: jobs/testContainer.yaml
    parameters:
      name: ps_7_1_ubuntu_18_04
      displayName: 'PowerShell 7.1 - ubuntu-18.04'
      imageName: mcr.microsoft.com/powershell
      imageTag: 7.1.0-ubuntu-18.04

  - template: jobs/testContainer.yaml
    parameters:
      name: ps_7_1_ubuntu_20_04
      displayName: 'PowerShell 7.1 - ubuntu-20.04'
      imageName: mcr.microsoft.com/powershell
      imageTag: 7.1.0-ubuntu-20.04

  - template: jobs/testContainer.yaml
    parameters:
      name: ps_6_ubuntu_18_04
      displayName: 'PowerShell 6.2.4 - ubuntu-18.04'
      imageName: mcr.microsoft.com/powershell
      imageTag: 6.2.4-ubuntu-18.04

# Release pipeline
- stage: Release
  displayName: Release
  dependsOn: [ 'Test', 'Analysis' ]
  condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v0.'))
  jobs:
  - job:
    displayName: Live
    pool:
      vmImage: $(imageName)
    variables:
      isPreRelease: $[contains(variables['Build.SourceBranchName'], '-B')]
    steps:

    # Download module from build
    - task: DownloadPipelineArtifact@2
      displayName: 'Download module'
      inputs:
        artifact: PSDocs
        path: $(Build.SourcesDirectory)/out/modules/PSDocs

    # Install pipeline dependencies
    - powershell: ./.azure-pipelines/pipeline-deps.ps1
      displayName: 'Install dependencies'<commit_msg>Update CI pipeline agents (#188)<commit_after># Azure DevOps
# CI pipeline for PSDocs

variables:
  version: '0.10.0'
  buildConfiguration: 'Release'
  disable.coverage.autogenerate: 'true'
  imageName: 'ubuntu-20.04'

 # Use build number format, i.e. 0.10.0-B2004001
name: $(version)-B$(date:yyMM)$(rev:rrr)

trigger:
  branches:
    include:
    - 'main'
  tags:
    include:
    - 'v0.*'

pr:
  branches:
    include:
    - 'main'

stages:

# Build pipeline
- stage: Build
  displayName: Build
  dependsOn: []
  jobs:
  - job:
    pool:
      vmImage: $(imageName)
    displayName: 'Module'
    steps:

    # Install pipeline dependencies
    - powershell: ./.azure-pipelines/pipeline-deps.ps1
      displayName: 'Install dependencies'

    # Build module
    - powershell: Invoke-Build -Configuration $(buildConfiguration) -Build $(Build.BuildNumber)
      displayName: 'Build module'

    # DotNet test results
    - task: PublishTestResults@2
      displayName: 'Publish unit test results'
      inputs:
        testRunTitle: 'DotNet on $(imageName)'
        testRunner: VSTest
        testResultsFiles: 'reports/*.trx'
        mergeTestResults: true
        platform: $(imageName)
        configuration: $(buildConfiguration)
        publishRunAttachments: true
      condition: succeededOrFailed()

    # PSRule results
    - task: PublishTestResults@2
      displayName: 'Publish PSRule results'
      inputs:
        testRunTitle: 'PSRule on $(imageName)'
        testRunner: NUnit
        testResultsFiles: 'reports/ps-rule*.xml'
        mergeTestResults: true
        platform: $(imageName)
        configuration: $(buildConfiguration)
        publishRunAttachments: true
      condition: succeededOrFailed()

    # Generate artifacts
    - publish: out/modules/PSDocs
      displayName: 'Publish module'
      artifact: PSDocs

# Analysis pipeline
- stage: Analysis
  displayName: Analysis
  dependsOn: []
  jobs:
  - job:
    pool:
      vmImage: $(imageName)
    displayName: 'SonarCloud'
    condition: not(eq(variables['Build.Reason'], 'PullRequest'))
    steps:

    - script: |
        echo "##vso[task.setvariable variable=JAVA_HOME]$(JAVA_HOME_11_X64)"
        echo "##vso[task.setvariable variable=PATH]$(JAVA_HOME_11_X64)\bin;$(PATH)"
      displayName: 'Set Java version'

    # Run SonarCloud analysis
    - script: dotnet tool install --global dotnet-sonarscanner
      displayName: 'Install Sonar scanner'

    - script: $HOME/.dotnet/tools/dotnet-sonarscanner begin /k:"BernieWhite_PSDocs" /o:"berniewhite-github" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.login=$(sonarQubeToken) /v:"$(Build.BuildNumber)" /d:sonar.cs.vscoveragexml.reportsPaths="reports/" /d:sonar.cs.xunit.reportsPaths="reports/"
      displayName: 'Prepare SonarCloud'

    - script: dotnet build
      displayName: 'Build solution for analysis'

    - script: $HOME/.dotnet/tools/dotnet-sonarscanner end /d:sonar.login=$(sonarQubeToken)
      displayName: 'Complete SonarCloud'

  - job: Secret_Scan
    pool: 'Hosted VS2017'
    displayName: Secret scan
    steps:
    - task: securedevelopmentteam.vss-secure-development-tools.build-task-credscan.CredScan@2
      displayName: 'Scan for secrets'
      inputs:
        debugMode: false
        toolMajorVersion: V2

    - task: securedevelopmentteam.vss-secure-development-tools.build-task-publishsecurityanalysislogs.PublishSecurityAnalysisLogs@2
      displayName: 'Publish scan logs'
      continueOnError: true

    - task: securedevelopmentteam.vss-secure-development-tools.build-task-postanalysis.PostAnalysis@1
      displayName: 'Check for failures'
      inputs:
        CredScan: true
        ToolLogsNotFoundAction: Error

# Test pipeline
- stage: Test
  dependsOn: Build
  jobs:

  - template: jobs/test.yaml
    parameters:
      name: ubuntu_20_04_coverage
      imageName: 'ubuntu-20.04'
      displayName: 'PowerShell coverage'
      coverage: 'true'
      publishResults: 'false'

  - template: jobs/test.yaml
    parameters:
      name: macOS_10_15
      displayName: 'PowerShell 7.1 - macOS-10.15'
      imageName: 'macOS-10.15'

  - template: jobs/test.yaml
    parameters:
      name: windows_2016
      displayName: 'PowerShell 5.1 - Windows 2016'
      imageName: 'vs2017-win2016'
      pwsh: 'false'

  - template: jobs/test.yaml
    parameters:
      name: windows_2019
      displayName: 'PowerShell 7.1 - Windows 2019'
      imageName: 'windows-2019'

  - template: jobs/testContainer.yaml
    parameters:
      name: alpine_3_10
      displayName: 'PowerShell 7.1 - alpine-3.10'
      imageName: mcr.microsoft.com/powershell/test-deps
      imageTag: alpine-3.10

  - template: jobs/testContainer.yaml
    parameters:
      name: ps_7_1_ubuntu_18_04
      displayName: 'PowerShell 7.1 - ubuntu-18.04'
      imageName: mcr.microsoft.com/powershell
      imageTag: 7.1.2-ubuntu-18.04

  - template: jobs/testContainer.yaml
    parameters:
      name: ps_7_1_ubuntu_20_04
      displayName: 'PowerShell 7.1 - ubuntu-20.04'
      imageName: mcr.microsoft.com/powershell
      imageTag: 7.1.2-ubuntu-20.04

  - template: jobs/testContainer.yaml
    parameters:
      name: ps_7_2_ubuntu_20_04_preview
      displayName: 'PowerShell 7.2 (Preview 7) - ubuntu-20.04'
      imageName: mcr.microsoft.com/powershell
      imageTag: 7.2.0-preview.7-ubuntu-20.04

# Release pipeline
- stage: Release
  displayName: Release
  dependsOn: [ 'Test', 'Analysis' ]
  condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v0.'))
  jobs:
  - job:
    displayName: Live
    pool:
      vmImage: $(imageName)
    variables:
      isPreRelease: $[contains(variables['Build.SourceBranchName'], '-B')]
    steps:

    # Download module from build
    - task: DownloadPipelineArtifact@2
      displayName: 'Download module'
      inputs:
        artifact: PSDocs
        path: $(Build.SourcesDirectory)/out/modules/PSDocs

    # Install pipeline dependencies
    - powershell: ./.azure-pipelines/pipeline-deps.ps1
      displayName: 'Install dependencies'
{'fraction_non_alphanumeric': 0.11039490861618799, 'fraction_numerical': 0.028720626631853787, 'mean_word_length': 2.9551468215553403, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3295260', 'n_tokens_mistral': 4239, 'n_tokens_neox': 3885, 'n_words': 820}