name: CI

on:
  pull_request:

jobs:
  checkstyle:
    name: "Checkstyle Main"
    runs-on: "vps-4"
    container:
      image: "cimg/openjdk:22.0-node"
    steps:
      - name: "Checkout"
        uses: actions/checkout@v3
      - name: Setup Java 22
        uses: actions/setup-java@v3
        with:
          distribution: "temurin"
          java-version: "22"
      - name: "Cache Gradle dependencies"
        uses: actions/cache@v3
        with:
          path: |
            ~/.gradle/caches
            ~/.gradle/wrapper
          key: gradle-${{ runner.os }}-common
          restore-keys: |
            gradle-${{ runner.os }}-
      - name: "Prepare Gradle"
        working-directory: ./backend
        run: gradle clean
      - name: "Check"
        working-directory: ./backend
        run: gradle checkstyleMain
      - name: "Stop Gradle"
        working-directory: ./backend
        run: gradle --stop

  eslint:
    name: eslint
    runs-on: vps-4
    container:
      image: catthehacker/ubuntu:act-latest
    steps:
      - name: Checkout Code
        uses: actions/checkout@v4
      - name: Install bun
        uses: oven-sh/setup-bun@v2
      - uses: actions/cache@v3
        working-directory: ./frontend
        with:
          path: |
            frontend/node_modules/
          key: ${{ runner.os }}-bun-
          restore-keys: |
            ${{ runner.os }}-bun-
      - name: Install dependencies
        run: |
          cd frontend
          bun install
      - name: Run Eslint
        run: |
          cd frontend
          bun run lint

  prettier:
    name: prettier
    runs-on: vps-4
    container:
      image: catthehacker/ubuntu:act-latest
    steps:
      - name: Checkout Code
        uses: actions/checkout@v4
      - name: Install bun
        uses: oven-sh/setup-bun@v2
      - uses: actions/cache@v3
        working-directory: ./frontend
        with:
          path: |
            frontend/node_modules/
          key: ${{ runner.os }}-bun-
          restore-keys: |
            ${{ runner.os }}-bun-
      - name: Install dependencies
        run: |
          cd frontend
          bun install
      - name: Run prettier
        run: |
          cd frontend
          bun run format:check

  test-build:
    name: test-build
    runs-on: vps-4
    container:
      image: catthehacker/ubuntu:act-latest
    steps:
      - name: Checkout Code
        uses: actions/checkout@v4
      - name: Install bun
        uses: oven-sh/setup-bun@v2
      - uses: actions/cache@v3
        working-directory: ./frontend
        with:
          path: |
            frontend/node_modules/
          key: ${{ runner.os }}-bun-
          restore-keys: |
            ${{ runner.os }}-bun-
      - uses: actions/cache@v3
        working-directory: ./frontend
        with:
          path: |
            frontend/dist/
          key: ${{ runner.os }}-dist-
          restore-keys: |
            ${{ runner.os }}-dist-
      - name: Install dependencies
        run: |
          cd frontend
          bun install
      - name: Test build
        run: |
          cd frontend
          bun run build
