name: Continuous Integration

on:
  push:
    branches:
      - "master"
    tags:
      - "v*"
  pull_request:

jobs:
  lint-frontend:
    name: Lint Frontend
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: pnpm/action-setup@v4
        with:
          package_json_file: "frontend/package.json"
      - uses: actions/setup-node@v6
        with:
          node-version: "24.x"
          cache: "pnpm"
          cache-dependency-path: "frontend/pnpm-lock.yaml"
      - working-directory: frontend
        run: |
          pnpm install --frozen-lockfile
          pnpm run lint

  lint-backend:
    name: Lint Backend
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-go@v6
        with:
          go-version: "1.25.x"
      - uses: golangci/golangci-lint-action@v9
        with:
          version: "latest"

  test:
    name: Test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-go@v6
        with:
          go-version: "1.25.x"
      - run: go test --race ./...

  build:
    name: Build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
        with:
          fetch-depth: 0
      - uses: actions/setup-go@v6
        with:
          go-version: '1.25'
      - uses: pnpm/action-setup@v4
        with:
          package_json_file: "frontend/package.json"
      - uses: actions/setup-node@v6
        with:
          node-version: "24.x"
          cache: "pnpm"
          cache-dependency-path: "frontend/pnpm-lock.yaml"
      - name: Install Task
        uses: go-task/setup-task@v1
      - run: task build

  release:
    name: Release
    needs: ["lint-frontend", "lint-backend", "test", "build"]
    if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
        with:
          fetch-depth: 0
      - uses: actions/setup-go@v6
        with:
          go-version: '1.25'
      - uses: pnpm/action-setup@v4
        with:
          package_json_file: "frontend/package.json"
      - uses: actions/setup-node@v6
        with:
          node-version: "24.x"
          cache: "pnpm"
          cache-dependency-path: "frontend/pnpm-lock.yaml"
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3
      - name: Install Task
        uses: go-task/setup-task@v1
      - run: task build:frontend
      - name: Login to Docker Hub
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      - name: Run GoReleaser
        uses: goreleaser/goreleaser-action@v6
        with:
          version: latest
          args: release --clean
        env:
          GITHUB_TOKEN: ${{ secrets.GH_PAT }}



