name: Commitlint

on:
  pull_request:
    branches:
      - main

concurrency:
  group: ${{ github.workflow }}-${{ github.head_ref }}
  cancel-in-progress: true

permissions:
  contents: read

jobs:
  commitlint:
    runs-on: ubuntu-22.04
    timeout-minutes: 5
    steps:
      - name: Check out Git repository
        uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
        with:
          # by default this only fetches the latest commit,
          # but more commits are needed to validate a range of commit messages
          fetch-depth: 0

      - name: Set up Node.js environment
        uses: ./.github/actions/setup-node-env

      - name: Validate commit messages
        run: yarn commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }}
