5
0
Fork 0
mirror of https://github.com/wagoid/commitlint-github-action.git synced 2025-11-07 00:06:54 +00:00
Lints Pull Request commits with commitlint
Find a file
Wagner Santos fc3ebae709 chore(deps): upgrade commitlint packages
BREAKING CHANGE: action now runs on commitlint 18
2023-11-01 05:32:16 -03:00
.github chore(deps): update node version to 20.9.0 2023-11-01 05:26:00 -03:00
.husky chore(.husky): add husky source [skip-ci] 2022-04-15 14:11:06 +01:00
fixtures fix: use helpUrl from config when present 2021-10-11 15:46:36 -03:00
src fix: make sure action passes when event doesn't have commits fixes #746 2023-07-23 07:31:18 -03:00
.dockerignore fix: build the action with rollup 2021-07-17 12:19:13 -03:00
.eslintignore style: add ESLint ignore file to enable linting of dotfiles (#103) 2021-02-25 19:03:56 +01:00
.eslintrc.json fix: build the action with rollup 2021-07-17 12:19:13 -03:00
.gitignore fix: build the action with rollup 2021-07-17 12:19:13 -03:00
.lintstagedrc.js fix: build the action with rollup 2021-07-17 12:19:13 -03:00
.nvmrc chore(deps): update node version to 20.9.0 2023-11-01 05:26:00 -03:00
.prettierrc feat: add commitlint action 2019-10-04 00:17:29 -03:00
.versionrc.json chore: replace deprecated standard-version with commit-and-tag-version 2022-10-06 11:36:17 -03:00
action.yml chore(release): publish 5.4.3 [skip-ci] 2023-07-23 10:35:47 +00:00
babel.config.json chore(deps): update node version to 20.9.0 2023-11-01 05:26:00 -03:00
CHANGELOG.md chore(release): publish 5.4.3 [skip-ci] 2023-07-23 10:35:47 +00:00
commitlint.config.js fix: build the action with rollup 2021-07-17 12:19:13 -03:00
Dockerfile chore(deps): update node version to 20.9.0 2023-11-01 05:26:00 -03:00
entrypoint.sh fix: set workspace directory as safe in the entrypoint 2022-05-07 06:31:36 -03:00
jest.config.js fix: build the action with rollup 2021-07-17 12:19:13 -03:00
LICENSE Initial commit 2019-10-01 18:29:56 -03:00
package-lock.json chore(deps): upgrade commitlint packages 2023-11-01 05:32:16 -03:00
package.json chore(deps): upgrade commitlint packages 2023-11-01 05:32:16 -03:00
README.md docs: remove fetch-depth from instructions since it's not needed anymore 2023-07-22 09:02:38 -03:00
rollup.config.js fix: build the action with rollup 2021-07-17 12:19:13 -03:00
run.js fix: build the action with rollup 2021-07-17 12:19:13 -03:00

Commitlint Github Action

Lints Pull Request commits with commitlint.

Usage

Create a github workflow in the .github folder, e.g. .github/workflows/commitlint.yml:

name: Lint Commit Messages
on: [pull_request]

jobs:
  commitlint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: wagoid/commitlint-github-action@v5

Alternatively, you can run on other event types such as on: [push]. In that case the action will lint the push event's commit(s) instead of linting commits from a pull request. You can also combine push and pull_request together in the same workflow.

Inputs

You can supply these inputs to the wagoid/commitlint-github-action@v5 step.

configFile

The path to your commitlint config file.

Default: commitlint.config.js

If the config file doesn't exist, config-conventional settings will be loaded as a default fallback.

Details on the configuration file can be found on the commitlint website.

failOnWarnings

Whether you want to fail on warnings or not.

Default: false

failOnErrors

Whether you want to fail on errors or not. Still outputs the results, just forces the action to pass even if errors are detected.

Default: true

helpURL

Link to a page explaining your commit message convention.

default: https://github.com/conventional-changelog/commitlint/#what-is-commitlint

commitDepth

When set to a valid Integer value - X, considers only the latest X number of commits.

default: null (Equivalent to linting all commits)

token

Personal access token (PAT) used to interact with the GitHub API. By default, the automatic token provided by GitHub is used. You can see more info about GitHub's default token here.

default: ${{ github.token }}

Outputs

results

The error and warning messages for each one of the analyzed commits. This is useful if you want to use the commitlint results in a JSON format in other jobs. See the documentation on how to read JSON information from outputs.

Below you can see an example text output together with its corresponding JSON output:

You have commit messages with errors

⧗   input: wrong message
✖   subject may not be empty [subject-empty]
✖   type may not be empty [type-empty]

✖   found 2 problems, 0 warnings
ⓘ   Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint

⧗   input: chore: my message
⚠   body must have leading blank line [body-leading-blank]

⚠   found 0 problems, 1 warnings
ⓘ   Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint
[
  {
    "hash": "cb0f846f13b490c2fd17bd5ed0b6f65ba9b86c75",
    "message": "wrong message",
    "valid": false,
    "errors": ["subject may not be empty", "type may not be empty"],
    "warnings": [],
  },
  {
    "hash": "cb14483cbde23b61322ffb8d3fcdc87f514a3141",
    "message": "chore: my message\n\nsome context without leading blank line",
    "valid": true,
    "errors": [],
    "warnings": ["body must have leading blank line"],
  },
]

About extends in your config file

This is a Docker action, and was made like this so that you can run it with minimum setup, regardless of your repo's environment. It comes packed with the most famous shared configurations that you can use in your commitlint config's extends field:

Apart from the shared configurations that are included by default, you can also include extra dependencies for other configs and plugins that you want to use.

In order to do so, you can use NODE_PATH env var to make the action take those dependencies into account. Below is an example workflow that does that.

name: Lint Commit Messages
on: [pull_request]

jobs:
  commitlint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v2
        with:
          node-version: '14'
      - run: npm install
      # Run the commitlint action, considering its own dependencies and yours as well 🚀
      # `github.workspace` is the path to your repository.
      - uses: wagoid/commitlint-github-action@v5
        env:
          NODE_PATH: ${{ github.workspace }}/node_modules

💡 You can see other ways to install your dependencies (including private ones) in the Setup Node action's docs.