Skip to content

Commit 1f52133

Browse files
committedSep 14, 2021
feat: initial orb release [semver:major]
1 parent 71d8c6b commit 1f52133

24 files changed

+314
-396
lines changed
 

Diff for: ‎.circleci/config.yml

+15-30
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ orbs:
44
# Replace this with your own!
55
commitlint: conventional-changelog/commitlint@<<pipeline.parameters.dev-orb-version>>
66
orb-tools: circleci/orb-tools@10.0
7-
bats: circleci/bats@1.0
87
shellcheck: circleci/shellcheck@2.0
8+
bats: circleci/bats@1.0
9+
node: circleci/node@4.7.0
910

1011
# Pipeline Parameters
1112
## These parameters are used internally by orb-tools. Skip to the Jobs section.
@@ -22,18 +23,6 @@ parameters:
2223
type: string
2324
default: "dev:alpha"
2425

25-
jobs:
26-
# Define one or more jobs which will utilize your orb's commands and parameters to validate your changes.
27-
integration-test-1:
28-
docker:
29-
- image: cimg/base:stable
30-
steps:
31-
- checkout
32-
# "greet" is a sample command packaged with this orb config.
33-
# This sample integration test will run as long as the greet command exists. Once you remove the greet command you should remove this line.
34-
# Push new changes first, before adding new tests to your config.
35-
- commitlint/greet
36-
3726
workflows:
3827
# Prior to producing a development orb (which requires credentials) basic validation, linting, and even unit testing can be performed.
3928
# This workflow will run on every commit
@@ -45,51 +34,47 @@ workflows:
4534
- shellcheck/check:
4635
dir: ./src/scripts
4736
exclude: SC2148
48-
# optional: Run BATS tests against your scripts
4937
- bats/run:
38+
exec_environment: node/default
5039
path: ./src/tests
40+
pre-steps:
41+
- run:
42+
name: Git Config
43+
command: |
44+
mkdir -p ~/.config/yarn
45+
sudo chown -R circleci ~/.config/
46+
sudo chgrp -R circleci ~/.config/
47+
git config --global user.email "communitypartner@circleci.com"
48+
git config --global user.name "CPE Team"
5149
# Publish development version(s) of the orb.
5250
- orb-tools/publish-dev:
5351
orb-name: conventional-changelog/commitlint
5452
context: orb-publishing # A restricted context containing your private publishing credentials. Will only execute if approved by an authorized user.
5553
requires:
5654
- orb-tools/lint
5755
- orb-tools/pack
58-
- bats/run
5956
- shellcheck/check
57+
- bats/run
6058
# Trigger an integration workflow to test the
6159
# dev:${CIRCLE_SHA1:0:7} version of your orb
6260
- orb-tools/trigger-integration-tests-workflow:
6361
name: trigger-integration-dev
6462
context: orb-publishing
6563
requires:
6664
- orb-tools/publish-dev
67-
68-
# This `integration-test_deploy` workflow will only run
69-
# when the run-integration-tests pipeline parameter is set to true.
70-
# It is meant to be triggered by the "trigger-integration-tests-workflow"
71-
# job, and run tests on <your orb>@dev:${CIRCLE_SHA1:0:7}.
7265
integration-test_deploy:
7366
when: << pipeline.parameters.run-integration-tests >>
7467
jobs:
75-
# Run any integration tests defined within the `jobs` key.
76-
- integration-test-1
77-
# Publish a semver version of the orb. relies on
78-
# the commit subject containing the text "[semver:patch|minor|major|skip]"
79-
# as that will determine whether a patch, minor or major
80-
# version will be published or if publishing should
81-
# be skipped.
82-
# e.g. [semver:patch] will cause a patch version to be published.
68+
- commitlint/lint
8369
- orb-tools/dev-promote-prod-from-commit-subject:
8470
orb-name: conventional-changelog/commitlint
8571
context: orb-publishing
8672
add-pr-comment: false
8773
fail-if-semver-not-indicated: true
8874
publish-version-tag: false
8975
requires:
90-
- integration-test-1
76+
- commitlint/lint
9177
filters:
9278
branches:
9379
only:
94-
- master
9580
- main

Diff for: ‎.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# orb.yml is "packed" from source, and not published directly from the repository.
2-
orb.yml
2+
orb.yml
3+
node_modules/

Diff for: ‎CHANGELOG.md

-19
This file was deleted.

Diff for: ‎README.md

+29-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,39 @@
1-
# Orb Project Template
1+
# commitlint orb
22

33
[![CircleCI Build Status](https://circleci.com/gh/conventional-changelog/commitlint-orb.svg?style=shield "CircleCI Build Status")](https://circleci.com/gh/conventional-changelog/commitlint-orb) [![CircleCI Orb Version](https://badges.circleci.com/orbs/conventional-changelog/commitlint.svg)](https://circleci.com/orbs/registry/orb/conventional-changelog/commitlint) [![GitHub License](https://img.shields.io/badge/license-MIT-lightgrey.svg)](https://raw.githubusercontent.com/conventional-changelog/commitlint-orb/master/LICENSE) [![CircleCI Community](https://img.shields.io/badge/community-CircleCI%20Discuss-343434.svg)](https://discuss.circleci.com/c/ecosystem/orbs)
44

55

66

7-
A starter template for orb projects. Build, test, and publish orbs automatically on CircleCI with [Orb-Tools](https://circleci.com/orbs/registry/orb/circleci/orb-tools).
7+
Lint your commit messages in a CircleCI job.
88

9-
Additional READMEs are available in each directory.
9+
Add this orb's `commitlint/lint` job to your existing CircleCI workflow to utilize [commitlint](https://github.com/conventional-changelog/commitlint) for validating commit messages against the [conventional commit format](https://conventionalcommits.org/).
1010

11+
## Example
12+
13+
This example shows importing the `commitlint` orb into a basic CircleCI 2.1 config file, and adding the `commitlint/lint` job to a workflow. This configuration will lint every commit pushed to the repository.
14+
15+
```yaml
16+
version: 2.1
17+
orbs:
18+
# Use the latest version of the orb.
19+
# See the Orb Registry, or GitHub Releases
20+
commitlint: conventional-changelog/commitlint@<latest version>
21+
workflows:
22+
my-workflow:
23+
jobs:
24+
- commitlint/lint
25+
```
26+
27+
CircleCI will report back the status of the `commitlint/lint` job and block a Pull Request from being merged if the job fails.
28+
29+
## Run the commitlint orb locally
30+
Want to test out the commitlint orb in your CI pipeline before pushing your changes? Use the CircleCI CLI to run any job defined in your `.circleci/config.yml` locally, including jobs from orbs.
31+
32+
Assuming your config file looks similar to the example above, and you have the [CircleCI CLI](https://circleci.com/docs/2.0/local-cli/) installed, you can run this orb for the current project locally with the following command.
33+
34+
```shell
35+
circleci local execute --job commitlint/lint
36+
```
1137

1238

1339
## Resources

Diff for: ‎commitlint.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {extends: ['@commitlint/config-conventional']}

Diff for: ‎src/@orb.yml

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
version: 2.1
22

33
description: >
4-
Sample orb description
5-
# What will your orb allow users to accomplish?
6-
# Descriptions should be short, simple, and informative.
4+
commitlint helps your team adhere to a standard commit convention.
5+
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.
76
8-
# This information will be displayed in the orb registry and is not mandatory.
97
display:
10-
home_url: "https://www.website.com/docs"
11-
source_url: "https://www.github.com/EXAMPLE_ORG/EXAMPLE_PROJECT"
8+
home_url: "https://commitlint.js.org/"
9+
source_url: "https://github.com/conventional-changelog/commitlint"
1210

13-
# If your orb requires other orbs, you can import them like this. Otherwise remove the "orbs" stanza.
14-
# orbs:
15-
# hello: circleci/hello-build@0.0.5

Diff for: ‎src/README.md

-26
This file was deleted.

Diff for: ‎src/commands/README.md

-27
This file was deleted.

Diff for: ‎src/commands/greet.yml

-15
This file was deleted.

Diff for: ‎src/examples/README.md

-13
This file was deleted.

Diff for: ‎src/examples/example.yml

-13
This file was deleted.

Diff for: ‎src/examples/lint_all_commits.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
description: |
2+
Add the `commitlint/lint` job to your existing workflow to quickly and easily begin linting your commit mesages.
3+
Ensure you have first added your `commitlint.config.js` file to your project.
4+
usage:
5+
version: 2.1
6+
orbs:
7+
commitlint: conventional-changelog/commitlint@1.0
8+
workflows:
9+
my-workflow:
10+
jobs:
11+
- commitlint/lint

Diff for: ‎src/executors/README.md

-29
This file was deleted.

Diff for: ‎src/executors/default.yml

-11
This file was deleted.

Diff for: ‎src/jobs/README.md

-30
This file was deleted.

Diff for: ‎src/jobs/hello.yml

-15
This file was deleted.

Diff for: ‎src/jobs/lint.yml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
description: |
2+
Add this lint job to your workflow to easily enable commit message lint checking as a step in your CI process.
3+
4+
5+
docker:
6+
- image: "cimg/node:<<parameters.node-version>>"
7+
8+
parameters:
9+
config-path:
10+
type: string
11+
description: Path to commitlint config file
12+
default: "./commitlint.config.js"
13+
configs:
14+
type: string
15+
description: A space-separated list of commitlint config packages to install.
16+
default: "@commitlint/config-conventional"
17+
target-branch:
18+
type: string
19+
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.
20+
default: "main"
21+
node-version:
22+
type: string
23+
default: "16.5.0"
24+
description: "Specify the NodeJS version used to run the commitlint job. This should not usually need to be changed."
25+
max-count:
26+
type: integer
27+
default: 10
28+
description: "The maximum number of commits to lint."
29+
steps:
30+
- checkout
31+
- run:
32+
name: "Run commitlint"
33+
environment:
34+
CL_PARAM_CONFIG_PATH: "<<parameters.config-path>>"
35+
CL_PARAM_NODE_VERSION: "<<parameters.node-version>>"
36+
CL_PARAM_TARGET_BRANCH: "<<parameters.target-branch>>"
37+
CL_PARAM_CONFIGS: "<<parameters.configs>>"
38+
CL_PARAM_MAX_COUNT: "<<parameters.max-count>>"
39+
command: <<include(scripts/lint.sh)>>

Diff for: ‎src/scripts/README.md

-40
This file was deleted.

Diff for: ‎src/scripts/greet.sh

-10
This file was deleted.

Diff for: ‎src/scripts/lint.sh

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
if ! command -v commitlint &> /dev/null
3+
then
4+
if [[ $EUID == 0 ]]; then export SUDO=""; else export SUDO="sudo"; fi
5+
$SUDO npm install -g @commitlint/cli "$CL_PARAM_CONFIGS"
6+
fi
7+
8+
current_branch="$(git rev-parse --abbrev-ref HEAD)"
9+
target_branch="$CL_PARAM_TARGET_BRANCH"
10+
git_log="$(git log --reverse --max-count="$CL_PARAM_MAX_COUNT" --format="format:%H")"
11+
12+
if [ -z "$git_log" ]; then
13+
echo "[WARNING] There are no commits in the log to lint."
14+
exit 0
15+
fi
16+
17+
# If there is only one commit, set target_head to that commit
18+
if [ "$(echo "$git_log" | wc -l | xargs)" == "1" ]; then
19+
target_head=""
20+
elif [ "$current_branch" != "$target_branch" ]; then
21+
# Using the ^ at the end git logs lower bound is not inclusive
22+
target_head="$(git cherry "$target_branch" | head -1 | cut -d " " -f2-)^"
23+
else
24+
commit="$(echo "$git_log" | head -1)"
25+
target_head="$(git log "$commit^" -1 --pretty=%H)"
26+
fi
27+
28+
commitlint --verbose --config "$CL_PARAM_CONFIG_PATH" --from="$target_head"

Diff for: ‎src/tests/README.md

-92
This file was deleted.

Diff for: ‎src/tests/greet.bats

-13
This file was deleted.

Diff for: ‎src/tests/lint-first-commit.bats

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
setup() {
2+
cd "$BATS_SUITE_TMPDIR" || exit
3+
yarn add @commitlint/config-conventional -s
4+
5+
export git_dir="${BATS_TEST_TMPDIR}/git_dir"
6+
mkdir -p "$git_dir" && cd "$git_dir" || exit
7+
8+
git init
9+
echo "module.exports = {extends: ['@commitlint/config-conventional']}" > "commitlint.config.js"
10+
export CL_PARAM_CONFIG_PATH="commitlint.config.js"
11+
export CL_PARAM_MAX_COUNT="10"
12+
}
13+
14+
main() {
15+
bash "$BATS_TEST_DIRNAME/../../src/scripts/lint.sh"
16+
}
17+
18+
test_commit() {
19+
local message="$1"
20+
21+
echo -e "${message}\n" >> file.txt
22+
git add file.txt && git commit -m "$message"
23+
}
24+
25+
@test 'Test linting the fist bad commit' {
26+
test_commit "bad: commit"
27+
echo "Commit Created"
28+
export current_branch="$(git rev-parse --abbrev-ref HEAD)"
29+
echo "Current branch: $current_branch"
30+
export CIRCLE_BRANCH="$current_branch"
31+
export CL_PARAM_TARGET_BRANCH="$current_branch"
32+
run main
33+
[[ "$output" == *"found 1 problems, 0 warnings"* ]]
34+
[[ "$output" == *"[type-enum]"* ]]
35+
}
36+
37+
@test 'Test linting the fist good commit' {
38+
test_commit "chore: setup"
39+
40+
current_branch="$(git rev-parse --abbrev-ref HEAD)"
41+
export CIRCLE_BRANCH="$current_branch"
42+
export CL_PARAM_TARGET_BRANCH="$current_branch"
43+
44+
run main
45+
[[ "$output" == *"found 0 problems, 0 warnings"* ]]
46+
}
47+
48+
@test 'Test linting with no commits' {
49+
export CIRCLE_BRANCH="main"
50+
export CL_PARAM_TARGET_BRANCH="main"
51+
52+
run main
53+
[[ "$output" == *"[WARNING] There are no commits in the log to lint."* ]]
54+
}
55+
56+
@test 'Test linting the history on the same branch' {
57+
test_commit "bad: commit"
58+
59+
for i in {1..5}; do
60+
test_commit "chore: add $i"
61+
done
62+
63+
export current_branch="$(git rev-parse --abbrev-ref HEAD)"
64+
export CIRCLE_BRANCH="$current_branch"
65+
export CL_PARAM_TARGET_BRANCH="$current_branch"
66+
67+
run main
68+
echo "$output"
69+
[[ "$output" == *"found 1 problems, 0 warnings"* ]]
70+
[[ "$output" == *"[type-enum]"* ]]
71+
}
72+

Diff for: ‎src/tests/lint.bats

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
setup() {
2+
cd "$BATS_SUITE_TMPDIR" || exit
3+
yarn add @commitlint/config-conventional
4+
5+
export git_dir="${BATS_TEST_TMPDIR}/git_dir"
6+
mkdir -p "$git_dir" && cd "$git_dir" || exit
7+
8+
git init
9+
10+
for i in {1..5}; do
11+
test_commit "chore: add $i"
12+
done
13+
14+
target_branch="$(git rev-parse --abbrev-ref HEAD)"
15+
git checkout -b "$BATS_TEST_NAME"
16+
current_branch="$(git rev-parse --abbrev-ref HEAD)"
17+
18+
export CIRCLE_BRANCH="$current_branch"
19+
export CL_PARAM_TARGET_BRANCH="$target_branch"
20+
export CL_PARAM_CONFIG_PATH="commitlint.config.js"
21+
export CL_PARAM_MAX_COUNT="10"
22+
23+
echo "module.exports = {extends: ['@commitlint/config-conventional']}" > "commitlint.config.js"
24+
}
25+
26+
main() {
27+
bash "$BATS_TEST_DIRNAME/../../src/scripts/lint.sh"
28+
}
29+
30+
test_commit() {
31+
local message="$1"
32+
33+
echo -e "${message}\n" >> file.txt
34+
git add file.txt && git commit -m "$message"
35+
}
36+
37+
@test 'Test linting on one bad commit' {
38+
test_commit "bad: commit"
39+
40+
run main
41+
[[ "$output" == *"found 1 problems, 0 warnings"* ]]
42+
[[ "$output" == *"[type-enum]"* ]]
43+
}
44+
45+
@test 'Test linting on one good commit' {
46+
test_commit "chore: commit"
47+
48+
run main
49+
[[ "$output" == *"found 0 problems, 0 warnings"* ]]
50+
}
51+
52+
@test 'Test linting the body of a commit' {
53+
test_commit "chore: this is a commit with a long body
54+
55+
Long line in the body should fail Lorem Ipsum is simply dummy text of the printing and typesetting industry Long line in the body should fail Lorem Ipsum is simply dummy text of the printing and typesetting industry.
56+
"
57+
run main
58+
[[ "$output" == *"found 1 problems, 0 warnings"* ]]
59+
[[ "$output" == *"[body-max-line-length]"* ]]
60+
}
61+
62+
@test 'Test linting multiple commits with only one bad one' {
63+
test_commit "bad: commit"
64+
65+
for i in {1..5}; do
66+
test_commit "chore: this is a commit"
67+
done
68+
69+
run main
70+
[[ "$output" == *"found 1 problems, 0 warnings"* ]]
71+
[[ "$output" == *"[type-enum]"* ]]
72+
}
73+
74+
@test 'Test linting multiple commits that are all good' {
75+
for i in {1..10}; do
76+
test_commit "chore: this is a commit"
77+
done
78+
79+
run main
80+
[[ "$output" == *"found 0 problems, 0 warnings"* ]]
81+
}
82+
83+
@test 'Test rely bad' {
84+
for i in {1..5}; do
85+
test_commit "chore: this is a commit"
86+
done
87+
88+
for i in {1..5}; do
89+
test_commit "this is a commit commit $1"
90+
done
91+
92+
for i in {1..10}; do
93+
test_commit "chore: this is a commit"
94+
done
95+
96+
run main
97+
error_count="$(echo "${output#0}" | grep -c "found 2 problems, 0 warnings")"
98+
[[ $error_count -eq 5 ]]
99+
}
100+
101+
@test 'Test linting on the same branch' {
102+
test_commit "bad: commit"
103+
104+
for i in {1..5}; do
105+
test_commit "chore: this is a commit"
106+
done
107+
108+
export CL_PARAM_TARGET_BRANCH="$CIRCLE_BRANCH"
109+
110+
run main
111+
[[ "$output" == *"found 1 problems, 0 warnings"* ]]
112+
[[ "$output" == *"[type-enum]"* ]]
113+
}

0 commit comments

Comments
 (0)
Please sign in to comment.