diff --git a/r2_metadata/pre-commit_autoupdate.r2.yml b/r2_metadata/pre-commit_autoupdate.r2.yml index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..38a40067ddb5fb8727c9a6b8fb277c9a8aa1c2f9 100644 --- a/r2_metadata/pre-commit_autoupdate.r2.yml +++ b/r2_metadata/pre-commit_autoupdate.r2.yml @@ -0,0 +1,12 @@ +files: + template: ../templates/python/code_quality/pre-commit-autoupdate/pre-commit-autoupdate.yml + documentation: ../templates/python/code_quality/pre-commit-autoupdate/README.md +data: + description: "Run pre-commit autoupdate on your repository" + icon: 🔄 + public: true + labels: + - Utilities + - Robustness + license: MIT + deprecated: false diff --git a/templates/python/code_quality/pre-commit-autoupdate/README.md b/templates/python/code_quality/pre-commit-autoupdate/README.md new file mode 100644 index 0000000000000000000000000000000000000000..25a8dd6cc6b218779266bc1186994a8a4dc1ed2d --- /dev/null +++ b/templates/python/code_quality/pre-commit-autoupdate/README.md @@ -0,0 +1,32 @@ +# pre-commit template + +## Objective + +Run [pre-commit autoupdate](https://pre-commit.com/#pre-commit-autoupdate) on your +project. `pre-commit` is a Python framework for managing and maintaining multi-language +pre-commit hooks. `pre-commit autoupdate` will check if your pre-commit hooks are +up-to-date. If not, an update should be performed. + +## 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-autoupdate 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"` | +| `AUTOUPDATE_CMD` | Bash commands to run pre-commit autoupdate | `"pre-commit autoupdate"` | + +## 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-autoupdate/pre-commit.yml b/templates/python/code_quality/pre-commit-autoupdate/pre-commit.yml new file mode 100644 index 0000000000000000000000000000000000000000..578528565107e244ff2aa42108aba5c0490290f0 --- /dev/null +++ b/templates/python/code_quality/pre-commit-autoupdate/pre-commit.yml @@ -0,0 +1,16 @@ +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: version_management + variables: + PYTHON_SETUP: "pip install pre-commit" + PRE_COMMIT_INSTALL: "pre-commit install" + AUTOUPDATE_CMD: "pre-commit autoupdate" + script: + - !reference [.python_install, script] + - ${PRE_COMMIT_INSTALL} + - ${AUTOUPDATE_CMD} + - git diff --exit-code