Skip to content
README.md 1.52 KiB
Newer Older
Ivan Artiukhov's avatar
Ivan Artiukhov committed
# `pre-commit`
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
> Executes all configured [pre-commit][pre-commit] hooks in the CI
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
## Getting Started
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
Include the following in `.gitlab-ci.yml`:
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
```yaml
include:
  - component: gitlab.arm.com/ci/component/pre-commit@<version>"
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
pre-commit:
  extends: .pre-commit
Ivan Artiukhov's avatar
Ivan Artiukhov committed
```

Ivan Artiukhov's avatar
Ivan Artiukhov committed
## Purpose 
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
Execute the `pre-commit` hooks as part of the `test` stage to prevent any regressions in the repository. It is
recommended to set the GitLab merge requests to [prevent merging unless the pipeline has passed][prevent-merge].
Ivan Artiukhov's avatar
Ivan Artiukhov committed

## Usage

Ivan Artiukhov's avatar
Ivan Artiukhov committed
### Image
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
The `.pre-commit` job will use the `pre-commit` container from the container registry for the same tag as the component version
used.
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
The image can be overridden with the [image][image] keyword in the `.gitlab-ci.yml`:
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
```yaml
include:
  - component: "gitlab.arm.com/ci/component/pre-commit@<version>"
    inputs: 
      image: registry.gitlab.arm.com/ci/component/pre-commit
  
job:
  extends: .pre-commit
```
### Configuration
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
`pre-commit` hooks can be added to the `.pre-commit-config.yaml`. See the [documentation][plugins] for adding plugins to the project.
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
We have a _pre-configured, recommended hooks_ at pre-commit/hooks. It is **highly recommended** to use those.
Ivan Artiukhov's avatar
Ivan Artiukhov committed

Ivan Artiukhov's avatar
Ivan Artiukhov committed
[pre-commit]: https://gitlab.arm.com/ci/component/pre-commit/-/blob/main/README.md?ref_type=heads
[plugins]: https://pre-commit.com/#plugins
[prevent-merge]: https://docs.gitlab.com/ee/user/project/merge_requests/auto_merge.html#:~:text=Select%20Settings%20%3E%20Merge%20requests.,Select%20Save.
[image]: https://docs.gitlab.com/ee/ci/yaml/#image