name: system-rubygems-bundler

on:
  pull_request:
    paths:
      - bundler/**
      - .github/workflows/system-rubygems-bundler.yml

  push:
    branches:
      - 3.5

concurrency:
  group: ci-${{ github.ref }}-${{ github.workflow }}
  cancel-in-progress: true

permissions:  # added using https://github.com/step-security/secure-workflows
  contents: read

defaults:
  run:
    shell: bash

jobs:
  system_rubygems_bundler:
    name: Bundler ${{ matrix.bundler.name }} against system Rubygems (${{ matrix.ruby.name }})
    runs-on: ubuntu-24.04
    strategy:
      fail-fast: false
      matrix:
        include:
          - { bundler: { name: 2, value: '' }, ruby: { name: ruby-3.0, value: 3.0.7 } }
          - { bundler: { name: 2, value: '' }, ruby: { name: ruby-3.1, value: 3.1.6 } }
          - { bundler: { name: 2, value: '' }, ruby: { name: ruby-3.2, value: 3.2.6 } }
          - { bundler: { name: 2, value: '' }, ruby: { name: ruby-3.3, value: 3.3.5 } }
          - { bundler: { name: 3, value: 3.0.0 }, ruby: { name: ruby-3.0, value: 3.0.7 } }
          - { bundler: { name: 3, value: 3.0.0 }, ruby: { name: ruby-3.1, value: 3.1.6 } }
          - { bundler: { name: 3, value: 3.0.0 }, ruby: { name: ruby-3.2, value: 3.2.6 } }
          - { bundler: { name: 3, value: 3.0.0 }, ruby: { name: ruby-3.3, value: 3.3.5 } }
    steps:
      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
      - name: Setup ruby
        uses: ruby/setup-ruby@7d3497fd78c07c0d84ebafa58d8dac60cd1f0763 # v1.199.0
        with:
          ruby-version: ${{ matrix.ruby.value }}
          bundler: none
      - name: Install graphviz
        run: sudo apt-get install graphviz -y
        if: matrix.bundler.value == ''
      - name: Replace version
        run: BUNDLER_SPEC_SUB_VERSION=${{ matrix.bundler.value }} bin/rake override_version
        if: matrix.bundler.value != ''
      - name: Prepare dependencies
        run: |
          bin/rake spec:parallel_deps
      - name: Run Test
        run: |
          bin/parallel_rspec
        working-directory: ./bundler
      - name: Save system RubyGems version to ENV
        run: |
          RGV=$(ruby -e 'puts Gem::VERSION.split(".")[0..2].join(".")')
          echo "RGV=v$RGV" >> $GITHUB_ENV
      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
        with:
          path: bundler/tmp/rubygems
          ref: ${{ env.RGV }}
        if: matrix.ruby.name != 'ruby-3.3'
      - name: Run Rubygems Requirement tests against local bundler, to make sure bundler monkeypatches preserve the behaviour
        run: |
          ruby -I../../lib:lib:test test/rubygems/test_gem_requirement.rb
        working-directory: ./bundler/tmp/rubygems
        if: matrix.ruby.name != 'ruby-3.3'
    timeout-minutes: 60
