trigger:
  batch: true
  branches:
    include:
      - main
      - release/*
pr: none
variables:
  Codeql.Enabled: false
  DisableDockerDetector: true
  build.configuration: Release
  test.filter: Category=Integration&Category!=Stress
jobs:
  - job: linux
    displayName: Linux
    timeoutInMinutes: 120
    pool:
      name: $(pool.linux.name)
      demands:
        - ImageOverride -equals agent-aziotedge-ubuntu-22.04-msmoby
    variables:
      testEnvironment: linux
    steps:
      - task: AzureKeyVault@2
        displayName: Get secrets
        inputs:
          azureSubscription: $(azure.subscription)
          keyVaultName: $(kv.name)
          secretsFilter: >-
            DummySecret1,
            EdgeCapableDevice2,
            EventHubConnStr2,
            IotDevice2ConnStr2,
            IotDevice3ConnStr2,
            IotHubConnStr2,
            IotHubMqttHeadCert
      - task: Bash@3
        displayName: Install Prerequisites
        inputs:
          filePath: scripts/linux/installPrereqs.sh
      - pwsh: |
          $store = [System.Security.Cryptography.X509Certificates.X509Store]::new('Root', 'CurrentUser')
          $store.Open('ReadWrite')
          $bytes = [System.Convert]::FromBase64String($env:CERT_VALUE)
          $cert = [System.Security.Cryptography.X509Certificates.X509Certificate2]::new($bytes)
          $store.Add($cert)
        displayName: Install protocol head certificate # Needed for integration tests
        env:
          CERT_VALUE: $(IotHubMqttHeadCert)
      - script: scripts/linux/buildBranch.sh -c $(Build.Configuration) --no-rocksdb-bin --skip-quickstart
        displayName: Build
      - script: sudo -E bash -c './scripts/linux/runTests.sh "$(test.filter)" "$(Build.Configuration)"'
        displayName: Integration Tests
        env:
          DummySecret1: $(DummySecret1)
          EdgeCapableDevice2: $(EdgeCapableDevice2)
          EventHubConnStr2: $(EventHubConnStr2)
          IotDevice2ConnStr2: $(IotDevice2ConnStr2)
          IotDevice3ConnStr2: $(IotDevice3ConnStr2)
          IotHubConnStr2: $(IotHubConnStr2)
          IotHubMqttHeadCert: $(IotHubMqttHeadCert)
      - task: PublishTestResults@2
        displayName: Publish test results
        inputs:
          testRunner: VSTest
          testResultsFiles: '**/TestResults/*.trx'
        condition: succeededOrFailed()
