# Prefix build number with "e2e" to ensure images pushed to ACR by this
# pipeline don't conflict with images pushed by the CI build pipeline.
name: e2e.$(Date:yyyyMMdd).$(Rev:r)

trigger: none
pr:
  branches:
    include:
      - main
      - release/*
  paths:
    exclude:
      - platform-validation
      - release/1.1-k8s-preview

variables:
  Codeql.Enabled: false
  DisableDockerDetector: true

resources:
  pipelines:
  - pipeline: ci-build
    source: 'Azure-IoT-Edge-Core CI Build'
    branch: 'main'

stages:

  - template: ../misc/templates/build-images.yaml
    parameters:
      build_single : 'ubuntu22.04:amd64'

  - template: ../misc/templates/build-packages.yaml
    parameters:
      build_single : 'ubuntu22.04:amd64'

  - stage: RunE2ETest
    displayName: End-to-End Test
    dependsOn:
      - CheckBuildImages
      - CheckBuildPackages
      - BuildImages
      - BuildPackages
    condition: or(succeeded('BuildImages'),succeeded('BuildPackages'))
    variables:
      builtImages: $[stageDependencies.CheckBuildImages.check_source_change_runtime.outputs['check_files.RUNTIMECHANGES']]
      builtPackages: $[stageDependencies.CheckBuildPackages.check_source_change_edgelet.outputs['check_files.EDGELETCHANGES']]
    jobs:
      - template: ../e2e/templates/get-storage-uri.yaml
        parameters:
          azureSubscription: $(az.subscription)

      - job: ubuntu_2204_amd64
        displayName: Ubuntu 22.04 amd64
        dependsOn: Token
        condition: succeeded('Token')
        variables:
          verbose: false
          os: linux
          arch: amd64
          identityArtifactName: aziot-identity-ubuntu22.04-amd64
          artifactName: iotedged-ubuntu22.04-amd64
          sas_uri: $[ dependencies.Token.outputs['generate.sas_uri'] ]
        pool:
          name: $(pool.linux.name)
          demands:
            - ImageOverride -equals agent-aziotedge-ubuntu-22.04-msmoby
        steps:
        - template: ../e2e/templates/e2e-setup.yaml
        - template: ../e2e/templates/e2e-run.yaml
          parameters:
            sas_uri: $(sas_uri)