name: Chart

on:
  push:
    branches:
      - main
      - release-*
    paths:
      - charts/ingress-nginx/Chart.yaml
  
  workflow_dispatch:

permissions:
  contents: read

jobs:
  release:
    name: Release
    runs-on: ubuntu-latest

    permissions:
      contents: write

    steps:
      - name: Set up Python
        uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
        with:
          python-version: 3.x

      - name: Set up Helm
        uses: azure/setup-helm@1a275c3b69536ee54be43f2070a358922e12c8d4 # v4.3.1
        with:
          version: v3.19.2

      - name: Set up Helm Chart Testing
        uses: helm/chart-testing-action@6ec842c01de15ebb84c8627d2744a0c2f2755c9f

      - name: Set up Artifact Hub
        run: |
          curl --fail --location https://github.com/artifacthub/hub/releases/download/v1.20.0/ah_1.20.0_linux_amd64.tar.gz --output /tmp/ah.tar.gz
          echo "9027626f19ff9f3ac668f222917130ac885e289e922e1428bfd2e7f066324e31  /tmp/ah.tar.gz" | shasum --check
          sudo tar --extract --file /tmp/ah.tar.gz --directory /usr/local/bin ah

      - name: Set up Git
        run: |
          git config --global user.name "${GITHUB_ACTOR}"
          git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"

      - name: Checkout code
        uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
        with:
          fetch-depth: 0

      - name: Lint chart
        run: |
          ct lint --config .ct.yaml
          ah lint --path charts/ingress-nginx

      - name: Release chart
        uses: helm/chart-releaser-action@cae68fefc6b5f367a0275617c9f83181ba54714f # v1.7.0
        env:
          CR_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          CR_RELEASE_NAME_TEMPLATE: helm-chart-{{ .Version }}
          CR_SKIP_EXISTING: true
        with:
          charts_dir: charts
