diff --git a/r2_metadata/pre-commit.r2.yml b/r2_metadata/pre-commit.r2.yml new file mode 100644 index 0000000000000000000000000000000000000000..3d0e9b97d9f91d565450fb5a062d500ee163a5a4 --- /dev/null +++ b/r2_metadata/pre-commit.r2.yml @@ -0,0 +1,15 @@ +files: + template: ../templates/python/code_quality/pre-commit/pre-commit.yml + documentation: ../templates/python/code_quality/pre-commit/README.md +data: + description: "Run pre-commit on your repository" + icon: âš ï¸ + public: true + labels: + - Utilities + - Code Quality + - Robustness + - Security + - Spelling + license: MIT + deprecated: false diff --git a/templates/python/code_quality/pre-commit/README.md b/templates/python/code_quality/pre-commit/README.md new file mode 100644 index 0000000000000000000000000000000000000000..bad732cd987e0431e872628b2b9a4478de161c27 --- /dev/null +++ b/templates/python/code_quality/pre-commit/README.md @@ -0,0 +1,29 @@ +# pre-commit template + +## Objective + +Run [pre-commit](https://pre-commit.com/) on your project. `pre-commit` is a Python +framework for managing and maintaining multi-language pre-commit hooks. + +## How to use it + +1. Configure the `.pre-commit-config.yaml` file in your repository's root directory with + your desired hooks. +2. Include the pre-commit template in your CI/CD configuration (see quick use above). +3. If you need to customize the job, check + the [jobs customization](https://docs.r2devops.io/get-started/use-templates/#job-templates-customization). + +## Variables + +| Name | Description | Default | +|----------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------| +| `PYTHON_SETUP` | Bash commands to setup your python environment with pre-commit. | `"pip install pre-commit"` | +| `IMAGE_TAG` | The default tag for the docker image. See [Python Docker Official Image](https://hub.docker.com/_/python) for supported tags and respective Dockerfile links. | `"latest"` | +| `PRE_COMMIT_INSTALL` | Bash commands to install pre-commit. | `"pre-commit install"` | +| `PRE_COMMIT_RUN` | Bash commands to run pre-commit. | `"pre-commit run --all-files"` | + +## Configuration of pre-commit + +To add configuration to `pre-commit`, you can add a `.pre-commit-config.yaml` file to +the root of your repository. This file will be used by `pre-commit` to configure the +hooks. diff --git a/templates/python/code_quality/pre-commit/pre-commit.yml b/templates/python/code_quality/pre-commit/pre-commit.yml new file mode 100644 index 0000000000000000000000000000000000000000..e7def61cf23a2f51fdca4b22f728f330fbc540cf --- /dev/null +++ b/templates/python/code_quality/pre-commit/pre-commit.yml @@ -0,0 +1,15 @@ +include: + - remote: 'https://api.r2devops.io/job/r/gitlab/dorianturba-templates/r2devops_catalog/r2_metadata/python_install@latest.yaml' + +pre-commit: + extends: + - .python_install + stage: code_quality + variables: + PYTHON_SETUP: "pip install pre-commit" + PRE_COMMIT_INSTALL: "pre-commit install" + PRE_COMMIT_RUN: "pre-commit run --all-files" + script: + - !reference [.python_install, script] + - ${PRE_COMMIT_INSTALL} + - ${PRE_COMMIT_RUN}