parameters:
- name: checkoutRepo
  type: string
  default: 'self'
- name: checkoutRef
  type: string
  default: ''
- name: gtestVersion
  type: string
  default: ''
- name: aptPackages
  type: object
  default:
    - cmake
    - git
    - ninja-build

- name: jobMatrix
  type: object
  default:
    buildJobs:
      - { os: ubuntu2204, packageManager: apt }
      - { os: almalinux8, packageManager: dnf }

jobs:
- ${{ each job in parameters.jobMatrix.buildJobs }}:
  - job: gtest_${{ job.os }}
    variables:
    - group: common
    - template: /.azuredevops/variables-global.yml
    pool:
      vmImage: 'ubuntu-22.04'
    ${{ if eq(job.os, 'almalinux8') }}:
      container:
        image: rocmexternalcicd.azurecr.io/manylinux228:latest
        endpoint: ContainerService3
    workspace:
      clean: all
    steps:
    - checkout: none
    - template: ${{ variables.CI_TEMPLATE_PATH }}/steps/dependencies-other.yml
      parameters:
        aptPackages: ${{ parameters.aptPackages }}
        packageManager: ${{ job.packageManager }}
    - template: ${{ variables.CI_TEMPLATE_PATH }}/steps/preamble.yml
    - task: Bash@3
      displayName: Clone GTest ${{ parameters.gtestVersion }}
      inputs:
        targetType: inline
        script: git clone https://github.com/google/googletest -b ${{ parameters.gtestVersion }} --depth=1 --shallow-submodules --recurse-submodules
        workingDirectory: $(Agent.BuildDirectory)
    - template: ${{ variables.CI_TEMPLATE_PATH }}/steps/build-cmake.yml
      parameters:
        os: ${{ job.os }}
        cmakeBuildDir: $(Agent.BuildDirectory)/googletest/build
        cmakeSourceDir: $(Agent.BuildDirectory)/googletest
        useAmdclang: false
        extraBuildFlags: >-
          -DGTEST_FORCE_SHARED_CRT=ON
          -DCMAKE_DEBUG_POSTFIX=d
          -GNinja
    - template: ${{ variables.CI_TEMPLATE_PATH }}/steps/artifact-upload.yml
      parameters:
        os: ${{ job.os }}
