# Run whenever a PR is generated or updated.

# Most jobs check out the code, ensure Python3 is installed, and for build
# tests the ESP8266 toolchain is cached when possible to speed up execution.

name: ESP8266Audio

on:
  push:
    branches:
      - master
  pull_request:

jobs:

  build-rp2040:
    name: Build RP2040
    runs-on: ubuntu-latest
    strategy:
      matrix:
        chunk: [0, 1, 2, 3, 4]
    steps:
    - uses: actions/checkout@v2
      with:
        submodules: true
    - uses: actions/setup-python@v2
      with:
        python-version: '3.x'
    - name: Build Sketches
      env:
        TRAVIS_BUILD_DIR: ${{ github.workspace }}
        TRAVIS_TAG: ${{ github.ref }}
        BUILD_TYPE: build_rp2040
        BUILD_MOD: 5
        BUILD_REM: ${{ matrix.chunk }}
      run: |
        bash ./tests/common.sh

  build-esp8266:
    name: Build ESP8266
    runs-on: ubuntu-latest
    strategy:
      matrix:
        chunk: [0, 1, 2, 3, 4]
    steps:
    - uses: actions/checkout@v2
      with:
        submodules: true
    - uses: actions/setup-python@v2
      with:
        python-version: '3.x'
    - name: Build Sketches
      env:
        TRAVIS_BUILD_DIR: ${{ github.workspace }}
        TRAVIS_TAG: ${{ github.ref }}
        BUILD_TYPE: build
        BUILD_MOD: 5
        BUILD_REM: ${{ matrix.chunk }}
      run: |
        bash ./tests/common.sh

  build-esp32:
    name: Build ESP-32
    runs-on: ubuntu-latest
    strategy:
      matrix:
        chunk: [0, 1, 2, 3, 4]
    steps:
    - uses: actions/checkout@v2
      with:
        submodules: true
    - uses: actions/setup-python@v2
      with:
        python-version: '3.x'
    - name: Build Sketches
      env:
        TRAVIS_BUILD_DIR: ${{ github.workspace }}
        TRAVIS_TAG: ${{ github.ref }}
        BUILD_TYPE: build_esp32
        BUILD_MOD: 5
        BUILD_REM: ${{ matrix.chunk }}
      run: |
        bash ./tests/common.sh

# Run host test suite under valgrind for runtime checking of code.
  host-tests:
    name: Host tests
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
      with:
        submodules: true
    - uses: actions/setup-python@v2
      with:
        python-version: '3.x'
    - name: Run host tests
      env:
        TRAVIS_BUILD_DIR: ${{ github.workspace }}
        TRAVIS_TAG: ${{ github.ref }}
      run: |
        sudo dpkg --add-architecture i386
        sudo apt-get update
        sudo apt-get install valgrind lcov gcc-multilib g++-multilib libc6-dbg:i386
        cd ./tests/host/
        make
        valgrind --leak-check=full --track-origins=yes -v --error-limit=no --show-leak-kinds=all --error-exitcode=999 ./mp3
        valgrind --leak-check=full --track-origins=yes -v --error-limit=no --show-leak-kinds=all --error-exitcode=999 ./aac
        valgrind --leak-check=full --track-origins=yes -v --error-limit=no --show-leak-kinds=all --error-exitcode=999 ./wav
        valgrind --leak-check=full --track-origins=yes -v --error-limit=no --show-leak-kinds=all --error-exitcode=999 ./flac
        valgrind --leak-check=full --track-origins=yes -v --error-limit=no --show-leak-kinds=all --error-exitcode=999 ./mod
        valgrind --leak-check=full --track-origins=yes -v --error-limit=no --show-leak-kinds=all --error-exitcode=999 ./wav
        valgrind --leak-check=full --track-origins=yes -v --error-limit=no --show-leak-kinds=all --error-exitcode=999 ./midi
        valgrind --leak-check=full --track-origins=yes -v --error-limit=no --show-leak-kinds=all --error-exitcode=999 ./opus

  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: arduino/arduino-lint-action@v1
        with:
          library-manager: 'update'

# Validate orthography
  code-spell:
    name: Check spelling
    runs-on: ubuntu-latest
    defaults:
      run:
        shell: bash
    steps:
    - uses: actions/checkout@v2
      with:
        submodules: true
    - name: Run codespell
      uses: codespell-project/actions-codespell@master
      with:
        skip: ./src/libmad,./src/libhelix-aac,./src/libopus,./src/libflac
        ignore_words_list: ESP8266,esp8266,esp,dout,DOUT,ser,ans,inout,numer,hist
