name: Build

on:
  pull_request:
  push:
    branches-ignore:
      - gh-pages

jobs: 
  build:
    container:
      image: ghcr.io/armmbed/mbed-os-env:latest
    runs-on: ubuntu-latest
    strategy:
      matrix:
        board:
          - "sensorwatch_red"
          - "sensorwatch_green"
          - "sensorwatch_blue"
          - "sensorwatch_pro"
        display:
          - "classic"
          - "custom"
    env:
      BOARD: ${{ matrix.board }}
      DISPLAY: ${{ matrix.display }}
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          submodules: recursive
      - name: Ensure workspace directory is defined as safe
        run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
      - name: Compile movement firmware
        run: make
        working-directory: '.'
      - name: Upload artifacts
        uses: actions/upload-artifact@v4
        with:
          name: ${{ matrix.board }}-display-${{ matrix.display }}-movement.uf2
          path: build/firmware.uf2

  build-simulator:
    container:
      image: emscripten/emsdk
    strategy:
      matrix:
        board:
          - "sensorwatch_red"
          - "sensorwatch_green"
          - "sensorwatch_blue"
          - "sensorwatch_pro"
        display:
          - "classic"
          - "custom"
    env:
      BOARD: ${{ matrix.board }}
      DISPLAY: ${{ matrix.display }}
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          submodules: recursive
      - name: Ensure workspace directory is defined as safe
        run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
      - name: Compile movement
        run: emmake make
        working-directory: '.'
      - name: Archive simulator build
        working-directory: './build-sim'
        run: |
          tar -czf movement.tar.gz firmware.html firmware.wasm firmware.js
      - name: Upload simulator build
        uses: actions/upload-artifact@v4
        with:
          name: ${{ matrix.board }}-display-${{ matrix.display }}-movement.tar.gz
          path: build-sim/movement.tar.gz
