name: Test with coverage

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

env:
  CARGO_TERM_COLOR: always

jobs:
  build:
    runs-on: ubuntu-latest
    services:
      postgres:
        image: postgres:15
        env:
          POSTGRES_DB: test_db
          POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
          --tmpfs /var/lib/postgresql/data
        ports:
          - 5432:5432
    env:
      POSTGRES_CONNECTION_STRING: "host=postgres user=postgres password=${{ secrets.POSTGRES_PASSWORD }} dbname=test_db"
    container:
      image: xd009642/tarpaulin:develop-nightly
      options: --security-opt seccomp=unconfined
    steps:
    - name: Checkout repo
      uses: actions/checkout@v4
      with:
          fetch-depth: 0
    - name: Generate code coverage
      run: |
          cargo +nightly tarpaulin --verbose --all-features --workspace --timeout 120 --out xml
    - name: Upload to codecov.io
      uses: codecov/codecov-action@v5
      with:
          token: ${{secrets.CODECOV_TOKEN}}
          fail_ci_if_error: true
          verbose: true
