name: Merge main into next

on:
  push:
    branches:
      - main

jobs:
  merge-to-next:
    runs-on: ubuntu-latest

    permissions:
      contents: write

    if: "${{ contains(github.event.head_commit.message, 'ci: publish version') }}"

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Set Git user
        run: |
          git config user.name "github-actions[bot]"
          git config user.email "41898282+github-actions[bot]@users.noreply.github.com"

      - name: Merge main into next
        run: |
          git checkout next
          git merge main --no-edit
          git push origin next
