Skip to content

ci: add commitlint GitHub Actions #4440

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Marukome0743
Copy link
Contributor

@Marukome0743 Marukome0743 commented Jun 4, 2025

Description

This PR adds a new GitHub Actions workflow that enforces Conventional Commit message conventions by installing dependencies, building the code, and validating commits on pushes, pull requests, and manual triggers.

File-Level Changes
Change Details Files
Define a new commitlint workflow with triggers and permissions
  • Create .github/workflows/commitlint.yml
  • Configure triggers for push, pull_request, and workflow_dispatch
  • Grant read access to repository contents
.github/workflows/commitlint.yml
Set up environment and build steps
  • Checkout repository with full history (fetch-depth: 0)
  • Install Node via actions/setup-node with yarn caching
  • Run yarn install and yarn build
  • Print versions of git, node, npm, yarn, and commitlint
.github/workflows/commitlint.yml
validate commits
  • Run commitlint on the last commit for pushes and manual dispatches
  • Run commitlint across the PR commit range for pull_request events
.github/workflows/commitlint.yml

Motivation and Context

Introduce a Conventional Commitlint workflow to enforce commit message conventions.
Why doesn't official repo check the commit message?

Usage examples

name: Conventional Commitlint

on:
  push:
  pull_request:
  workflow_dispatch:

permissions:
  contents: read

jobs:
  commitlint:
    name: Commitlint
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
        with:
          fetch-depth: 0

      - name: Setup Node
        uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
        with:
          node-version: lts/*
          cache: yarn

      - name: Install dependencies
        run: yarn install --frozen-lockfile

      - name: Build packages
        run: yarn build

      - name: Print versions
        run: |
          git --version
          node --version
          npm --version
          yarn --version
          yarn commitlint --version

      - name: Validate current commit (last commit) with commitlint
        if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
        run: yarn commitlint --last --verbose

      - name: Validate PR commits with commitlint
        if: github.event_name == 'pull_request'
        run: yarn commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose
Sequence Diagram for the Commit Validation Process
sequenceDiagram
    actor Dev as Developer
    participant GH as GitHub
    participant GHA as GitHub Actions
    participant CW as Commitlint Workflow

    Dev->>GH: Push commit(s) / Create PR / Dispatch workflow
    GH->>GHA: Trigger "Conventional Commitlint" workflow
    GHA->>CW: Start job "Commitlint"
    CW->>CW: Checkout code
    CW->>CW: Setup Node.js
    CW->>CW: Install dependencies (yarn)
    CW->>CW: Build packages (yarn)
    alt if event is 'push' or 'workflow_dispatch'
        CW->>CW: Validate last commit (commitlint --last)
    else if event is 'pull_request'
        CW->>CW: Validate PR commits (commitlint --from BASE --to HEAD)
    end
    alt Commit messages are valid
        CW-->>GHA: Report Success for "Commitlint" job
    else Commit messages are invalid
        CW-->>GHA: Report Failure for "Commitlint" job
    end
    GHA-->>GH: Update CI Status (e.g., on PR checks)
    GH-->>Dev: Display CI Status & Logs
Loading

How Has This Been Tested?

My forked repo and this commit's test were succeeded.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Copy link

codesandbox-ci bot commented Jun 4, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Comment on lines 41 to 43
- name: Create commitlint.config.js
run: |
echo "export default { extends: ['@commitlint/config-conventional'] };" > commitlint.config.js
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it already present at

commitlint/package.json

Lines 28 to 33 in 8a295f0

"commitlint": {
"extends": [
"@commitlint/config-conventional",
"@commitlint/config-workspace-scopes"
]
},
?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is.
I removed the Create commitlint.config.js step.

cache: yarn

- name: Install dependencies
run: yarn install --ignore-engines --frozen-lockfile
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
run: yarn install --ignore-engines --frozen-lockfile
run: yarn install --frozen-lockfile

Alreay set at

--install.ignore-engines true

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, deleted.

@JounQin
Copy link
Collaborator

JounQin commented Jun 4, 2025

Personally I never use a separate workflow for commitlint on CI, and we've already have husky to ensure the commit message at

node @commitlint/cli/lib/cli.js --edit $1

@Marukome0743
Copy link
Contributor Author

Personally I never use a separate workflow for commitlint on CI, and we've already have husky to ensure the commit message at

node @commitlint/cli/lib/cli.js --edit $1

You are right. but, some PRs don't follow the rules.
For example, you can create a PR through Git GUI tools such as SourceTree without checking husky.
My opinion is this CI isn't redundant under the specific conditions.

@JounQin
Copy link
Collaborator

JounQin commented Jun 4, 2025

For example, you can create a PR through Git GUI tools such as SourceTree without checking husky.
My opinion is this CI isn't redundant under the specific conditions.

And that's totally fine for users to contribute easily, the final committed message will follow our rules when we merge those PRs.

@Marukome0743
Copy link
Contributor Author

For example, you can create a PR through Git GUI tools such as SourceTree without checking husky.
My opinion is this CI isn't redundant under the specific conditions.

And that's totally fine for users to contribute easily, the final committed message will follow our rules when we merge those PRs.

Wow, sounds nice!
Thank you very much whether this PR is merged or not!

@escapedcat
Copy link
Member

I guess it depends on how strict the org is and why you need a specific commit message format. And what consequences you have to deal with if a "wrong" messages is being merged.

In our case we haven't been strict and (mostly) update wrong messages when a PR is being merged.

The value I would see in this PR is that we would dogfood our own docs, which might be good to see if things are working as expected?

@escapedcat
Copy link
Member

Personally I never use a separate workflow for commitlint on CI, and we've already have husky to ensure the commit message at [...]

Currently I do not work on any project using commitlint at all 😅

@JounQin
Copy link
Collaborator

JounQin commented Jun 4, 2025

The value I would see in this PR is that we would dogfood our own docs, which might be good to see if things are working as expected?

Such dogfooding would make contributing to this project more difficult as I mentioned.

Currently I do not work on any project using commitlint at all 😅

Oh, really? I'm using it in all my projects. 🤣

@Marukome0743
Copy link
Contributor Author

The value I would see in this PR is that we would dogfood our own docs, which might be good to see if things are working as expected?

I quite agree.
It's very useful for the outsiders like me because I can feel like how commitlint works before use.

Currently I do not work on any project using commitlint at all 😅

The most of contributors are so polite and wise that commitlint isn't needed but, it ensures the quality of commit message.

@Marukome0743
Copy link
Contributor Author

The value I would see in this PR is that we would dogfood our own docs, which might be good to see if things are working as expected?

Such dogfooding would make contributing to this project more difficult as I mentioned.

I see your points.
In this project, the most of users would understand the importance of conventional commit since the people who do not know about it will not come here.
So, I think the enforcement of conventional commit doesn't inhibit the new contribution.

@JounQin
Copy link
Collaborator

JounQin commented Jun 4, 2025

since the people who do not know about it will not come here.

Then how those false postive PRs came from?

@Marukome0743
Copy link
Contributor Author

since the people who do not know about it will not come here.

Then how those false postive PRs came from?

Umm... I'm not sure...
That might be default value of GitHub commits.

I felt that the importance of this issue might depend on whether you value the user or the contributor.

@JounQin I am very appreciative of your input.
I'm newbie in this field so I believe you are right.

I was very happy to hear how the maintainers use commitlint in their works.
Anyway, it's OK to close this PR, thanks!

@JounQin
Copy link
Collaborator

JounQin commented Jun 4, 2025

I felt that the importance of this issue might depend on whether you value the user or the contributor.

The contributors are also the users at the same time. ❤️

@escapedcat
Copy link
Member

I feel like it could be a nice way to point people at a working (CI) example as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants