name: 'setup stackql test'

on:
  push:
    branches:
    - main
    - 'develop-**'
  pull_request:

defaults:
  run:
    shell: bash

jobs:
  stackql-test-matrix:
    name: Stackql local run on ${{ matrix.os }} ${{ matrix.use_wrapper && 'with' || 'without'  }} wrapper
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
        use_wrapper: [true, false]

    steps:
    - name: Checkout
      uses: actions/checkout@v6

    - name: Setup Stackql
      uses: ./
      with:
        use_wrapper: ${{matrix.use_wrapper}}

    - name: Run Registry List
      id: run-registry-list
      run: |
        echo "registry_list_output<<EOF" >> $GITHUB_ENV
        stackql exec "REGISTRY LIST" >> $GITHUB_ENV
        echo "EOF" >> $GITHUB_ENV

    - name: Validate Registry List
      run: |
        echo "Registry list output:"
        echo "$registry_list_output"

        # Validate header row: expect | provider | and | version | columns
        # Use [[:space:]] instead of \s for macOS bash 3.2 compatibility
        HEADER_REGEX='\|[[:space:]]*provider[[:space:]]*\|[[:space:]]*version[[:space:]]*\|'
        if ! [[ "$registry_list_output" =~ $HEADER_REGEX ]]; then
          echo "Registry list header does not match expected format"
          exit 1
        fi

        # Validate at least one data row: | <name> | v<major>.<minor>.<patch> |
        DATA_ROW_REGEX='\|[[:space:]]*[a-z][a-z0-9_]*[[:space:]]*\|[[:space:]]*v[0-9]+\.[0-9]+\.[0-9]+[[:space:]]*\|'
        if ! [[ "$registry_list_output" =~ $DATA_ROW_REGEX ]]; then
          echo "Registry list does not contain a valid data row"
          exit 1
        fi

        echo "Registry list validated successfully."