name: CI
on: [push, pull_request]
jobs:
  test:
    name: Test
    runs-on: ubuntu-latest
    strategy:
      matrix:
        go-version: [1.22.x]

    services:
      redis:
        image: redis:6.2-alpine
        ports:
          - 6379:6379
      postgres:
        image: postgis/postgis:14-3.3-alpine
        env:
          POSTGRES_DB: gocommon_test
          POSTGRES_USER: gocommon_test
          POSTGRES_PASSWORD: temba
        ports:
          - 5432:5432
        options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
      minio:
        image: bitnami/minio:latest
        env:
          MINIO_ROOT_USER: root
          MINIO_ROOT_PASSWORD: tembatemba
        ports:
          - 9000:9000     
        options: --health-cmd "mc ready local" --health-interval 10s --health-timeout 5s --health-retries 5

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

      - name: Install Linux packages
        run: sudo apt install -y --no-install-recommends pandoc

      - name: Install Go
        uses: actions/setup-go@v5
        with:
          go-version: ${{ matrix.go-version }}

      - name: Run tests
        run: go test -p=1 -coverprofile=coverage.text -covermode=atomic ./...

      - name: Upload coverage
        if: success()
        uses: codecov/codecov-action@v4
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          fail_ci_if_error: true