name: Go

on:
  push:
    branches: [master, v9, v9.7, v9.8]
  pull_request:
    branches: [master, v9, v9.7, v9.8]

permissions:
  contents: read

jobs:

  benchmark:
    name: benchmark
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        redis-version:
          - "8.0.x" # Redis CE 8.0
          - "7.4.x" # Redis stack 7.4
        go-version:
          - "1.23.x"
          - "1.24.x"

    steps:
      - name: Set up ${{ matrix.go-version }}
        uses: actions/setup-go@v5
        with:
          go-version: ${{ matrix.go-version }}

      - name: Checkout code
        uses: actions/checkout@v4

      - name: Setup Test environment
        env:
          REDIS_VERSION: ${{ matrix.redis-version }}
          CLIENT_LIBS_TEST_IMAGE: "redislabs/client-libs-test:${{ matrix.redis-version }}"
        run: |
          set -e
          redis_version_np=$(echo "$REDIS_VERSION" | grep -oP '^\d+.\d+')
          
          # Mapping of redis version to redis testing containers
          declare -A redis_version_mapping=(
            ["8.0.x"]="8.0.2"
            ["7.4.x"]="rs-7.4.0-v5"
          )
          if [[ -v redis_version_mapping[$REDIS_VERSION] ]]; then
            echo "REDIS_VERSION=${redis_version_np}" >> $GITHUB_ENV
            echo "REDIS_IMAGE=redis:${{ matrix.redis-version }}" >> $GITHUB_ENV
            echo "CLIENT_LIBS_TEST_IMAGE=redislabs/client-libs-test:${redis_version_mapping[$REDIS_VERSION]}" >> $GITHUB_ENV
          else
            echo "Version not found in the mapping."
            exit 1
          fi
        shell: bash
      - name: Set up Docker Compose environment with redis ${{ matrix.redis-version }}
        run: make docker.start
        shell: bash
      - name: Benchmark Tests
        env:
          RCE_DOCKER: "true"
          RE_CLUSTER: "false"
        run: make bench
        shell: bash

  test-redis-ce:
    name: test-redis-ce
    runs-on: ubuntu-latest
    strategy:
        fail-fast: false
        matrix:
          redis-version:
            - "8.0.x" # Redis CE 8.0
            - "7.4.x" # Redis stack 7.4
            - "7.2.x" # Redis stack 7.2
          go-version:
            - "1.23.x"
            - "1.24.x"

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Run tests
        uses: ./.github/actions/run-tests
        with:
          go-version: ${{matrix.go-version}}
          redis-version: ${{ matrix.redis-version }}

      - name: Upload to Codecov
        uses: codecov/codecov-action@v5
        with:
          files: coverage.txt
          token: ${{ secrets.CODECOV_TOKEN }}

