Skip to content

Commit be13641

Browse files
author
Alan Christie
committed
build: Switch to using pre-commit
1 parent d6d6f0e commit be13641

File tree

6 files changed

+144
-7
lines changed

6 files changed

+144
-7
lines changed

.cz.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
# Commitizen custom configuration.
3+
# Here we extend it to add all our recognised types into the changelog.
4+
# The default ignores pretty-much anything other than 'feat' and 'fix'.
5+
#
6+
# See the default at...
7+
# https://github.com/commitizen-tools/commitizen/
8+
# blob/095f02e6c419b60c90aa84b8cebc9e9eacc8a391/commitizen/defaults.py#L83
9+
commitizen:
10+
name: cz_customize
11+
# What's the first revision we're interested imn?
12+
# For us it's the revision we started using
13+
# enforcing the use of conventional commits.
14+
# Prior to 19.1.0 we weren't using it on every commit
15+
# and didn't have everything ready for change-logs.
16+
changelog_start_rev: 19.1.0
17+
customize:
18+
schema_pattern: "^(?P<change_type>feat|fix|perf|refactor|style|test|build|docs|ci|BREAKING CHANGE)(?:\\((?P<scope>[^()\\r\\n]*)\\)|\\()?(?P<breaking>!)?:\\s(?P<message>.*)?"
19+
commit_parser: "^(?P<change_type>feat|fix|perf|refactor|style|test|build|docs|ci|BREAKING CHANGE)(?:\\((?P<scope>[^()\\r\\n]*)\\)|\\()?(?P<breaking>!)?:\\s(?P<message>.*)?"
20+
# The changelog_pattern identifies the commit types
21+
# that will be included.
22+
# Build the changelog with 'cz ch' on the staging or production branches.
23+
changelog_pattern: "^(feat|fix|perf|refactor|style|test|build|docs|ci)?"
24+
# A mapping of type to its group name in the changelog.
25+
# We call 'feat' commits 'New Features'
26+
change_type_map:
27+
build: Build
28+
docs: Documentation
29+
feat: New Features
30+
fix: Bug Fixes
31+
perf: Performance Improvements
32+
refactor: Refactoring
33+
style: Stylistic Changes
34+
ci: CI/CD
35+
test: Testing
36+
# The order of commit types in the changelog...
37+
change_type_order:
38+
- "feat"
39+
- "fix"
40+
- "perf"
41+
- "refactor"
42+
- "style"
43+
- "test"
44+
- "build"
45+
- "ci"
46+
- "docs"

.github/workflows/build-latest.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ jobs:
4242
ansible-galaxy install -r requirements.yaml
4343
- name: Lint
4444
run: |
45-
yamllint .
46-
find . -type f -name '*.yaml.j2' -exec yamllint {} +
45+
pre-commit run --all-files
4746
ansible-lint
4847
- name: Login to DockerHub
4948
uses: docker/login-action@v1

.github/workflows/build.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ jobs:
4444
ansible-galaxy install -r requirements.yaml
4545
- name: Lint
4646
run: |
47-
yamllint .
48-
find . -type f -name '*.yaml.j2' -exec yamllint {} +
47+
pre-commit run --all-files
4948
ansible-lint
5049
- name: Build
5150
uses: docker/build-push-action@v2

.pre-commit-config.yaml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
minimum_pre_commit_version: 2.18.1
3+
exclude: ^(docs|tests|example-data|migrations|unit-test-data|VERSION)
4+
5+
repos:
6+
7+
# commit-msg hooks
8+
# ----------
9+
10+
# Conventional Commit message checker (commitizen)
11+
- repo: https://github.com/commitizen-tools/commitizen
12+
rev: master
13+
hooks:
14+
- id: commitizen
15+
stages:
16+
- commit-msg
17+
18+
# pre-commit hooks
19+
# ----------
20+
21+
# Standard pre-commit rules
22+
- repo: https://github.com/pre-commit/pre-commit-hooks
23+
rev: v4.1.0
24+
hooks:
25+
- id: check-case-conflict
26+
- id: check-docstring-first
27+
- id: check-executables-have-shebangs
28+
- id: check-shebang-scripts-are-executable
29+
- id: detect-private-key
30+
- id: end-of-file-fixer
31+
- id: trailing-whitespace
32+
args:
33+
- --markdown-linebreak-ext=md
34+
# Black (uncompromising) Python code formatter
35+
- repo: https://github.com/psf/black
36+
rev: 22.3.0
37+
hooks:
38+
- id: black
39+
args:
40+
- --target-version
41+
- py310
42+
# MyPy
43+
- repo: https://github.com/pre-commit/mirrors-mypy
44+
rev: v0.942
45+
hooks:
46+
- id: mypy
47+
files: ^operator
48+
# YAML Lint
49+
# We have to adjust this hook, whcih looks for yaml files,
50+
# because some of our files are 'disguised' and not found by
51+
# 'identify', used by pre-commit. So we basically say...
52+
# All files that end '.yaml' or '.yaml.j2'
53+
# See https://pre-commit.com/#filtering-files-with-types
54+
- repo: https://github.com/adrienverge/yamllint
55+
rev: v1.26.3
56+
hooks:
57+
- id: yamllint
58+
types:
59+
- file
60+
files: (\.yaml|\.yaml.j2)$

README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99

1010
![GitHub tag (latest SemVer pre-release)](https://img.shields.io/github/v/tag/informaticsmatters/data-manager-jupyter-operator?include_prereleases)
1111

12+
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
13+
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)
14+
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
15+
1216
This repo contains a Kubernetes _Operator_ based on the [kopf] and [kubernetes]
1317
Python packages that is used by the **Informatics Matters Data Manager API**
1418
to create Jupyter Notebooks for the Data Manager service.
@@ -22,10 +26,32 @@ By default, the operator creates instances using the Jupyter image: -
2226

2327
Prerequisites: -
2428

25-
- Python (ideally 3.9.x)
29+
- Python
2630
- Docker
2731
- A kubernetes config file
2832

33+
## Contributing
34+
The project uses: -
35+
36+
- [pre-commit] to enforce linting of files prior to committing them to the
37+
upstream repository
38+
- [Commitizen] to enforce a [Convention Commit] commit message format
39+
- [Black] as a code formatter
40+
41+
You **MUST** comply with these choices in order to contribute to the project.
42+
43+
To get started review the pre-commit utility and the conventional commit style
44+
and then set-up your local clone by following the **Installation** and
45+
**Quick Start** sections: -
46+
47+
pip install -r build-requirements.txt
48+
pre-commit install -t commit-msg -t pre-commit
49+
50+
Now the project's rules will run on every commit, and you can check the
51+
current health of your clone with: -
52+
53+
pre-commit run --all-files
54+
2955
## Building the operator (local development)
3056
The operator container, residing in the `operator` directory,
3157
is automatically built and pushed to Docker Hub using GitHub Actions.
@@ -183,6 +209,10 @@ Both are exposed in the example parameter file `example-parameters.yaml`.
183209

184210
[ansible]: https://www.ansible.com
185211
[ansible galaxy]: https://galaxy.ansible.com
212+
[black]: https://black.readthedocs.io/en/stable
186213
[certificate manager]: https://cert-manager.io/docs/installation/kubernetes/
214+
[commitizen]: https://commitizen-tools.github.io/commitizen/
215+
[conventional commit]: https://www.conventionalcommits.org/en/v1.0.0/
187216
[kopf]: https://pypi.org/project/kopf/
188217
[kubernetes]: https://pypi.org/project/kubernetes/
218+
[pre-commit]: https://pre-commit.com

build-requirements.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
ansible-lint
2-
yamllint
1+
ansible-lint == 6.0.2
2+
black == 22.3.0
3+
mypy == 0.942
4+
pre-commit == 2.18.1
5+
yamllint == 1.26.3

0 commit comments

Comments
 (0)