Using Conventional Commits in GitHub Actions

Maintaining a clear commit history is crucial in software projects. Conventional Commits provide a structured way to format commit messages, which can be enforced using GitHub Actions.

Setting Up GitHub Action

Here's an example GitHub Action to enforce Conventional Commits:

name: Conventional Commit Gate

on:
  pull_request:
    types: [opened, synchronize, reopened, edited]

permissions:
  contents: write
  issues: write
  pull-requests: write
  id-token: write

jobs:
  validate-pr-title:
    runs-on: ubuntu-latest
    steps:
      - name: Conventional Commit Gate
        uses: ytanikin/PRConventionalCommits@1.1.0
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          task_types: '["feat","fix","docs","test","ci","refactor","perf","chore","revert","release","merge","hotfix"]'

Conventional Commit Format

A Conventional Commit message follows this structure:

<type>[optional scope]: <description>
[optional body]
[optional footer(s)]

Common Types

  • feat: Adds a new feature
  • fix: Patches a bug
  • docs: Documentation changes
  • refactor: Code changes that neither fix a bug nor add a feature
  • test: Adding or updating tests
  • ci: Changes to CI configuration
  • chore: Other changes that don't modify src or test files

Examples

feat: add user login feature
fix: resolve issue with user logout
docs: update README with setup instructions

Benefits

  • Automated Changelogs: Generate changelogs from commit messages.
  • Semantic Versioning: Automate version bumps based on commit types.
  • Improved Communication: Clear and consistent commit messages.

By integrating Conventional Commits into your GitHub workflow, you ensure a maintainable and understandable commit history.