diff --git a/.github/workflows/semantic-pull-request.md b/.github/workflows/semantic-pull-request.md index f2aa13e5..c3aadb9b 100644 --- a/.github/workflows/semantic-pull-request.md +++ b/.github/workflows/semantic-pull-request.md @@ -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. diff --git a/.github/workflows/semantic-pull-request.yml b/.github/workflows/semantic-pull-request.yml index c5862a49..2209ab1e 100644 --- a/.github/workflows/semantic-pull-request.yml +++ b/.github/workflows/semantic-pull-request.yml @@ -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. diff --git a/actions/quality/lint-pull-request-title/README.md b/actions/quality/lint-pull-request-title/README.md index c9c51234..90eaeaa9 100644 --- a/actions/quality/lint-pull-request-title/README.md +++ b/actions/quality/lint-pull-request-title/README.md @@ -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. diff --git a/actions/quality/lint-pull-request-title/action.yml b/actions/quality/lint-pull-request-title/action.yml index 09769c6c..766b93fa 100644 --- a/actions/quality/lint-pull-request-title/action.yml +++ b/actions/quality/lint-pull-request-title/action.yml @@ -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. diff --git a/actions/quality/lint-pull-request-title/package-lock.json b/actions/quality/lint-pull-request-title/package-lock.json index 64d96a9b..a07c3f43 100644 --- a/actions/quality/lint-pull-request-title/package-lock.json +++ b/actions/quality/lint-pull-request-title/package-lock.json @@ -12,7 +12,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" @@ -235,6 +236,18 @@ "node": ">=22" } }, + "node_modules/@hoverkraft/commitlint-config": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/@hoverkraft/commitlint-config/-/commitlint-config-0.0.2.tgz", + "integrity": "sha512-dMDBDpsdgu0CEO56vuT4jkQX+6trCGN4SbGXAHLd9mBzzdNtzaJtnEcAvvycdEgxyfSWTW5NAZVTvVaDOxZEpQ==", + "license": "MIT", + "dependencies": { + "@commitlint/config-conventional": "21.2.4" + }, + "engines": { + "node": ">=24.0.0" + } + }, "node_modules/@simple-libs/stream-utils": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/@simple-libs/stream-utils/-/stream-utils-2.0.0.tgz", diff --git a/actions/quality/lint-pull-request-title/package.json b/actions/quality/lint-pull-request-title/package.json index b0176f04..f2e5a427 100644 --- a/actions/quality/lint-pull-request-title/package.json +++ b/actions/quality/lint-pull-request-title/package.json @@ -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" diff --git a/actions/quality/lint-pull-request-title/src/index.js b/actions/quality/lint-pull-request-title/src/index.js index 92e9c6e9..72765c8a 100644 --- a/actions/quality/lint-pull-request-title/src/index.js +++ b/actions/quality/lint-pull-request-title/src/index.js @@ -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 }, diff --git a/actions/quality/lint-pull-request-title/src/index.test.js b/actions/quality/lint-pull-request-title/src/index.test.js index be4325cd..fbac13ee 100644 --- a/actions/quality/lint-pull-request-title/src/index.test.js +++ b/actions/quality/lint-pull-request-title/src/index.test.js @@ -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-")); @@ -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], @@ -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(); @@ -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); } }); } @@ -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]"]) { @@ -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); @@ -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"], }), ); diff --git a/docs/usage/commits.md b/docs/usage/commits.md index e6a8a674..ff7cb3c5 100644 --- a/docs/usage/commits.md +++ b/docs/usage/commits.md @@ -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` @@ -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 @@ -55,7 +64,8 @@ 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 @@ -63,7 +73,7 @@ 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: @@ -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`.