---
name: Test

on:
  pull_request: {}
  push:
    branches:
      - master

permissions:
  contents: read

jobs:
  rubocop:
    env:
      BUNDLE_WITHOUT: release
    runs-on: ubuntu-24.04
    steps:
      - uses: actions/checkout@v6
      - name: Install Ruby ${{ matrix.ruby }}
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: "3.3"
          bundler-cache: true
      - name: Run Rubocop
        run: bundle exec rake rubocop
  test:
    runs-on: ubuntu-24.04
    strategy:
      fail-fast: false
      matrix:
        ruby:
          - "2.7"
          - "3.0"
          - "3.1"
          - "3.2"
          - "3.3"
          - "3.4"
          - "4.0"
          - jruby-9.4
          - jruby-10
        openvox:
          - "~> 8"
          - "~> 7"
          - "https://github.com/OpenVoxProject/puppet.git#main"
        exclude:
          - ruby: jruby-10
            openvox: "~> 7"
          - ruby: "4.0"
            openvox: "~> 7"

          - ruby: "3.4"
            openvox: "~> 7"

          - ruby: "3.0"
            openvox: "~> 8"
          - ruby: "2.7"
            openvox: "~> 8"

          - ruby: "3.0"
            openvox: "https://github.com/openvoxproject/puppet.git#main"
          - ruby: "2.7"
            openvox: "https://github.com/openvoxproject/puppet.git#main"

    env:
      OPENVOX_VERSION: ${{ matrix.openvox }}
      COVERAGE: ${{ matrix.coverage }}
    name: "Ruby ${{ matrix.ruby }} - OpenVox ${{ matrix.openvox }}"
    steps:
      - name: Enable coverage reporting on Ruby 3.1
        if: matrix.openvox == '~> 7' && matrix.ruby == '3.1'
        run: echo 'COVERAGE=yes' >> $GITHUB_ENV
      - uses: actions/checkout@v6
      - name: Install Ruby ${{ matrix.ruby }}
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: ${{ matrix.ruby }}
          bundler-cache: true
      - name: Display Ruby environment
        run: bundle env
      - name: spec tests
        run: bundle exec rake features
      - name: Verify gem builds
        run: gem build --strict --verbose *.gemspec

  tests:
    if: always()
    needs:
      - rubocop
      - test
    runs-on: ubuntu-24.04
    name: Test suite
    steps:
      - name: Decide whether the needed jobs succeeded or failed
        uses: re-actors/alls-green@release/v1
        with:
          jobs: ${{ toJSON(needs) }}
