name: Release Charts

on:
  push:
    branches:
      - main
    paths:
      - "charts/**"

jobs:
  release:
    runs-on: ubuntu-22.04
    steps:
      - name: Add workspace as safe directory
        run: |
          git config --global --add safe.directory /__w/FHIRFLARE-IG-Toolkit/FHIRFLARE-IG-Toolkit

      - name: Checkout
        uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
        with:
          fetch-depth: 0

      - name: Configure Git
        run: |
          git config user.name "$GITHUB_ACTOR"
          git config user.email "$GITHUB_ACTOR@users.noreply.github.com"

      - name: Update dependencies
        run: find charts/ ! -path charts/ -maxdepth 1 -type d -exec helm dependency update {} \;

      - name: Add Helm Repositories
        run: |
          helm repo add hapifhir https://hapifhir.github.io/hapi-fhir-jpaserver-starter/
          helm repo update

      - name: Run chart-releaser
        uses: helm/chart-releaser-action@be16258da8010256c6e82849661221415f031968 # v1.5.0
        with:
          config: .github/ct/config.yaml
        env:
          CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
