name: Package Helm Chart

on:
  push:
    branches: [main]
    paths:
      - 'Charts/**'
  pull_request:
    branches: [main]
    paths:
      - 'Charts/**'

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Install Helm
        uses: azure/setup-helm@v4
        with:
          version: v3.16.0

      - name: Lint chart
        run: helm lint Charts/entkube

  package:
    runs-on: ubuntu-latest
    needs: lint
    if: github.event_name == 'push' && github.ref == 'refs/heads/main'
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Install Helm
        uses: azure/setup-helm@v4
        with:
          version: v3.16.0

      - name: Package chart
        run: helm package Charts/entkube --destination .helm-packages/

      - name: Login to Helm OCI registry
        run: echo "${{ secrets.REGISTRY_PASSWORD }}" | helm registry login ${{ vars.REGISTRY_HOST }} --username ${{ vars.REGISTRY_USER }} --password-stdin

      - name: Push chart to OCI registry
        run: helm push .helm-packages/entkube-*.tgz oci://${{ vars.REGISTRY_HOST }}/entkube
