---
# Tools that can save round-trips to github and a lot of time:
#
# yamllint -f parsable pull_request.yml
# pip3 install ruamel.yaml.cmd
# yaml merge-expand pull_request.yml exp.yml &&
#    diff -w -u pull_request.yml exp.yml
#
# github.com also has a powerful web editor that can be used without
# committing.

# This is the name of this workflow and should technically be called
# something like "Main Workflow" but the place where most people see
# this name is the Checks window next to other, non-github checks.
name: GitHub Actions

# yamllint disable-line rule:truthy
on:
  push:
    branches:
      - 'main'
      - 'stable-**'
      - '**-stable'
  pull_request:
    branches:
      - 'main'
      - 'stable-**'
      - '**-stable'

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# Some jobs may not need submodules but for now our CMakeLists.txt
# systemically downloads them anyway when missing at build time. Easier
# and cleaner to clone everything at once.

jobs:

  doxygen:
    runs-on: ubuntu-20.04

    steps:
      - uses: actions/checkout@v2

      - name: apt get doxygen graphviz
        run: sudo apt-get -y install ninja-build doxygen graphviz

      - name: list all warnings, warnings are not failures
        run: cmake -GNinja -S doc -B docbuild && ninja -C docbuild -v doc

      # Build again (it's very quick) so warnings don't go unnoticed
      - name: fail and stop on first warning
        run: printf 'WARN_AS_ERROR = YES\n' >> doc/sof.doxygen.in &&
          ninja -C docbuild -v doc


  testbench:
    runs-on: ubuntu-20.04

    steps:
      - uses: actions/checkout@v2
        with: {fetch-depth: 0, submodules: recursive}

      - name: docker
        run: docker pull thesofproject/sof && docker tag thesofproject/sof sof

      # testbench needs some topologies
      - name: build topologies
        run: ./scripts/docker-run.sh ./scripts/build-tools.sh -t
      - name: build testbench
        run: ./scripts/docker-run.sh ./scripts/rebuild-testbench.sh
      - name: test
        run: ./scripts/host-testbench.sh


  gcc-build-only:
    runs-on: ubuntu-20.04

    strategy:
      matrix:
        platform: [sue jsl tgl]

    steps:

      - uses: actions/checkout@v2
        with: {fetch-depth: 0, submodules: recursive}

      - name: docker
        run: docker pull thesofproject/sof && docker tag thesofproject/sof sof

      - name: xtensa-build-all
        env:
          PLATFORM: ${{ matrix.platform }}
        run: ./scripts/docker-run.sh
          ./scripts/xtensa-build-all.sh -r ${PLATFORM}

  # Warning: there is a fair amount of duplication between 'build-only'
  # and 'qemu-boot' because github does not support YAML anchors as of Jan
  # 2021.  Defining our new actions would be overkill. Another popular
  # option is to generate this file from a source with YAML anchors
  # before committing it; also deemed overkill for the current amount of
  # duplication.

  qemu-boot-test:
    runs-on: ubuntu-20.04

    strategy:
      matrix:
        # Compiler-based grouping, see HOST= in xtensa-build-all.sh The
        # only reason for grouping is to avoid the matrix swarming the
        # user interface and burying other checks.
        platform: [imx8 imx8x imx8m,
                   byt cht, bdw hsw, apl skl kbl, cnl icl]

    steps:

      - uses: actions/checkout@v2
        with: {fetch-depth: 0, submodules: recursive}

      - name: turn off HAVE_AGENT
        run: echo CONFIG_HAVE_AGENT=n >
          src/arch/xtensa/configs/override/no-agent.config

      - name: docker SOF
        run: docker pull thesofproject/sof && docker tag thesofproject/sof sof

      - name: xtensa-build-all -o no-agent
        env:
          PLATFORM: ${{ matrix.platform }}
        run: ./scripts/docker-run.sh
          ./scripts/xtensa-build-all.sh -o no-agent -r ${PLATFORM}

      - name: docker QEMU
        run: docker pull thesofproject/sofqemu &&
          docker tag thesofproject/sofqemu sofqemu

      - name: qemu-check
        env:
          PLATFORM: ${{ matrix.platform }}
        run: ./scripts/docker-qemu.sh
          ../sof.git/scripts/qemu-check.sh ${PLATFORM}
