name: Prepare helm release
on:
  repository_dispatch:
    types: [prepare-helm-release]
jobs:
  change-app-version:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - run: |
          git config user.name github-actions
          git config user.email github-actions@github.com
      - name: Change versions
        run: |
          git checkout -b release-${{ github.event.client_payload.appversion}}
          version=$(cat charts/kafka-ui/Chart.yaml  | grep version | awk '{print $2}')
          version=${version%.*}.$((${version##*.}+1))
          sed -i "s/version:.*/version: ${version}/" charts/kafka-ui/Chart.yaml
          sed -i "s/appVersion:.*/appVersion: ${{ github.event.client_payload.appversion}}/" charts/kafka-ui/Chart.yaml
          git add  charts/kafka-ui/Chart.yaml
          git commit -m "release ${version}"
          git push --set-upstream origin release-${{ github.event.client_payload.appversion}}
      - name: Slack Notification
        uses: rtCamp/action-slack-notify@v2
        env:
          SLACK_TITLE: "release-${{ github.event.client_payload.appversion}}"
          SLACK_MESSAGE: "A new release of the helm chart has been prepared. Branch name: release-${{ github.event.client_payload.appversion}}"
          SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
