name: test

on:
  push:
  schedule: # run every month
    - cron: '0 0 1 * *'
  pull_request:
  workflow_dispatch:
    
jobs:
  test_rust:
    name: Test Rust
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Setup Rust
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: stable
      - name: Setup WASM
        uses: jetli/wasm-pack-action@v0.4.0
      - name: Test Native & WASM
        run: |
          cargo clippy --verbose --all-targets --all-features -- -D warnings
          cargo test --verbose
          cargo test --features alloc --no-default-features --verbose
          wasm-pack test --chrome --headless --features alloc --no-default-features --verbose
      - name: Setup and check Embedded
        run: |
          rustup target add thumbv7m-none-eabi
          cargo check --target thumbv7m-none-eabi --features alloc --no-default-features
          rustup override set nightly
          rustup target add thumbv7m-none-eabi
          cargo check --target thumbv7m-none-eabi --features alloc --no-default-features
          sudo apt-get update && sudo apt-get install qemu qemu-system-arm
      - name: Test Embedded (in nightly)
        timeout-minutes: 3
        run: |
          cd tests/embedded
          cargo run
