name: Code Coverage Report

on:
  push:
    branches:
      - main
      - "feature/**"
      - "fix/**"
      - "release/**"
  pull_request:
    branches:
      - main
      - "release/**"

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

env:
  CARGO_TERM_COLOR: always

jobs:
  code_coverage_report:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: dtolnay/rust-toolchain@stable

      - name: Install dependencies
        run: |
          sudo apt-get update && sudo apt-get install -y make libfontconfig1-dev pkg-config

      - name: Install Tarpaulin
        run: cargo install cargo-tarpaulin

      - name: Generate code coverage report
        run: |
          cargo tarpaulin \
            --lib \
            --timeout 180 \
            --out Xml

      - name: Upload coverage reports to Codecov
        uses: codecov/codecov-action@v6
        with:
          fail_ci_if_error: false
        env:
          CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
