name: Coding Style
on: [pull_request, workflow_dispatch]

jobs:
  back:
    name: "Lint Back"
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1

      - name: Setup .NET
        uses: actions/setup-dotnet@v1
        with:
          dotnet-version: 7.0.x

      - name: Build the app
        run: cd back && dotnet build -p:CheckCodingStyle=true -p:TreatWarningsAsErrors=true '-p:SkipTranscoder=true'

  front:
    name: "Lint Front"
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: ./front
    steps:
      - uses: actions/checkout@v1

      - name: Find yarn cache
        id: yarn-cache-path
        run: echo "::set-output name=dir::$(yarn cache dir)"

      - name: Restore cache
        uses: actions/cache@v2
        with:
          path: ${{ steps.yarn-cache-path.outputs.dir }}
          key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
          restore-keys: ${{ runner.os }}-yarn-

      - name: Install dependencies
        run: yarn install --immutable

      - name: Lint
        run: yarn lint && yarn format

  scanner:
    name: "Lint scanner"
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: ./scanner
    steps:
      - uses: actions/checkout@v1

      - name: Run black
        run: |
          pip install black-with-tabs
          black . --check

  transcoder:
    name: "Lint transcoder"
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: ./transcoder
    steps:
      - uses: actions/checkout@v1

      - uses: dtolnay/rust-toolchain@stable

      - name: Run cargo fmt
        run: |
          cargo fmt --check
