# CI jobs

name: CI

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  cf2:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout Repo
      uses: actions/checkout@v2
      with:
        submodules: true

    - name: build
      run: docker run --rm -v ${PWD}:/module bitcraze/builder ./tools/build/build PLATFORM=cf2 UNIT_TEST_STYLE=min

    - name: Upload Build Artifact
      uses: actions/upload-artifact@v2.1.4
      with:
        name: cf2-${{ github.sha }}
        path: cf2.bin
  
  tag:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout Repo
      uses: actions/checkout@v2
      with:
        submodules: true

    - name: build
      run: docker run --rm -v ${PWD}:/module bitcraze/builder ./tools/build/build PLATFORM=tag UNIT_TEST_STYLE=min

    - name: Upload Build Artifact
      uses: actions/upload-artifact@v2.1.4
      with:
        name: tag-${{ github.sha }}
        path: tag.bin
  
  all-flags:
    runs-on: ubuntu-latest
    needs: cf2

    steps:
    - name: Checkout Repo
      uses: actions/checkout@v2
      with:
        submodules: true

    - name: All features
      run: docker run --rm -v ${PWD}:/module bitcraze/builder ./tools/build/build PLATFORM=cf2 DEBUG=1 "EXTRA_CFLAGS=-DCALIBRATED_LED_MORSE -DIMU_TAKE_ACCEL_BIAS -DIMU_MPU6500_DLPF_256HZ -DMADWICK_QUATERNION_IMU -DDEBUG_QUEUE_MONITOR -DENABLE_BQ_DECK -DSITAW_ENABLED -DOW_WRITE_TEST -DOW_READ_TEST -DDEBUG_PRINT_ON_UART -DENABLE_UART1 -DENABLE_UART2"  UNIT_TEST_STYLE=min    

  features:
    runs-on: ubuntu-latest
    needs: cf2

    strategy:
      fail-fast: false
      matrix:
        features:
        # Build cf2 with bosch sensors
        - SENSORS=bosch
        # Build cf2 with TDMA
        - LPS_TDMA_ENABLE=1 "EXTRA_CFLAGS=-DTDMA_NSLOTS_BITS=1 -DTDMA_SLOT=0"
        # Build cf2 with TDOA2 positioning mode
        - LPS_TDOA_ENABLE=1
        # Build cf2 with TDOA3 positioning mode
        - LPS_TDOA3_ENABLE=1
        # Build cf2 with TDOA3 and all config options
        - LPS_TDOA3_ENABLE=1 "EXTRA_CFLAGS=-DLPS_2D_POSITION_HEIGHT=1.2 -DLPS_LONGER_RANGE -DLPS_FULL_TX_POWER"
        # Build Bigquad deck with all config options
        - >
          "EXTRA_CFLAGS=-DENABLE_BQ_DECK -DBQ_DECK_ENABLE_OSD -DBQ_DECK_ENABLE_PM"
    env:
      FEATURE: ${{ matrix.features }}
    
    steps:
    - name: Checkout Repo
      uses: actions/checkout@v2
      with:
        submodules: true

    - name: build
      run: docker run --rm -v ${PWD}:/module bitcraze/builder ./tools/build/build PLATFORM=cf2 ${{ env.FEATURE }} UNIT_TEST_STYLE=min

  apps:
    runs-on: ubuntu-latest
    needs: cf2

    strategy:
      fail-fast: false
      matrix:
        example:
        - app_api
        - examples/app_hello_world
        - examples/app_peer_to_peer
        - examples/demos/app_push_demo
        - examples/demos/swarm_demo
    env:
      EXAMPLE: ${{ matrix.example }}
    
    steps:
    - name: Checkout Repo
      uses: actions/checkout@v2
      with:
        submodules: true

    - name: build
      run: docker run --rm -v ${PWD}:/module bitcraze/builder bash -c "cd ${EXAMPLE}; make -j$(nproc)"