name: 🛡️ Check PR Title

on:
  pull_request:
    types: [opened, edited]

jobs:
  lint-pr-title:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          # Only fetch the config file from the repository
          sparse-checkout-cone-mode: false
          sparse-checkout: .commitlintrc.yml

      - name: Install dependencies
        run: npm install --global @commitlint/config-conventional commitlint

      - name: Check PR title with commitlint
        env:
          PR_TITLE: ${{ github.event.pull_request.title }}
          HELP_URL: https://github.com/wxt-dev/wxt/blob/main/CONTRIBUTING.md#conventional-pr-titles
        run: echo "$PR_TITLE" | npx commitlint --help-url $HELP_URL
