name: CI
on: [push, pull_request]

env:
  JRUBY_OPTS: -Xcext.enabled=true

permissions:
  contents: read

jobs:
  build:
    name: "Test / Ruby ${{ matrix.ruby }}"
    runs-on: ubuntu-latest
    strategy:
      matrix:
        ruby:
          - "3.3"
          - "3.4"
          - "4.0"
      fail-fast: false

    steps:
      - name: Checkout
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          fetch-depth: 10

      - uses: ruby/setup-ruby@c4e5b1316158f92e3d49443a9d58b31d25ac0f8f # v1
        with:
          ruby-version: ${{ matrix.ruby }}
          bundler-cache: true

      - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
        with:
          # Required by lib/github/commands/rest2html (RST rendering)
          python-version: "3.x"

      - uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
        with:
          path: ~/.cache/pip
          key: ${{ runner.os }}-pip

      - name: Install Perl dependencies
        run: |
          curl -1sLf \
            'https://dl.cloudsmith.io/public/nxadm-pkgs/rakudo-pkg/setup.deb.sh' \
            | sudo -E bash
          sudo apt-get update -qq
          sudo apt-get install perl rakudo-pkg

          curl -fsSL https://cpanmin.us | perl - --sudo App::cpanminus
          sudo cpanm --installdeps --notest Pod::Simple

      - name: Install Python dependencies
        run: |
          echo 'docutils==0.22.4 --hash=sha256:d0013f540772d1420576855455d050a2180186c91c15779301ac2ccb3eeb68de' > /tmp/requirements.txt
          python -m pip install --require-hashes --no-deps -r /tmp/requirements.txt

      - name: Run rake
        run: |
          export PATH=$PATH:/.perl6/bin:/opt/rakudo-pkg/bin
          bundle exec rake
