# Note on topology: server:
# The GH actions use mongo-orchestration, which uses a "server" topology for
# the standalone one.

name: Run Driver Tests
on: [push, pull_request]
jobs:
  build:
    name: "${{matrix.os}} ruby-${{matrix.ruby}} mongodb-${{matrix.mongodb}} ${{matrix.topology}}"
    env:
      CI: true
      TESTOPTS: "-v"
    runs-on: ubuntu-22.04
    continue-on-error: true
    strategy:
      fail-fast: false
      matrix:
        os: [ ubuntu-22.04 ]
        ruby: [ "3.2" ]
        mongodb: [ "7.0", "8.0" ]
        topology: [ replica_set, sharded_cluster ]
    steps:
    - name: repo checkout
      uses: actions/checkout@v2
      with:
        submodules: recursive
    - id: start-mongodb
      name: start mongodb
      uses: mongodb-labs/drivers-evergreen-tools@master
      with:
        version: "${{matrix.mongodb}}"
        topology: "${{matrix.topology}}"
    - name: load ruby
      uses: ruby/setup-ruby@v1
      with:
        ruby-version: "${{matrix.ruby}}"
        bundler: 2
    - name: bundle
      run: bundle install --jobs 4 --retry 3
    - name: prepare test suite
      run: bundle exec rake spec:prepare
      env:
        MONGODB_URI: ${{ steps.start-mongodb.outputs.cluster-uri }}
    - name: prepare replica set
      run: ruby -Ilib -I.evergreen/lib -rbundler/setup -rserver_setup -e ServerSetup.new.setup_tags
      if: ${{ matrix.topology == 'replica_set' }}
      env:
        MONGODB_URI: ${{ steps.start-mongodb.outputs.cluster-uri }}
    - name: wait for sessions
      run: bundle exec rake spec:wait_for_sessions
      if: ${{ matrix.topology == 'sharded_cluster' && matrix.mongodb == '3.6' }}
      env:
        MONGODB_URI: ${{ steps.start-mongodb.outputs.cluster-uri }}
    - name: test
      timeout-minutes: 60
      continue-on-error: false
      run: bundle exec rake spec:ci
      env:
        MONGODB_URI: ${{ steps.start-mongodb.outputs.cluster-uri }}
