name: Coding Standards

on:
  pull_request_target:
    branches:
      - main
      - master
    paths:
      - '.github/workflows/codingstandard.yml'
      - 'build/**'
      - 'package.json'
      - 'package-lock.json'
      - 'src/**'

  push:
    branches:
      - main
      - master
    paths:
      - '.github/workflows/codingstandard.yml'
      - 'build/**'
      - 'package.json'
      - 'package-lock.json'
      - 'src/**'

  workflow_dispatch:

concurrency:
  group: coding-standards-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true

jobs:
  tag:
    name: Lint and build
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v5

      - name: Setup Node
        uses: actions/setup-node@v5
        with:
          node-version: 20
          cache: 'npm'
          cache-dependency-path: package-lock.json

      - name: Restore node_modules
        id: node-modules-cache
        uses: actions/cache@v5
        with:
          path: node_modules
          key: ${{ runner.os }}-node-20-modules-${{ hashFiles('package-lock.json') }}

      - name: Install dependencies
        if: steps.node-modules-cache.outputs.cache-hit != 'true'
        run: npm ci --prefer-offline --no-audit --no-fund

      - name: Lint JS
        run: npm run lint-js

      - name: Lint CSS
        run: npm run lint-css

      - name: Build
        run: npm run build
