You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Due to pre-commit limitations, pre-commit commitlint must be run on all commits in the CI instead of just branch commits
If you are adamant about only running on branch commits, you should probably install and run commitlint without pre-commit. Below are some potential ideas for "from" refs, depending on your platform.
Original notes:
Due to pre-commit limitations, there is currently no good way to run this thing in CI. It should be run against new commits using commitlint --from=my-ref, not all commits. But we would need to specify the "from" ref. pre-commit does not support passing CLI arguments to hook commands and --from-ref and --to-refdo not support running hooks that do not take files (anything other than commitlint --edit). We would really need support for hooks that do not take files.
Here are some opinionated ideas that may or may not work:
Best right now: Forget pre-commit for this in CI. Get a LTS node environment, parse the tool versions out of the pre-commit config to avoid differences between local and CI runs, install the tools, and run commitlint directly with your "from" ref.
Theoretical best: --from-ref works!!!
Theoretical best given pre-commit limitations: Allow commitlint to run on a git log file either by implementing it in commitlint (unlikely) or writing a wrapper program that calls commitlint many times and aggregates the results. Then call pre-commit once with such a file.
Easiest: Use pre-commit to run commitlint on all commits using commitlint --from. The pre-commit hook for this is not yet implemented here. Use the commitlint-all hook. See the README for details.
Maybe: Use an environment variable like so FROM=my-ref pre-commit run [...] then somehow get it in your hook commitlint --from=$FROM.
Very unlikely: Maybe come up with a fancy git hack to limit the refs available to commitlint, then run a pre-commit hook that runs commitlint on "all" commits.
For completeness, here are some ideas for running commitlint against a range of commits since I find the commitlint CI Setup Guide to be lacking in this regard:
From refs
Local: the base commit from the source branch (which is probably main); so --from="$(git merge-base --fork-point main)"
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
TL;DR
Original notes:
Due to pre-commit limitations, there is currently no good way to run this thing in CI. It should be run against new commits using
commitlint --from=my-ref
, not all commits. But we would need to specify the "from" ref. pre-commit does not support passing CLI arguments to hook commands and--from-ref
and--to-ref
do not support running hooks that do not take files (anything other thancommitlint --edit
). We would really need support for hooks that do not take files.Here are some opinionated ideas that may or may not work:
--from-ref
works!!!git log
file either by implementing it in commitlint (unlikely) or writing a wrapper program that calls commitlint many times and aggregates the results. Then call pre-commit once with such a file.git log
output to files, call pre-commit once for each file, and aggregate the results. Seepre-commit run
gets all refs regardless of--from-ref
pre-commit/pre-commit#3056 (comment).commitlint --from
.The pre-commit hook for this is not yet implemented here.Use the commitlint-all hook. See the README for details.FROM=my-ref pre-commit run [...]
then somehow get it in your hookcommitlint --from=$FROM
.For completeness, here are some ideas for running commitlint against a range of commits since I find the commitlint CI Setup Guide to be lacking in this regard:
From refs
main
); so--from="$(git merge-base --fork-point main)"
$GITHUB_BASE_SHA
$CI_MERGE_REQUEST_DIFF_BASE_SHA
Beta Was this translation helpful? Give feedback.
All reactions