name: Lint, Test, Build, and Push Docker Image

on:
  push:
    branches:
      - '**'
    tags:
      - '**'
  pull_request:
    branches:
      - '**'

jobs:
  lint:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Set up Node.js
        uses: actions/setup-node@v3
        with:
          node-version: '23'

      - name: Install frontend dependencies
        run: |
          cd frontend
          npm install

      - name: Cache pre-commit environment
        uses: actions/cache@v3
        with:
          path: |
            ~/.cache/pre-commit
          key: ${{ runner.os }}-pre-commit-${{ hashFiles('**/.pre-commit-config.yaml') }}
          restore-keys: |
            ${{ runner.os }}-pre-commit-

      - name: Install dependencies
        run: |
          pip install pre-commit
          pre-commit install

      - name: Run pre-commit
        run: |
          pre-commit run --all-files
