name: CI

on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master
  workflow_dispatch:

env:
  # https://blog.rust-lang.org/2022/06/22/sparse-registry-testing.html
  CARGO_UNSTABLE_SPARSE_REGISTRY: "true"
  # actions-rust-lang/setup-rust-toolchain sets some default RUSTFLAGS
  RUSTFLAGS: ""

jobs:
  lint:
    strategy:
      matrix:
        toolchain:
          # Run against a "known good" nightly
          - nightly-2023-01-13
          # Check for breakage on latest nightly
          - nightly

    # But if latest nightly fails, allow the workflow to continue
    continue-on-error: ${{ matrix.toolchain == 'nightly' }}
    runs-on: ubuntu-latest
    container: devkitpro/devkitarm
    steps:
      - name: Checkout branch
        uses: actions/checkout@v2

      - uses: ./.github/actions/setup
        with:
          toolchain: ${{ matrix.toolchain }}

      - name: Check formatting
        run: cargo fmt --all --verbose -- --check

      - name: Cargo check
        run: cargo 3ds clippy --color=always --workspace --verbose --all-targets
        # --deny=warnings would be nice, but can easily break CI for new clippy
        # lints getting added. I'd also like to use Github's "inline warnings"
        # feature, but https://github.com/actions/runner/issues/2341 means we
        # can't have both that *and* colored output.

  doctests:
    strategy:
      matrix:
        toolchain:
          - nightly-2023-01-13
          - nightly
    continue-on-error: ${{ matrix.toolchain == 'nightly' }}
    runs-on: ubuntu-latest
    container: devkitpro/devkitarm
    steps:
      - name: Checkout branch
        uses: actions/checkout@v2

      - uses: ./.github/actions/setup
        with:
          toolchain: ${{ matrix.toolchain }}

      - name: Build doc tests
        run: cargo 3ds test --doc --verbose

  # TODO: it would be nice to actually build 3dsx for examples/tests, etc.
  # and run it somehow, but exactly how remains to be seen.