name: "Test Helm Charts"
on:
  push:
    branches-ignore: ['renovate/**']
  pull_request:
env:
  helm-version: v3.11.0
jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: Set up chart-testing
        uses: helm/chart-testing-action@v2.3.1
      - name: Run chart-testing (lint)
        run: make lint
      - name: Run ShellCheck on scripts shipped with helm chart
        uses: ludeeus/action-shellcheck@master
        with:
          scandir: './chart/scripts'
      - name: Run ShellCheck on development scripts
        uses: ludeeus/action-shellcheck@master
        with:
          scandir: './scripts'
          severity: error
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        kube:
          - "1.23"
          - "1.24"
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: Increase fs watchers
        run: |
          sudo sysctl fs.inotify.max_user_watches=524288
          sudo sysctl fs.inotify.max_user_instances=524288
      - name: Set up chart-testing
        uses: helm/chart-testing-action@v2.3.1
      - name: Start kuberenetes cluster with cert-manager
        env:
          KUBE_VERSION: ${{ matrix.kube }}
        run: |
          make start-kind
          make cert-manager
      - name: Start timescaledb-single helm chart install
        run: |
          make timescaledb
      - name: Wait for cluster to finish bootstraping
        run: kubectl wait --for=condition=Ready pods --all --all-namespaces --timeout=300s
      - name: Run e2e chart-testing
        run: make e2e
      - name: Setup tmate session
        if: ${{ failure() }}
        uses: mxschmitt/action-tmate@v3
        with:
          limit-access-to-actor: true
  test-result:
    name: End-to-End Test Results
    if: always()
    needs:
      - test
    runs-on: ubuntu-latest
    steps:
      - name: Mark the job as a success
        if: needs.test.result == 'success'
        run: exit 0
      - name: Mark the job as a failure
        if: needs.test.result != 'success'
        run: exit 1