name: Build Demo

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

      - name: Install dependencies
        run: sudo apt-get update && sudo apt-get install -y cmake ninja-build

      - name: Download hpm_sdk
        run: |
          cd ~
          git clone https://github.com/hpmicro/hpm_sdk.git

      - name: Download RISC-V toolchain
        run: |
          cd ~
          wget https://github.com/hpmicro/riscv-gnu-toolchain/releases/download/2023.10.18/rv32imac_zicsr_zifencei_multilib_b_ext-linux.tar.gz
          tar -xzf rv32imac_zicsr_zifencei_multilib_b_ext-linux.tar.gz

      - name: Build demo
        run: |
          cd demo/hpmicro
          export HPM_SDK_BASE=~/hpm_sdk
          export GNURISCV_TOOLCHAIN_PATH=~/rv32imac_zicsr_zifencei_multilib_b_ext-linux
          export HPM_SDK_TOOLCHAIN_VARIANT=
          cmake -S . -B build -GNinja -DBOARD=hpm6800evk -DHPM_BUILD_TYPE=ram -DCMAKE_BUILD_TYPE=debug;cmake --build build
