name: Build HW models

on:
  pull_request

env:
  CHECKOUT_PATH: ${{ github.workspace }}/ext_NRF52_hw_models
  NRFX_BASE: ${{ github.workspace }}/nrfx
  BSIM_OUT_PATH: ${{ github.workspace }}/bsim
  BSIM_COMPONENTS_PATH: ${{ github.workspace }}/bsim/components
  BSIM_BASE_PATH: ${{ github.workspace }}/bsim/components

jobs:
  build-hw-models:
    name: "Build HW models"
    runs-on: ubuntu-latest

    steps:
    - name: Install dependencies
      run: |
        sudo apt-get install gcc-multilib binutils

    - name: Get PR
      uses: actions/checkout@v2
      with:
        path: ${{env.CHECKOUT_PATH}}

    - name: Fetch dependencies
      run: |
        git clone -b v2.8.0 --depth=1 https://github.com/NordicSemiconductor/nrfx ${NRFX_BASE}
        mkdir ${BSIM_OUT_PATH}
        cd ${BSIM_OUT_PATH}
        wget https://storage.googleapis.com/git-repo-downloads/repo
        chmod a+x ./repo
        python3 ./repo init -u https://github.com/BabbleSim/manifest.git -m nrf_hw_models_ci.xml -b master --depth=1
        python3 ./repo sync -c

    - name: Compile HW models
      run: |
        cd ${CHECKOUT_PATH}
        make compile
