ci: Add commit message linting commit hook
Add `gitlint` to our `pre-commit` hooks. `gitlint` runs as a `commit-msg` hook. To run `gitlint` you can use one of the following methods: * Install as a commit message hook: `pre-commit install --hook-type commit-msg` * Run through `pre-commit` CLI on the latest commit: `pre-commit run gitlint --hook-stage commit-msg --commit-msg-filename .git/COMMIT_EDITMSG` If installing the commit hook, you must run the `pre-commit` install command above even if you've already run a plain `pre-commit install`. `pre-commit install` will not install `commit-msg` hooks by default. We can't use `pre-commit` to run `gitlint` in CI, because the default `pre-commit` hook for `gitlint` forces users to pass the `commit-msg-filename` argument, which has the following drawbacks: * We can only lint the latest commit (`.git/COMMIT_EDITMSG`) or all commits in the history (`.git/HEAD`) - we can't specify an arbitrary range of commits we want to lint. We can't lint all commits in the history in this repo, because some of them fail the `gitlint` checks. * `COMMIT_EDITMSG` isn't created in the CI env: it's an artifact created by git after editing the commit message. For those reasons we just run `gitlint` directly in CI on the range of commits from the target branch to HEAD, e.g. `origin/main..HEAD` for MRs targeting the main branch. Signed-off-by:Robert Walton <rob.walton@arm.com> Signed-off-by:
Jaeden Amero <jaeden.amero@arm.com>
Loading
Please register or sign in to comment