name: Bump Version and Create PR

on:
  workflow_dispatch:
    inputs:
      BUMP_TYPE:
        description: "Select the bump type"
        required: true
        type: choice
        options:
          - patch
          - minor
          - major

jobs:
  bump-version:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Use Node.js 20.x
        uses: actions/setup-node@v3
        with:
          node-version: '20.x'

      - name: Install modules
        run: |
          npm ci --prefix enabler
          npm version --prefix enabler ${{ inputs.BUMP_TYPE }}

          npm ci --prefix processor
          npm version --prefix processor ${{ inputs.BUMP_TYPE }}

      - name: Commit changes
        run: |
          git config --global user.name 'github-actions[bot]'
          git config --global user.email 'github-actions[bot]@users.noreply.github.com'
          git add .
          git commit -m 'chore: bump version'

      - name: Create Pull Request
        uses: peter-evans/create-pull-request@v3
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          commit-message: "chore: bump version"
          branch: "bump-version-branch"
          title: "Bump version"
          body: "This PR bumps the version. This is executed by a GitHub Action `bump.yaml`."
          labels: "version bump"
