name: Test charts
permissions: {}

on:
  pull_request:
    branches:
      - "main"
    paths:
      - '.github/configs/**'
      - '.github/workflows/helm-*.yml'
      - 'charts/**'
      - 'Makefile'

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  linter-artifacthub:
    runs-on: ubuntu-latest
    container:
      image: artifacthub/ah
      options: --user root
    steps:
      - name: Checkout
        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
      - name: Run ah lint
        working-directory: ./charts/
        run: ah lint
  lint:
    runs-on: ubuntu-24.04
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
        with:
          fetch-depth: 0
      - uses: azure/setup-helm@9bc31f4ebc9c6b171d7bfbaa5d006ae7abdb4310 # v5
      - name: Linting Chart
        run: helm lint ./charts/capsule

      - name: Run chart-testing (lint)
        run: make helm-lint

      - name: Run docs-testing (helm-docs)
        id: helm-docs
        run: |
          make helm-docs
          if [[ $(git diff --stat) != '' ]]; then
            echo -e '\033[0;31mDocumentation outdated! (Run make helm-docs locally and commit)\033[0m ❌'
            git diff --color
            exit 1
          else
            echo -e '\033[0;32mDocumentation up to date\033[0m ✔'
          fi
      - name: Run schema-testing (helm-schema)
        id: helm-schema
        run: |
          make helm-schema
          if [[ $(git diff --stat) != '' ]]; then
            echo -e '\033[0;31mSchema outdated! (Run make helm-schema locally and commit)\033[0m ❌'
            git diff --color
            exit 1
          else
            echo -e '\033[0;32mSchema up to date\033[0m ✔'
          fi
      - name: Run chart-testing (install)
        run: HELM_KIND_CONFIG="./hack/kind-cluster.yml" make helm-test
