name: Merge main to develop
on:
  push:
    branches:
      - 'main'

jobs:
  Merge_main_to_develop:
    runs-on: ubuntu-latest
    permissions:
      contents: write

    steps:
      - name: Checkout develop
        uses: actions/checkout@v4
        with:
          ref: develop
          fetch-depth: 0
      - name: Merge main to develop and push
        run: |
          git config user.name '${{ secrets.BPMN_IO_USERNAME }}'
          git config user.email '${{ secrets.BPMN_IO_EMAIL }}'
          git merge -m 'Merge main to develop' --no-edit origin/main
          git push

      - name: Notify failure on Slack
        if: failure()
        uses: slackapi/slack-github-action@v2.0.0
        with:
          method: chat.postMessage
          token: ${{ secrets.SLACK_BOT_TOKEN }}
          payload: |
            channel: ${{ secrets.SLACK_CHANNEL_ID }}
            text: 'Automatic merge of <https://github.com/${{ github.repository }}/tree/${{ github.ref }}|${{ github.ref }}> to <https://github.com/${{ github.repository }}/tree/develop|${{ github.repository }}#develop> failed.'
