name: Test Spark
on:
  pull_request:
    paths:
    - tests/install_KinD_create_KinD_cluster_install_kustomize.sh
    - .github/workflows/test_spark.yaml
    - applications/spark/**
    - tests/spark*.sh
    - tests/istio*
    - tests/oauth2-proxy_install.sh
    - common/cert-manager/**
    - common/oauth2-proxy/**
    - common/istio*/**

permissions:
  contents: read
  actions: read

jobs:
  build:
    runs-on: ubuntu-latest
    timeout-minutes: 15
    steps:
    - name: Checkout
      uses: actions/checkout@v4

    - name: Install KinD, Create KinD cluster and Install kustomize
      run: ./tests/install_KinD_create_KinD_cluster_install_kustomize.sh

    - name: Install Istio
      run: ./tests/istio-cni_install.sh

    - name: Install oauth2-proxy
      run: ./tests/oauth2-proxy_install.sh

    - name: Install cert-manager
      run: ./tests/cert_manager_install.sh

    - name: Create kubeflow namespace
      run: kustomize build common/kubeflow-namespace/base | kubectl apply -f -

    - name: Install KF Multi Tenancy
      run: ./tests/multi_tenancy_install.sh

    - name: Create KF Profile
      run: kustomize build common/user-namespace/base | kubectl apply -f -

    - name: Build & Apply manifests
      run: |
        cd applications/spark
        # TODO remove the debugging lines
        ls -lah  ../../tests/
        chmod u+x ../../tests/*.sh
        ../../tests/spark_install.sh
        ../../tests/spark_test.sh "kubeflow-user-example-com"
