name: Lint

on:
  push:
    branches:
      - main
  pull_request:

jobs:
  lint:
    name: Lint SourceCode
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3

      - name: Setup node
        uses: actions/setup-node@v3
        with:
          node-version: 18
          check-latest: true
          cache: 'yarn'

      - name: Install
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          profile: default
          override: true
          components: rustfmt, clippy

      - name: Cache cargo
        uses: actions/cache@v3
        with:
          path: |
            ~/.cargo/registry
            ~/.cargo/git
          key: lint-cargo-cache

      - name: 'Install dependencies'
        run: yarn install --immutable --mode=skip-build

      - name: 'Lint JS/TS'
        run: yarn lint

      - name: Cargo fmt
        run: cargo fmt -- --check

      - name: Clippy
        run: cargo clippy

      - name: Clear the cargo caches
        run: |
          cargo install cargo-cache --no-default-features --features ci-autoclean
          cargo-cache