on:
  pull_request:
    branches:
      - main
  push:
    branches:
      - main

name: Continuous integration

jobs:
  test_on_linux:
    name: Tests on Linux
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions-rs/toolchain@v1.0.7
        with:
          toolchain: stable
          override: true
          profile: minimal
      - name: Cache cargo
        uses: actions/cache@v3
        with:
          path: |
            target
            ~/.cargo/git
            ~/.cargo/registry
          key: ${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.lock') }}
      - name: Run cargo-tarpaulin
        uses: actions-rs/tarpaulin@v0.1
        with:
          args: --features intl --ignore-tests
      - name: Upload to codecov.io
        uses: codecov/codecov-action@v3

  test_on_windows:
    name: Tests on Windows
    runs-on: windows-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions-rs/toolchain@v1.0.7
        with:
          toolchain: stable
          override: true
          profile: minimal
      - name: Cache cargo
        uses: actions/cache@v3
        with:
          path: |
            target
            ~/.cargo/git
            ~/.cargo/registry
          key: ${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.lock') }}
      - uses: actions-rs/cargo@v1
        with:
          command: test
          args: -v --features intl

  test_on_macos:
    name: Tests on MacOS
    runs-on: macos-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions-rs/toolchain@v1.0.7
        with:
          toolchain: stable
          override: true
          profile: minimal
      - uses: actions-rs/cargo@v1
        with:
          command: test
          args: -v --features intl

  fmt:
    name: Rustfmt
    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
      - uses: actions-rs/cargo@v1
        with:
          command: fmt
          args: --all -- --check

  clippy:
    name: Clippy
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions-rs/toolchain@v1.0.7
        with:
          toolchain: stable
          override: true
          profile: minimal
          components: clippy
      - name: Cache cargo
        uses: actions/cache@v3
        with:
          path: |
            target
            ~/.cargo/git
            ~/.cargo/registry
          key: ${{ runner.os }}-cargo-clippy-${{ hashFiles('**/Cargo.lock') }}
      - uses: actions-rs/cargo@v1
        with:
          command: clippy
          args: -- --verbose

  examples:
    name: Examples
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions-rs/toolchain@v1.0.7
        with:
          toolchain: stable
          override: true
          profile: minimal
      - name: Cache cargo
        uses: actions/cache@v3
        with:
          path: |
            target
            ~/.cargo/git
            ~/.cargo/registry
          key: ${{ runner.os }}-cargo-examples-${{ hashFiles('**/Cargo.lock') }}
      - run: cd boa_examples
      - name: Build examples
        uses: actions-rs/cargo@v1
        with:
          command: build
      - name: Run example classes
        uses: actions-rs/cargo@v1
        with:
          command: run
          args: --bin classes

  doc:
    name: Documentation
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions-rs/toolchain@v1.0.7
        with:
          toolchain: stable
          override: true
          profile: minimal
      - name: Cache cargo
        uses: actions/cache@v3
        with:
          path: |
            target
            ~/.cargo/git
            ~/.cargo/registry
          key: ${{ runner.os }}-cargo-doc-${{ hashFiles('**/Cargo.lock') }}
      - name: Generate documentation
        uses: actions-rs/cargo@v1
        with:
          command: doc
          args: -v --document-private-items --all-features
