name: PR title lint

# Squash-merge uses the PR title as the commit subject on `main`, and
# semantic-release (conventionalcommits preset) cuts a release for
# `feat:`/`fix:`/`perf:`/`refactor:`/`build:`/`revert:`/`docs:` (see
# `.releaserc.json` releaseRules). A non-conventional title therefore lands on
# `main` and is silently skipped by the release job — so gate the title against
# the Conventional Commits grammar.
on:
  pull_request:
    types: [opened, edited, synchronize, reopened]
  # Required status checks in the `main` merge queue must ALSO report on the
  # queue's speculative `merge_group` commit, or the queue stalls forever waiting
  # for a check that only ran on the PR. A `merge_group` commit has no PR title to
  # lint (the title was already validated when the PR entered the queue), so the
  # job runs with its only step skipped and reports success — the green the queue
  # needs, without re-linting.
  merge_group:

permissions:
  pull-requests: read

jobs:
  lint-title:
    name: Conventional PR title
    runs-on: ubuntu-latest
    steps:
      - if: github.event_name == 'pull_request'
        uses: amannn/action-semantic-pull-request@v5
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          # Keep in lockstep with the semantic-release commit-analyzer preset.
          types: |
            feat
            fix
            perf
            build
            chore
            ci
            docs
            refactor
            revert
            style
            test
          requireScope: false
          subjectPattern: ^(?![A-Z]).+$
          subjectPatternError: |
            The subject "{subject}" must start with a lowercase letter.
