name: Lint and Test Chart

on:
  pull_request:
    paths:
      - "charts/external-dns/**"

jobs:
  lint-test:
    if: github.repository == 'kubernetes-sigs/external-dns'
    runs-on: ubuntu-latest
    defaults:
      run:
        shell: bash
    steps:
      - name: Checkout
        uses: actions/checkout@v4 # v4.0.0
        with:
          fetch-depth: 0

      - name: Run Artifact Hub lint
        run: |
          set -euo pipefail
          curl -Lo ah_linux_amd64.tar.gz https://github.com/artifacthub/hub/releases/download/v1.9.0/ah_1.9.0_linux_amd64.tar.gz
          tar -xzvf ah_linux_amd64.tar.gz ah
          ./ah lint --kind helm || exit 1
          rm -f ./ah ./ah_linux_amd64.tar.gz

      - name: Set-up Helm
        uses: azure/setup-helm@5119fcb9089d432beecbf79bb2c7915207344b78 # v3.5
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          version: latest

      - name: Set-up Python
        uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          python-version: "3.x"

      - name: Set-up chart-testing
        uses: helm/chart-testing-action@e8788873172cb653a90ca2e819d79d65a66d4e76 # v2.4.0

      - name: Run chart-testing (list-changed)
        id: list-changed
        run: |
          changed=$(ct list-changed)
          if [[ -n "$changed" ]]; then
            echo "changed=true" >> $GITHUB_OUTPUT
          fi

      - name: Run chart-testing (lint)
        run: ct lint --check-version-increment=false

      - name: Set-up Kind cluster
        uses: helm/kind-action@dda0770415bac9fc20092cacbc54aa298604d140 # v1.8.0
        with:
          wait: 120s
        if: steps.list-changed.outputs.changed == 'true'

      - name: Run chart-testing (install)
        run: ct install
