name: Quality checks 👌🧪

on:
  workflow_call:
    inputs:
      commit:
        required: true
        type: string
  workflow_dispatch:

jobs:
  dependency-review:
    name: Vulnerable dependencies 🔎
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repository
        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          ref: ${{ inputs.commit }}
          show-progress: false

      - name: Scan
        uses: actions/dependency-review-action@a1d282b36b6f3519aa1f3fc636f609c47dddb294 # v5.0.0
        with:
          ## Workaround from https://github.com/actions/dependency-review-action/issues/456
          ## TODO: Remove when necessary
          base-ref: ${{ github.event.pull_request.base.sha || 'master' }}
          head-ref: ${{ github.event.pull_request.head.sha || github.ref }}

  quality:
    name: Run ${{ matrix.command }} 🕵️‍♂️
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        command:
          - build:es-check
          - lint
          - stylelint
          - build:check
          - test

    steps:
      - name: Checkout ⬇️
        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          ref: ${{ inputs.commit }}
          show-progress: false

      - name: Setup node environment ⚙️
        uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6.5.0
        with:
          node-version-file: .nvmrc
          cache: npm
          check-latest: true

      - name: Install dependencies 📦
        run: npm ci --no-audit

      - name: Run ${{ matrix.command }} ⚙️
        run: npm run ${{ matrix.command }}
