name: Publish Helm Chart
on:
  workflow_call:
    inputs:
      version:
        required: true
        type: string
    secrets:
      GH_TOKEN:
        required: true

jobs:
  publish-helm:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Set up Helm
        uses: azure/setup-helm@v4

      - name: Package Helm chart
        run: |
          mkdir -p ./helm-packages
          helm package helm \
            --version ${{ inputs.version }} \
            --app-version ${{ inputs.version }} \
            --destination ./helm-packages

      - name: Authenticate to GitHub Packages
        run: |
          echo "${{ secrets.GH_TOKEN }}" | helm registry login ghcr.io -u ${{ github.actor }} --password-stdin

      - name: Push Helm chart to GitHub Packages (OCI)
        run: |
          helm push ./helm-packages/portabase-${{ inputs.version }}.tgz oci://ghcr.io/portabase/charts