name: Frontend Workflow

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - "*"

jobs:
  install-front:
    uses: ./.github/workflows/front-dependencies-installation.yml
    with:
      node_version: "22.x"

  lint-front:
    runs-on: ubuntu-latest
    needs: install-front
    steps:
      - name: Checkout repository
        uses: actions/checkout@v6

      - name: Setup Node.js
        uses: actions/setup-node@v6
        with:
          node-version: "24.x"
      - name: Restore the frontend cache
        uses: actions/cache@v5
        with:
          path: "src/frontend/**/node_modules"
          key: front-node_modules-${{ hashFiles('src/frontend/**/package-lock.json') }}
          fail-on-cache-miss: true

      - name: Check linting
        run: cd src/frontend/ && npm run lint

  test-unit:
    runs-on: ubuntu-latest
    needs: install-front
    steps:
      - name: Checkout repository
        uses: actions/checkout@v6

      - name: Setup Node.js
        uses: actions/setup-node@v6
        with:
          node-version: "24.x"

      - name: Restore the frontend cache
        uses: actions/cache@v5
        with:
          path: "src/frontend/**/node_modules"
          key: front-node_modules-${{ hashFiles('src/frontend/**/package-lock.json') }}
          fail-on-cache-miss: true

      - name: Run unit tests
        run: |
          cd src/frontend/apps/calendars
          TZ=Europe/Paris npm test
