name: Helm

on:
  push:
    branches:
      - main
      - legacy

jobs:

  changes:
    runs-on: ubuntu-latest
    if: |
      (github.repository == 'kubernetes/ingress-nginx')
    outputs:
      docs: ${{ steps.filter.outputs.docs }}
      charts: ${{ steps.filter.outputs.charts }}

    steps:

      - name: Checkout
        uses: actions/checkout@v2

      - uses: dorny/paths-filter@v2
        id: filter
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          filters: |
            charts:
              - 'charts/ingress-nginx/Chart.yaml'
              - 'charts/ingress-nginx/**/*'

  chart:
    name: Release Chart
    runs-on: ubuntu-latest
    needs:
      - changes
    if: |
      (github.repository == 'kubernetes/ingress-nginx') &&
      (needs.changes.outputs.charts == 'true')

    steps:

      - name: Checkout master
        uses: actions/checkout@v2
        with:
          # Fetch entire history. Required for chart-releaser; see https://github.com/helm/chart-releaser-action/issues/13#issuecomment-602063896
          fetch-depth: 0

      - name: Setup
        shell: bash
        run: |
          git config --global user.name "$GITHUB_ACTOR"
          git config --global user.email "$GITHUB_ACTOR@users.noreply.github.com"

      - name: Run chart-releaser
        uses: helm/chart-releaser-action@v1.1.0
        env:
          CR_TOKEN: "${{ secrets.PERSONAL_TOKEN }}"
          CR_RELEASE_NAME_TEMPLATE: "helm-chart-{{ .Version }}"
        with:
          charts_dir: charts
