name: Test Coverage

on: [push, pull_request]

permissions:
  contents: read

env:
  COVERAGE: PartialSummary

jobs:
  test:
    name: ${{matrix.ruby}} on ${{matrix.os}}
    runs-on: ${{matrix.os}}-latest
    
    strategy:
      matrix:
        os:
          - ubuntu
          - macos
        
        ruby:
          - ruby
    
    steps:
    - uses: actions/checkout@v6
    - uses: ruby/setup-ruby@v1
      with:
        ruby-version: ${{matrix.ruby}}
        bundler-cache: true
    
    - name: Run tests
      timeout-minutes: 5
      run: bundle exec bake test
    
    - uses: actions/upload-artifact@v5
      with:
        include-hidden-files: true
        if-no-files-found: error
        name: coverage-${{matrix.os}}-${{matrix.ruby}}
        path: .covered.db
  
  validate:
    needs: test
    runs-on: ubuntu-latest
    
    steps:
    - uses: actions/checkout@v6
    - uses: ruby/setup-ruby@v1
      with:
        ruby-version: ruby
        bundler-cache: true
    
    - uses: actions/download-artifact@v6
    
    - name: Validate coverage
      timeout-minutes: 5
      run: bundle exec bake covered:validate --paths */.covered.db \;
