name: Coverage

on:
  workflow_dispatch:
  push:
    branches: [main, master]
  pull_request:
    branches: [main, master]

jobs:
  coverage:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable

      - name: Install tarpaulin
        uses: taiki-e/install-action@cargo-tarpaulin

      - name: Generate coverage
        run: >-
          cargo tarpaulin --locked --out Xml --output-dir ./coverage
          --timeout 1200 --follow-exec --fail-under 50

      - name: Report coverage summary
        run: |
          echo "## Coverage Report" >> $GITHUB_STEP_SUMMARY
          echo "Coverage report generated and uploaded as artifact." >> $GITHUB_STEP_SUMMARY

      - name: Upload coverage report
        uses: actions/upload-artifact@v6
        with:
          name: coverage-report
          path: ./coverage/cobertura.xml
          retention-days: 30
