name: Ruby

on:
  push:
  pull_request:
  workflow_dispatch:

jobs:
  Lint:
    runs-on: ubuntu-latest
    env:
      BUNDLE_GEMFILE: gemfiles/7.2.gemfile
    steps:
      - uses: actions/checkout@v5
        with:
          fetch-depth: 0
      - uses: ruby/setup-ruby@v1
        with:
          ruby-version: 3.2
          bundler-cache: true
      # Disabled since it requires access not granted by GitHub Actions for PRs
      # - name: Danger
      #   if: ${{ github.event_name == 'pull_request' }}
      #   env:
      #     DANGER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      #   run: |
      #     bundle exec danger
      - name: Rubocop
        run: bundle exec rubocop --autocorrect
  Test:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        ruby-version: [ '3.4', '3.3', '3.2', 'ruby-head' ]
        gemfile: [ '8.1', '8.0', '7.2', 'edge' ]
        exclude:
          - ruby-version: 3.2
          - gemfile: 'edge'
    env:
      BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
    steps:
      - uses: actions/checkout@v5
      - name: Set up Ruby
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: ${{ matrix.ruby-version }}
          bundler-cache: true
      - name: Run tests
        run: bundle exec rake test
  Demo:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - name: Set up Ruby
        uses: ruby/setup-ruby@v1
        with:
          working-directory: demo
          bundler-cache: true
          ruby-version: 3.4
        env:
          BUNDLE_GEMFILE: '../Gemfile'
      - name: Run tests
        working-directory: demo
        run: bundle exec rake test:all
      # - name: Commit changed screenshots and other files
      #   if: failure()
      #   working-directory: demo
      #   run: bundle exec rake commit

