name: Cargo Build & Test

on:
  push:
  pull_request:

env: 
  CARGO_TERM_COLOR: always

jobs:
  build_and_test:
    name: Rust project - latest
    runs-on: rustup-all
    steps:
      - uses: actions/checkout@v4
      - run: cargo build --verbose
      - run: cargo test --verbose
  release:
    name: Release
    runs-on: rustup-wasm
    if: gitea.ref == 'refs/heads/main'
    needs: build_and_test
    steps:
      - uses: actions/checkout@v4
      - run: cargo clean
      - run: cargo update -p wasm-bindgen --precise $(wasm-bindgen --version | cut -d ' ' -f 2)
      - run: cargo build --target wasm32-unknown-unknown --bin wasm --features web --release
      - run: wasm-bindgen target/wasm32-unknown-unknown/release/wasm.wasm --out-dir wasm --web
      - run: cp wasm/* /data/site/nes/
