name: Continuous integration

on:
  pull_request:
    branches:
      - main
  push:
    branches:
      - main
      - staging # bors
      - trying # bors

jobs:
  coverage:
    name: Coverage
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions-rs/toolchain@v1.0.7
        with:
          toolchain: stable
          override: true
          profile: minimal
      - uses: Swatinem/rust-cache@v2
        with:
          key: tarpaulin
      - name: Run cargo-tarpaulin
        uses: actions-rs/tarpaulin@v0.1
        with:
          args: --features intl --ignore-tests --engine llvm
      - name: Upload to codecov.io
        uses: codecov/codecov-action@v3

  tests:
    name: Build and Test
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os:
          - macos-latest
          - windows-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions-rs/toolchain@v1.0.7
        with:
          toolchain: stable
          override: true
          profile: minimal
      - uses: Swatinem/rust-cache@v2
      - name: Build tests
        run: cargo test --no-run --profile ci
      # this order is faster according to rust-analyzer
      - name: Build
        run: cargo build --all-targets --quiet --profile ci
      - name: Install latest nextest
        uses: taiki-e/install-action@nextest
      - name: Test with nextest
        run: cargo nextest run --profile ci --cargo-profile ci --features intl

  misc:
    name: Misc
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions-rs/toolchain@v1.0.7
        with:
          toolchain: stable
          override: true
          profile: minimal
          components: rustfmt, clippy
      - uses: Swatinem/rust-cache@v2
        with:
          key: misc
      - name: Format (rustfmt)
        run: cargo fmt --all --check
      - name: Lint (All features)
        run: cargo clippy --all-features --all-targets
      - name: Lint (No features)
        run: cargo clippy --no-default-features --all-targets
      - name: Generate documentation
        run: cargo doc -v --document-private-items --all-features
      - name: Build
        run: cargo build --all-targets --quiet --profile ci
      - run: cd boa_examples
      - name: Build examples
        run: cargo build --quiet --profile ci
      - name: Run example classes
        run: cargo run --bin classes --profile ci
