name: Conventional Commits on: pull_request: types: [opened, edited, synchronize, reopened] permissions: contents: read jobs: lint-commits: name: Commits follow Conventional Commits runs-on: ubuntu-latest steps: - uses: actions/checkout@v7 with: fetch-depth: 0 - name: Validate commit messages env: BASE_SHA: ${{ github.event.pull_request.base.sha }} HEAD_SHA: ${{ github.event.pull_request.head.sha }} run: | # Conventional Commits pattern: # [optional scope]: # # Types recognised by semantic-release (commit-analyzer defaults): # feat, fix, perf, revert, docs, style, chore, refactor, test, build, ci # # Breaking changes are signalled by appending ! before the colon: # feat!: or feat(scope)!: # # Merge commits are skipped automatically via --no-merges. # # References: # https://www.conventionalcommits.org/en/v1.0.0/ PATTERN='^(feat|fix|perf|revert|docs|style|chore|refactor|test|build|ci)(\([-a-zA-Z0-9_.,]+\))?!?: .{1,}' FAILED=0 while IFS= read -r msg; do if echo "$msg" | grep -qE "$PATTERN"; then echo "ok: $msg" else echo "::error::Commit does not follow Conventional Commits: $msg" echo "" echo " Got: $msg" echo "" echo " Expected format: [optional scope]: " echo " Examples:" echo " feat(pubsub): add subscription filter support" echo " fix(gcs): correct ETag format for multipart uploads" echo " chore: release 1.0.0" echo " feat!: remove legacy endpoint" echo "" echo " Valid types: feat, fix, perf, revert, docs, style, chore, refactor, test, build, ci" echo " See: https://www.conventionalcommits.org/en/v1.0.0/" FAILED=1 fi done < <(git log --no-merges --format="%s" "$BASE_SHA".."$HEAD_SHA") exit $FAILED