Use CircleCI version 2.1 at the top of your .circleci/config.yml file.
1
version: 2.1
Add the orbs
stanza below your version, invoking the orb:
1
2
orbs:
commitlint: conventional-changelog/commitlint@1.0.0
Use commitlint
elements in your existing workflows and jobs.
Opt-in to use of uncertified orbs on your organization’s Security settings page.
Add the `commitlint/lint` job to your existing workflow to quickly and easily begin linting your commit mesages. Ensure you have first added your `commitlint.config.js` file to your project.
1
2
3
4
5
6
7
version: '2.1'
orbs:
commitlint: conventional-changelog/commitlint@1.0
workflows:
my-workflow:
jobs:
- commitlint/lint
Add this lint job to your workflow to easily enable commit message lint checking as a step in your CI process.
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
config-path | Path to commitlint config file | No | ./commitlint.config.js | string |
configs | A space-separated list of commitlint config packages to install. | No | '@commitlint/config-conventional' | string |
max-count | The maximum number of commits to lint. | No | 10 | integer |
node-version | Specify the NodeJS version used to run the commitlint job. This should not usually need to be changed. | No | 16.5.0 | string |
target-branch | Commits in the current branch will be compared against the target branch for linting. All commits not present in the target branch will be linted. | No | main | string |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# This code is licensed from CircleCI to the user under the MIT license.
# See here for details: https://circleci.com/developer/orbs/licensing
version: 2.1
description: |
commitlint helps your team adhere to a standard commit convention. Add commit message linting to your CI process to prevent non-standard commit messages from being merged, and provide contrinbutors with details for resolving their PR.
display:
home_url: https://commitlint.js.org/
source_url: https://github.com/conventional-changelog/commitlint
jobs:
lint:
description: |
Add this lint job to your workflow to easily enable commit message lint checking as a step in your CI process.
docker:
- image: cimg/node:<<parameters.node-version>>
parameters:
config-path:
default: ./commitlint.config.js
description: Path to commitlint config file
type: string
configs:
default: '@commitlint/config-conventional'
description: A space-separated list of commitlint config packages to install.
type: string
max-count:
default: 10
description: The maximum number of commits to lint.
type: integer
node-version:
default: 16.5.0
description: Specify the NodeJS version used to run the commitlint job. This should not usually need to be changed.
type: string
target-branch:
default: main
description: Commits in the current branch will be compared against the target branch for linting. All commits not present in the target branch will be linted.
type: string
steps:
- checkout
- run:
command: |
#!/bin/bash
if ! command -v commitlint &> /dev/null
then
if [[ $EUID == 0 ]]; then export SUDO=""; else export SUDO="sudo"; fi
$SUDO npm install -g @commitlint/cli "$CL_PARAM_CONFIGS"
fi
current_branch="$(git rev-parse --abbrev-ref HEAD)"
target_branch="$CL_PARAM_TARGET_BRANCH"
git_log="$(git log --reverse --max-count="$CL_PARAM_MAX_COUNT" --format="format:%H")"
if [ -z "$git_log" ]; then
echo "[WARNING] There are no commits in the log to lint."
exit 0
fi
# If there is only one commit, set target_head to that commit
if [ "$(echo "$git_log" | wc -l | xargs)" == "1" ]; then
target_head=""
elif [ "$current_branch" != "$target_branch" ]; then
# Using the ^ at the end git logs lower bound is not inclusive
target_head="$(git cherry "$target_branch" | head -1 | cut -d " " -f2-)^"
else
commit="$(echo "$git_log" | head -1)"
target_head="$(git log "$commit^" -1 --pretty=%H)"
fi
commitlint --verbose --config "$CL_PARAM_CONFIG_PATH" --from="$target_head"
environment:
CL_PARAM_CONFIG_PATH: <<parameters.config-path>>
CL_PARAM_CONFIGS: <<parameters.configs>>
CL_PARAM_MAX_COUNT: <<parameters.max-count>>
CL_PARAM_NODE_VERSION: <<parameters.node-version>>
CL_PARAM_TARGET_BRANCH: <<parameters.target-branch>>
name: Run commitlint
examples:
lint_all_commits:
description: |
Add the `commitlint/lint` job to your existing workflow to quickly and easily begin linting your commit mesages.
Ensure you have first added your `commitlint.config.js` file to your project.
usage:
version: "2.1"
orbs:
commitlint: conventional-changelog/commitlint@1.0
workflows:
my-workflow:
jobs:
- commitlint/lint