name: Ruby

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

permissions:
  contents: read

jobs:
  test:
    defaults:
      run:
        working-directory: ./web
    runs-on: ubuntu-latest
    strategy:
      matrix:
        ruby-version: ['3.3', '3.4']

    steps:
    - uses: actions/checkout@v5
    - name: Set up Ruby
      uses: ruby/setup-ruby@v1
      with:
        ruby-version: ${{ matrix.ruby-version }}
        bundler-cache: true
        working-directory: ./web
    - name: Set up dependencies
      run: bundle install
    - name: Run rufo
      run: bundle exec rufo --check .
    - name: Run tests
      run: |
        mkdir -p tmp/test-results
        bundle exec rspec \
          --require rspec_junit_formatter \
          --format progress \
          --format RspecJunitFormatter \
          --out tmp/test-results/rspec.xml
    - name: Upload test results to Codecov
      uses: codecov/test-results-action@v1
      with:
        token: ${{ secrets.CODECOV_TOKEN }}
        files: ./web/tmp/test-results/rspec.xml
        flags: ruby-${{ matrix.ruby-version }}
    - name: Upload coverage to Codecov
      uses: codecov/codecov-action@v5
      with:
        token: ${{ secrets.CODECOV_TOKEN }}
        fail_ci_if_error: false
        flags: ruby-${{ matrix.ruby-version }}
      env:
        CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
