name: Install Zephyr and dependencies (Linux only)
description: Install Zephyr and dependencies (Linux only)
runs:
  using: "composite"
  steps:
    - name: Setup environment variables
      run: |
        echo "SDK_VERSION=0.16.8" >> $GITHUB_ENV
      shell: bash
    - name: Dependencies
      run: |
        sudo apt-get update && sudo apt-get upgrade
        sudo apt-get install -y --no-install-recommends git cmake ninja-build gperf \
            ccache dfu-util device-tree-compiler wget \
            python3-dev python3-pip python3-setuptools python3-tk python3-wheel xz-utils file \
            make gcc gcc-multilib g++-multilib libsdl2-dev libmagic1
      shell: bash
    - name: Install West
      run: pip install west
      shell: bash
    - name: Install Zephyr SDK
      run : |
        wget -q "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${{env.SDK_VERSION}}/zephyr-sdk-${{env.SDK_VERSION}}_linux-x86_64.tar.xz"
        wget -O - "https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v${{env.SDK_VERSION}}/sha256.sum" | shasum --check --ignore-missing
        sudo tar xvf "zephyr-sdk-${{env.SDK_VERSION}}_linux-x86_64.tar.xz" --directory /opt/
        cd "/opt/zephyr-sdk-${{env.SDK_VERSION}}"
        sudo ./setup.sh -t all -h -c
      shell: bash
    - name: Download and install Zephyr RTOS with the lf-west-template
      run: |
          cd $HOME
          git clone https://github.com/lf-lang/lf-west-template && cd lf-west-template
          west update
          west zephyr-export
          pip install -r deps/zephyr/scripts/requirements.txt
          echo "LF_WEST_TEMPLATE_BASE=$HOME/lf-west-template" >> $GITHUB_ENV
          echo "ZEPHYR_BASE=$HOME/lf-west-template/deps/zephyr" >> $GITHUB_ENV
          echo "ZEPHYR_SDK_INSTALL_DIR=/opt/zephyr-sdk-${{env.SDK_VERSION}}/" >> $GITHUB_ENV
      shell: bash
