Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/semantic-pull-request.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@

## Overview

Validate pull request titles with the same commitlint policy as the shared linter.
Validate pull request titles with the repository's commitlint policy.

The lint-pull-request-title action runs on Node.js and reads the repository's root commitlint config.
It falls back to `@commitlint/config-conventional` when no rules are configured.
It falls back to the bundled `@hoverkraft/commitlint-config` when no rules are configured.
Contributor and bot titles use the same repository rules; warnings produce annotations.
The action owns its dependencies and installs them from its lockfile with lifecycle scripts disabled.
Git-generated messages are not exempt by default; repository ignore settings take precedence.
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/semantic-pull-request.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Validate pull request titles with the same commitlint policy as the shared linter.
# Validate pull request titles with the repository's commitlint policy.
#
# The lint-pull-request-title action runs on Node.js and reads the repository's root commitlint config.
# It falls back to `@commitlint/config-conventional` when no rules are configured.
# It falls back to the bundled `@hoverkraft/commitlint-config` when no rules are configured.
# Contributor and bot titles use the same repository rules; warnings produce annotations.
# The action owns its dependencies and installs them from its lockfile with lifecycle scripts disabled.
# Git-generated messages are not exempt by default; repository ignore settings take precedence.
Expand Down
2 changes: 1 addition & 1 deletion actions/quality/lint-pull-request-title/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
## Overview

Validate the event's pull request title using the checked-out repository's commitlint config.
Fall back to `@commitlint/config-conventional` when no rules are configured.
Fall back to the bundled `@hoverkraft/commitlint-config` when no rules are configured.
The same repository rules apply to people and bots; warnings produce annotations.
Requires a pull request event and a repository checkout.
Dependencies are installed from the action's lockfile with lifecycle scripts disabled.
Expand Down
2 changes: 1 addition & 1 deletion actions/quality/lint-pull-request-title/action.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Lint pull request title
description: |
Validate the event's pull request title using the checked-out repository's commitlint config.
Fall back to `@commitlint/config-conventional` when no rules are configured.
Fall back to the bundled `@hoverkraft/commitlint-config` when no rules are configured.
The same repository rules apply to people and bots; warnings produce annotations.
Requires a pull request event and a repository checkout.
Dependencies are installed from the action's lockfile with lifecycle scripts disabled.
Expand Down
15 changes: 14 additions & 1 deletion actions/quality/lint-pull-request-title/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion actions/quality/lint-pull-request-title/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"@commitlint/config-conventional": "21.2.4",
"@commitlint/format": "21.2.3",
"@commitlint/lint": "21.2.4",
"@commitlint/load": "21.2.4"
"@commitlint/load": "21.2.4",
"@hoverkraft/commitlint-config": "0.0.2"
},
"engines": {
"node": ">=24.0.0"
Expand Down
2 changes: 1 addition & 1 deletion actions/quality/lint-pull-request-title/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export async function run({
config = await load(
{
extends: [
fileURLToPath(import.meta.resolve("@commitlint/config-conventional")),
fileURLToPath(import.meta.resolve("@hoverkraft/commitlint-config")),
],
},
{ cwd },
Expand Down
46 changes: 31 additions & 15 deletions actions/quality/lint-pull-request-title/src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import { run } from "./index.js";
const conventionalPreset = fileURLToPath(
import.meta.resolve("@commitlint/config-conventional"),
);
const sharedPreset = fileURLToPath(
import.meta.resolve("@hoverkraft/commitlint-config"),
);

function workspace(t) {
const directory = mkdtempSync(join(tmpdir(), "title-policy-"));
Expand All @@ -25,16 +28,11 @@ const cases = [
["feature", "feat: add a shared validator", true],
["breaking change", "feat(api)!: require a release tag", true],
["dependency update", "build(deps): bump a dependency", true],
[
"uppercase subject",
"build(deps): Bump a dependency",
false,
"subject-case",
],
["uppercase subject", "build(deps): Bump a dependency", true, "subject-case"],
["unknown type", "unknown: add a validator", false, "type-enum"],
["missing subject", "fix:", false, "subject-empty"],
["trailing period", "fix: add a validator.", false, "subject-full-stop"],
["long header", "fix: ".padEnd(101, "x"), false, "header-max-length"],
["long header", "fix: ".padEnd(101, "x"), true, "header-max-length"],
["generated merge", "Merge pull request #1 from example/branch", false],
["generated revert", 'Revert "feat: add a validator"', false],
["version", "v1.2.3", false],
Expand All @@ -43,7 +41,7 @@ const cases = [
];

for (const [name, title, valid, rule] of cases) {
test(`conventional fallback: ${name}`, async (t) => {
test(`shared policy fallback: ${name}`, async (t) => {
// Arrange
const cwd = workspace(t);
const core = reporter();
Expand All @@ -56,6 +54,7 @@ for (const [name, title, valid, rule] of cases) {
assert.equal(core.setFailed.mock.callCount(), valid ? 0 : 1);
if (rule) {
assert.ok(core.info.mock.calls[0].arguments[0].includes(rule));
assert.equal(core.warning.mock.callCount(), valid ? 1 : 0);
}
});
}
Expand Down Expand Up @@ -96,11 +95,7 @@ test("repository warnings apply equally to contributors and bots", async (t) =>
writeFileSync(
join(cwd, ".commitlintrc.json"),
JSON.stringify({
extends: [conventionalPreset],
rules: {
"subject-case": [1, "never", ["sentence-case"]],
"header-max-length": [1, "always", 100],
},
extends: [sharedPreset],
}),
);
for (const actor of ["contributor", "dependabot[bot]", "renovate[bot]"]) {
Expand Down Expand Up @@ -152,6 +147,28 @@ test("repository errors still fail when other rules only warn", async (t) => {
assert.equal(core.warning.mock.callCount(), 1);
});

test("repository severity overrides remain blocking", async (t) => {
const cwd = workspace(t);
writeFileSync(
join(cwd, ".commitlintrc.json"),
JSON.stringify({
extends: [sharedPreset],
rules: { "subject-case": [2, "never", ["sentence-case"]] },
}),
);
const core = reporter();
await run({
core,
context: {
payload: { pull_request: { title: "build(deps): Bump a dependency" } },
},
cwd,
});
assert.equal(core.setFailed.mock.callCount(), 1);
assert.match(core.info.mock.calls[0].arguments[0], /subject-case/);
assert.equal(core.warning.mock.callCount(), 0);
});

test("loads relative presets and repository plugins from a JavaScript config", async (t) => {
// Arrange
const cwd = workspace(t);
Expand Down Expand Up @@ -238,8 +255,7 @@ test("resolves the bundled preset without installing repository dependencies", (
writeFileSync(
join(cwd, ".commitlintrc.json"),
JSON.stringify({
extends: ["@commitlint/config-conventional"],
rules: { "subject-case": [1, "never", ["sentence-case"]] },
extends: ["@hoverkraft/commitlint-config"],
}),
);

Expand Down
44 changes: 30 additions & 14 deletions docs/usage/commits.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,25 @@ Use commitlint's standard configuration formats, such as `.commitlintrc.json`,
Keep one configuration source. Extend a preset and override only the rules that
need different behavior. See the [commitlint configuration reference](https://commitlint.js.org/reference/configuration.html).

For repositories using Dependabot, see this repository's
[commitlint configuration](../../.commitlintrc.json). It keeps conventional types
and required subjects blocking while reporting casing and line lengths as warnings.

These overrides belong to the repository. The image and title workflow do not
change their severity. A repository can choose stricter rules.
The [title action](../../actions/quality/lint-pull-request-title/README.md) bundles
[`@hoverkraft/commitlint-config`](https://github.com/hoverkraft-tech/commitlint-config)
and uses it when no rules are configured. A repository can also extend it explicitly:

```json
{
"extends": ["@hoverkraft/commitlint-config"]
}
```

The Super-Linter image supplies the conventional preset as a fallback when no
configuration is found. The title action follows commitlint's `--default-config`
behavior: it uses the conventional preset when configuration resolves to no rules.
The shared preset keeps conventional types, required subjects and whitespace rules
blocking. Subject casing and line lengths produce warnings for all authors.
Repository overrides take precedence, including stricter severity settings.
Invalid configuration and missing presets fail validation.

The Super-Linter image supplies `@commitlint/config-conventional` as
its fallback. See this repository's [configuration](../../.commitlintrc.json) for
matching warning severities. Additional presets must be available to the image.

## Local and CI validation

Call both shared workflows and keep their versions aligned. Grant `contents: read`
Expand All @@ -42,9 +49,11 @@ changes in that PR take effect after merging. No secrets are required.

The standalone [lint-pull-request-title action](../../actions/quality/lint-pull-request-title/README.md)
requires a checkout when called directly. It owns its locked dependencies and
installs them with lifecycle scripts disabled. The bundled conventional preset is
available without installing the repository's dependencies. Install any additional
presets or plugins before calling the action. Relative presets resolve from the
installs them with lifecycle scripts disabled. The bundled shared and conventional
presets are available without a root npm manifest or repository dependency installation.
The action release pins their versions. Locally installed presets take precedence;
install dependencies first when the repository's lockfile must select the version.
Install additional presets or plugins before calling the action. Relative presets resolve from the
repository configuration. Repository rules, parser settings, plugins and ignore
settings are respected. Git-generated messages are not exempt as PR titles unless
the repository explicitly configures that behavior. Warnings appear as GitHub
Expand All @@ -55,15 +64,16 @@ Use the same Super-Linter image version in local linting and CI. Run the reposit
warnings in Super-Linter, and leave `ENABLE_COMMITLINT_STRICT_MODE` disabled if warnings
should remain nonblocking. Node.js projects with a local `commit-msg` hook need
`@commitlint/cli` and their configured presets installed; let the hook discover the
same root configuration.
same root configuration. Follow the [preset usage guide](https://github.com/hoverkraft-tech/commitlint-config/blob/main/docs/usage/commits.md)
for local installation.

Merge settings must preserve a validated conventional message. If squash merging
is enabled, use the validated PR title for the resulting commit. A passing title
check does not validate edits made to the merge message afterward.

## Dependency updates

Configure each Dependabot ecosystem with its supported message options:
Configure every Dependabot ecosystem with explicit message options:

```yaml
commit-message:
Expand All @@ -77,4 +87,10 @@ or commit-body lines may exceed the preset's length limits. Configure the desire
severity in the repository's commitlint rules. Updating the Dependabot configuration
does not rewrite existing commits.

Nx workspaces keep `@commitlint/config-nx-scopes` after the shared preset in
`extends`. Install workspace dependencies before calling the title action so Nx
can discover project scopes. For these repositories, omit Dependabot's
`include: scope`: its `deps` and `deps-dev` scopes are not Nx project names.
An unscoped `build:` update remains valid without weakening scope validation.

For Renovate, enable semantic commits and use `build` as `semanticCommitType`.
Loading