trigger: none
pr:
  branches:
    include:
      - main
      - release/*
      
jobs:

################################################################################
  - job: check_run_pipeline
################################################################################
    displayName: Check pipeline preconditions (changes ARE in builds or edge-modules/api-proxy-module or mqtt/edgelet-client)
    pool:
      name: $(pool.linux.name)
      demands:
        - ImageOverride -equals agent-aziotedge-ubuntu-22.04-msmoby
    steps:
      - bash: |
          git log -m -1 --name-only --first-parent --pretty="" | egrep -i '^(rust-toolchain\.toml|builds|edge-modules/api-proxy-module|mqtt/edgelet-client)'
          if [[ $? == 0 ]]; then
            echo "Detected changes inside builds or edge-modules/api-proxy-module or mqtt/edgelet-client folders"
            echo "##vso[task.setvariable variable=RUN_PIPELINE;isOutput=true]TRUE"
          fi
        displayName: Check changes in sources
        name: check_files

################################################################################
  - job: linux_amd64
################################################################################
    displayName: Linux amd64
    dependsOn: check_run_pipeline
    condition: eq(dependencies.check_run_pipeline.outputs['check_files.RUN_PIPELINE'], 'true')
    pool:
      name: $(pool.linux.name)
      demands:
        - ImageOverride -equals agent-aziotedge-ubuntu-22.04-msmoby
    steps:
      - script: echo "##vso[task.setvariable variable=NO_VALGRIND;]true"
        displayName: Set env variables
      - bash: scripts/linux/generic-rust/install.sh --project-root "edge-modules/api-proxy-module"
        displayName: Install Rust
      - bash: scripts/linux/generic-rust/build.sh --project-root "edge-modules/api-proxy-module"  --packages "api-proxy-module"  --reduced-linker
        displayName: Build
      - bash: edge-modules/api-proxy-module/build/linux/test.sh
        displayName: Test
