name: Tinyauth CI
on:
  push:
    branches:
      - main
  pull_request:

permissions:
  contents: read

jobs:
  ci:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

      - name: Setup bun
        uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2

      - name: Setup go
        uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6
        with:
          go-version: "^1.26.0"

      - name: Go dependencies
        run: go mod download

      - name: Install frontend dependencies
        run: |
          cd frontend
          bun install --frozen-lockfile

      - name: Set version
        run: |
          echo testing > internal/assets/version

      - name: Lint frontend
        run: |
          cd frontend
          bun run lint

      - name: Build frontend
        run: |
          cd frontend
          bun run build

      - name: Copy frontend
        run: |
          cp -r frontend/dist internal/assets/dist

      - name: Run tests
        run: go test -coverprofile=coverage.txt -v ./...

      - name: Upload coverage reports to Codecov
        uses: codecov/codecov-action@57e3a136b779b570ffcdbf80b3bdc90e7fab3de2 # v6
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
