# This workflow is intentionally disabled while we're still working on it
# It's close to ready, but a race condition needs to be fixed with
# API server and Vespa startup, and it needs to have a way to build/test against
# local containers

name: Helm - Lint and Test Charts

on:
  merge_group:
  pull_request:
    branches: [ main ]

jobs:
  lint-test:
    runs-on: Amd64

    # fetch-depth 0 is required for helm/chart-testing-action
    steps:
    - name: Checkout code
      uses: actions/checkout@v3
      with:
        fetch-depth: 0
        
    - name: Set up Helm
      uses: azure/setup-helm@v4.2.0
      with:
        version: v3.14.4
      
    - name: Set up Python
      uses: actions/setup-python@v4
      with:
        python-version: '3.11'
        cache: 'pip'
        cache-dependency-path: |
          backend/requirements/default.txt
          backend/requirements/dev.txt
          backend/requirements/model_server.txt
    - run: |
        python -m pip install --upgrade pip
        pip install -r backend/requirements/default.txt
        pip install -r backend/requirements/dev.txt
        pip install -r backend/requirements/model_server.txt

    - name: Set up chart-testing
      uses: helm/chart-testing-action@v2.6.1

    - name: Run chart-testing (list-changed)
      id: list-changed
      run: |
        changed=$(ct list-changed --target-branch ${{ github.event.repository.default_branch }})
        if [[ -n "$changed" ]]; then
          echo "changed=true" >> "$GITHUB_OUTPUT"
        fi

    - name: Run chart-testing (lint)
#       if: steps.list-changed.outputs.changed == 'true'
      run: ct lint --all --config ct.yaml --target-branch ${{ github.event.repository.default_branch }}

    - name: Create kind cluster
#       if: steps.list-changed.outputs.changed == 'true'
      uses: helm/kind-action@v1.10.0

    - name: Run chart-testing (install)
#       if: steps.list-changed.outputs.changed == 'true'
      run: ct install --all --config ct.yaml
#       run: ct install --target-branch ${{ github.event.repository.default_branch }}
      