name: Release Helm chart

# Run this workflow manually
on:
  workflow_dispatch:
    inputs:
      chartVersion:
        description: "Helm chart version to release. eg. 0.4.1"
        required: true
      appVersion:
        description: "Operator app version without quotes, eg. 0.5.1 . If not provided, the one in Chart.yaml won't be overwritten."
        required: false

jobs:
  release-helm-chart:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4

      - name: Deploy Helm chart
        run: |
          sed -i '0,/version:.*/s//version: ${{ github.event.inputs.chartVersion }}/' chart/jenkins-operator/Chart.yaml

          if [ ${{ github.event.inputs.appVersion }} ] ; then
            sed -i '/appVersion:.*/s//appVersion: "${{ github.event.inputs.appVersion }}"/' chart/jenkins-operator/Chart.yaml
          fi

          make helm-release-latest

      # Creates pull request with new chart version
      - name: Create Pull Request
        uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v6
        with:
          commit-message: Release Helm chart ${{ github.event.inputs.chartVersion }}
          branch: helm-chart-release-${{ github.event.inputs.chartVersion }}
          title: Release ${{ github.event.inputs.chartVersion }} Helm Chart
          body: |
            Release ${{ github.event.inputs.chartVersion }} Helm Chart
