name: Linux Build Status
on:
  [push, pull_request]
jobs:
  build-test:
    runs-on: ubuntu-latest
    if: "!contains(github.ref, 'coverity_scan')"
    strategy:
      matrix:
        DOCKER_IMAGE: [ "ubuntu-18.04", "ubuntu-20.04", "fedora-32", "opensuse-leap" ]
        TPM2TSS_BRANCH: ["master"]
        CC: ["gcc", "clang"]
    steps:
      - name: Check out repository
        uses: actions/checkout@v2
      - name: Launch Action
        uses:
          tpm2-software/ci/runCI@main
        with:
          PROJECT_NAME: ${{ github.event.repository.name }}
          DOCKER_IMAGE: "${{ matrix.DOCKER_IMAGE }}"
          TPM2TSS_BRANCH: "${{ matrix.TPM2TSS_BRANCH }}"
          CC: "${{ matrix.CC }}"
          GIT_FULL_CLONE: true
      - name: failure
        if: ${{ failure() }}
        run: find -name test-suite.log | xargs cat || true
  multi-arch:
    runs-on: ubuntu-latest
    if: "!contains(github.ref, 'coverity_scan')"
    strategy:
      matrix:
        ARCH: [
          "ubuntu-20.04.arm32v7",
          "ubuntu-20.04.arm64v8",
          "fedora-32.ppc64le"
        ]
    steps:
      - name: Setup QEMU
        run: |
          sudo apt-get update
          sudo apt-get install qemu binfmt-support qemu-user-static
          docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
      - name: Check out repository
        uses: actions/checkout@v2
      - name: Launch Action
        uses:
          tpm2-software/ci/runCI@main
        with:
          PROJECT_NAME: ${{ github.event.repository.name }}
          DOCKER_IMAGE: ${{ matrix.ARCH }}
          TPM2TSS_BRANCH: master
          CC: gcc
          MAKE_TARGET: check
      - name: failure
        if: ${{ failure() }}
        run: find -name test-suite.log | xargs cat || true
  coverage-test:
    runs-on: ubuntu-latest
    if: "!contains(github.ref, 'coverity_scan')"
    steps:
      - name: Check out repository
        uses: actions/checkout@v2
      - name: Launch Action
        uses:
          tpm2-software/ci/runCI@main
        with:
          PROJECT_NAME: ${{ github.event.repository.name }}
          ENABLE_COVERAGE: true
          DOCKER_IMAGE: ubuntu-18.04
          TPM2TSS_BRANCH: master
          MAKE_TARGET: check
          CC: gcc
      - name: failure
        if: ${{ failure() }}
        run: find -name test-suite.log | xargs cat || true
  coverity-test:
    runs-on: ubuntu-latest
    if: contains(github.ref, 'coverity_scan') && github.event_name == 'push'
    steps:
      - name: Check out repository
        uses: actions/checkout@v2
      - name: Launch Action
        uses:
          tpm2-software/ci/coverityScan@main
        with:
          PROJECT_NAME: ${{ github.event.repository.name }}
          ENABLE_COVERITY: true
          TPM2TSS_BRANCH: "3.0.x"
          TPM2TOOLS_BRANCH: "4.0"
          REPO_BRANCH: ${{ github.ref }}
          REPO_NAME: ${{ github.repository }}
          DOCKER_IMAGE: ubuntu-18.04
          CC: gcc
          COVERITY_SCAN_TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }}
          COVERITY_SUBMISSION_EMAIL: william.c.roberts@intel.com
  whitespace-check:
    runs-on: ubuntu-latest
    if: github.event_name == 'pull_request' && !contains(github.ref, 'coverity_scan')
    steps:
      - name: Check out repository
        uses: actions/checkout@v2
      - name: Perform Whitespace Check
        env:
          BASE_REF: ${{ github.base_ref }}
        run: git fetch origin "$BASE_REF" && git diff --check "origin/$BASE_REF"
