-
-
Notifications
You must be signed in to change notification settings - Fork 185
Description
Motivation
There is a nice service for pre-commit called https://pre-commit.ci/.
I do not think that prek should copy or reimplement this feature.
However, it would be beneficial if prek could be used more naturally within a CI/CD pipeline, as this would reduce duplicated configuration.
Current Behaviour
At the moment, I can already run:
prek run --all-files
within my CI/CD script.
By default, this runs hooks that either have no stages definition (defaulting to all stages) or explicitly include the pre-commit stage.
For my use case, I would like to skip a specific hook within CI/CD because it is already checked by another job.
pre-commit.ci supports this via ci.skip.
Currently, I can work around this by running:
prek run --all-files --hook-type manual
in CI and configuring hooks like this:
repos:
- repo: 'git@something'
rev: '1.6.1'
hooks:
- id: 'lint'
stages: ['pre-push', 'manual']
- id: 'format'
stages: ['pre-commit', 'manual']
- id: 'test'
stages: ['pre-push']However, for someone reading this configuration and knowing it is executed in CI/CD, this is confusing.
The manual stage semantically suggests the opposite of CI/CD.
Click to view old suggestion
Suggested Behaviour (Old)
Therefore, I suggest adding a dedicated ci hook stage for this use case.
The intention would then be clear when running:
prek run --hook-type ci
Example configuration:
repos:
- repo: 'git@something'
rev: '1.6.1'
hooks:
- id: 'lint'
stages: ['pre-push', 'ci']
- id: 'format'
stages: ['pre-commit', 'ci']
- id: 'test'
stages: ['pre-commit']This is a small change, but it would encourage and simplify the use of prek in CI/CD environments.
Suggested Behaviour (new)
As @pygarap pointed out, a good solution for this problem would be the introduction of "groups".
Example Configuration
repos:
- repo: 'git@something'
rev: '1.6.1'
hooks:
- id: 'lint'
groups: ['ci']
stages: ['pre-push']
- id: 'format'
groups: ['ci']
- id: 'test'
stages: ['pre-push']Now we could just run prek run --all-files --group ci
Group should be repeatable:
prek run --all-files --group ci --group lint --group test
It might be nice to add a --exclude-group:
prek run --all-files --exclude-group format
To be noted --group (incl. --exlcude-group and --hook-type should be mutually exclusive.
Once a group is selected hook stages are ignored for the selection which hook to run.