name: $(BuildID)_$(BuildDefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.r)
resources:
  - repo: self
    clean: true

jobs:
- job: Phase_2
  displayName: Ubuntu 20.04 - Node 14.x
  condition: succeededOrFailed()
  pool:
    vmImage: 'Ubuntu 20.04'

  steps:
  - task: NodeTool@0
    displayName: 'Use Node 14.x'
    inputs:
      versionSpec: '14.x'

  - script: |
       npm install --global node-gyp
       npm install --global lerna@^6.6.2
       npm install
    displayName: 'Install Dependencies'

  - script: |
        lerna bootstrap --hoist
        lerna run build
    displayName: 'Bootstrap & Build'

  - script: 'lerna run ci'
    displayName: 'Unit & Integration Tests'
    env:
      IOTHUB_CONNECTION_STRING: $(IOTHUB-CONNECTION-STRING)

  - script: 'lerna run e2e'
    displayName: 'E2E Tests'
    env:
      IOTHUB_CA_ROOT_CERT: $(IOTHUB-CA-ROOT-CERT)
      IOTHUB_CA_ROOT_CERT_KEY: $(IOTHUB-CA-ROOT-CERT-KEY)
      IOT_PROVISIONING_DEVICE_ENDPOINT: $(IOT-PROVISIONING-DEVICE-ENDPOINT)
      IOTHUB_CONNECTION_STRING: $(IOTHUB-CONNECTION-STRING)
      STORAGE_CONNECTION_STRING: $(STORAGE-CONNECTION-STRING)
      IOT_PROVISIONING_DEVICE_IDSCOPE: $(IOT-PROVISIONING-DEVICE-IDSCOPE)
      IOT_PROVISIONING_ROOT_CERT: $(IOT-PROVISIONING-ROOT-CERT)
      IOT_PROVISIONING_ROOT_CERT_KEY: $(IOT-PROVISIONING-ROOT-CERT-KEY)
      IOT_PROVISIONING_SERVICE_CONNECTION_STRING: $(IOT-PROVISIONING-SERVICE-CONNECTION-STRING)
      DPS_CONN_STRING_INVALID_CERT: $(DPS-CONN-STRING-INVALID-CERT)
      DPS_GLOBAL_DEVICE_ENDPOINT_INVALID_CERT: $(DPS-GLOBAL-DEVICE-ENDPOINT-INVALID-CERT)
      IOTHUB_CONN_STRING_INVALID_CERT: $(IOTHUB-CONN-STRING-INVALID-CERT)
      IOTHUB_DEVICE_CONN_STRING_INVALID_CERT: $(IOTHUB-DEVICE-CONN-STRING-INVALID-CERT)

  - task: PublishTestResults@2
    displayName: 'Publish Test Results | Mocha'
    inputs:
      testResultsFiles: '**/test-results.*.xml'
      mergeTestResults: true
      testRunTitle: 'E2E Tests - Linux'
    condition: succeededOrFailed()
