-
-
Notifications
You must be signed in to change notification settings - Fork 1
build(commitlint): enforce Conventional Commit messages locally and in CI #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
35c7662
build(commitlint): enforce Conventional Commit messages with the same…
math3usmartins 9ee2234
ci(commitlint): gate pull requests on Conventional Commit messages
math3usmartins 90cee57
fix(commitlint): reinstall stale node_modules and require the compose…
math3usmartins 06810ec
fix(commitlint): run the node service behind a compose profile
math3usmartins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| #!/bin/sh | ||
| # Commit-message lint: the SAME tool CI runs — commitlint over | ||
| # commitlint.config.mjs — executed through the docker compose `node` service, | ||
| # so contributors need docker but no host Node toolchain. | ||
| # | ||
| # Installed by `composer install` via `git config core.hooksPath .githooks`. | ||
| # The message is piped on stdin (comment lines stripped, as git would on | ||
| # commit), so no path mapping into the container is needed and the hook works | ||
| # from worktrees too. node_modules is (re)installed from the lockfile whenever | ||
| # it's missing or stale, so the local commitlint always matches the pinned one. | ||
|
|
||
| msg_file="$1" | ||
|
|
||
| if ! command -v docker > /dev/null 2>&1; then | ||
| echo "commit-msg: docker is required to lint the commit message (compose service 'node')." >&2 | ||
| echo " rules: commitlint.config.mjs (Conventional Commits) — CI enforces the same check." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # `command -v docker` isn't enough: this hook runs `docker compose run`, which | ||
| # needs the Compose v2 plugin. Without it, Docker prints its own cryptic | ||
| # "'compose' is not a docker command" — surface a useful message instead. | ||
| if ! docker compose version > /dev/null 2>&1; then | ||
| echo "commit-msg: the Docker Compose v2 plugin is required ('docker compose' is unavailable)." >&2 | ||
| echo " rules: commitlint.config.mjs (Conventional Commits) — CI enforces the same check." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| top=$(git rev-parse --show-toplevel) | ||
|
|
||
| # Reinstall when node_modules is absent OR the lockfile is newer than the | ||
| # installed binary — a version bump a collaborator pulls in updates | ||
| # package-lock.json but leaves node_modules untouched, and a stale local | ||
| # commitlint would silently disagree with CI. `npm ci` is otherwise skipped so | ||
| # the common case (already installed) stays fast. | ||
| sed -e 's/\r$//' -e '/^#/d' "$msg_file" \ | ||
| | docker compose --project-directory "$top" run --rm -T --no-deps node sh -c ' | ||
| if [ ! -x node_modules/.bin/commitlint ] || [ package-lock.json -nt node_modules/.bin/commitlint ]; then | ||
| npm ci --no-audit --no-fund --loglevel=error | ||
| fi | ||
| exec node_modules/.bin/commitlint | ||
| ' | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| name: Commitlint | ||
|
|
||
| # Gate every PR on Conventional Commit messages. Same tool, same version, same | ||
| # config as the local .githooks/commit-msg hook: commitlint pinned by | ||
| # package-lock.json, rules in commitlint.config.mjs. | ||
|
|
||
| on: | ||
| pull_request: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: ci-${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| commitlint: | ||
| name: Conventional commit messages | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| # commitlint needs the full PR range, not a shallow tip. | ||
| fetch-depth: 0 | ||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| # Keep in step with the compose `node` service image. | ||
| node-version: 24 | ||
| cache: npm | ||
| - name: Install commitlint (lockfile-pinned) | ||
| run: npm ci --no-audit --no-fund | ||
| - name: Lint PR commit messages | ||
| run: > | ||
| npx --no-install commitlint | ||
| --from ${{ github.event.pull_request.base.sha }} | ||
| --to ${{ github.event.pull_request.head.sha }} | ||
| --verbose |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,3 +13,4 @@ | |
| /core/.xphp-cache/ | ||
| docker-compose.override.yml | ||
| .phpunit.result.cache | ||
| node_modules/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // Commit-message rules: Conventional Commits (https://www.conventionalcommits.org). | ||
| // One rule set, one tool, two entry points: | ||
| // - locally: .githooks/commit-msg runs commitlint through the docker compose | ||
| // `node` service (installed by `composer install`) | ||
| // - in CI: .github/workflows/commitlint.yml runs the same lockfile-pinned | ||
| // commitlint over every PR commit | ||
| // | ||
| // The stock preset already matches this repo's history: | ||
| // type(scope): lowercase subject | ||
| // with types build/chore/ci/docs/feat/fix/perf/refactor/revert/style/test, an | ||
| // optional free-form scope (monomorphize, specializer, parser, cli, ...), a | ||
| // 100-char header cap, and merge/revert/fixup subjects ignored. | ||
| export default { | ||
| extends: ['@commitlint/config-conventional'], | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.