Skip to content

Commit

Permalink
Replace some checks by pre commits hooks
Browse files Browse the repository at this point in the history
To use more standards tools
  • Loading branch information
sbrunner committed Jan 12, 2023
1 parent 72f391a commit 9d907f1
Show file tree
Hide file tree
Showing 37 changed files with 637 additions and 2,180 deletions.
15 changes: 15 additions & 0 deletions .github/jsonschema-precommit
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash -eux

pip install --requirement=requirements.txt
make jsonschema

for f in config.md applications.md; do
for c in trailing-whitespace prettier; do
pre-commit run --files=$f $c > /dev/null || true
done
done
for f in c2cciutils/configuration.py c2cciutils/applications_definition.py; do
for c in black isort pyupgrade; do
pre-commit run --files=$f $c > /dev/null || true
done
done
5 changes: 5 additions & 0 deletions .github/renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
prConcurrentLimit: 0,
lockFileMaintenance: { enabled: true, automerge: true, schedule: 'on the first day of the month' },
baseBranches: ['master', '1.4', '1.3', '1.2', '1.1'],
'pre-commit': { enabled: true },
regexManagers: [
{
fileMatch: ['^.pre-commit-config.yaml$'],
matchStrings: [" +- '?(?<depName>[^' @=]+)(@|==)(?<currentValue>[^' @=]+)'? # (?<datasource>.+)"],
},
{
fileMatch: ['^c2cciutils/applications-versions.yaml$'],
matchStrings: [
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/changelog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ jobs:
- uses: actions/checkout@v3

- run: echo "${HOME}/.local/bin" >> ${GITHUB_PATH}
- run: cd c2cciutils; npm install
- run: python3 -m pip install --user --requirement=requirements.txt
- run: poetry build
- run: python3 -m pip install --user --force-reinstall dist/c2cciutils-0.0.0-py3-none-any.whl[checks]
Expand Down
16 changes: 13 additions & 3 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,28 @@ jobs:
if: env.HAS_SECRETS == 'HAS_SECRETS'

- run: echo "${HOME}/.local/bin" >> ${GITHUB_PATH}
- run: cd c2cciutils; npm install
- run: python3 -m pip install --user --requirement=requirements.txt
- run: poetry build
env:
POETRY_DYNAMIC_VERSIONING_BYPASS: 0.0.0
- run: python3 -m pip install --user --force-reinstall dist/c2cciutils-0.0.0-py3-none-any.whl[checks,publish]
- run: rm -rf dist build

- uses: actions/cache@v3
with:
path: ~/.cache/pre-commit
key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
restore-keys: "pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}\npre-commit-"
- run: pre-commit run --all-files

- name: Environment
run: c2cciutils-env
env:
GITHUB_EVENT: ${{ toJson(github) }}
- name: Checks
run: c2cciutils-checks
env:
GITHUB_EVENT: ${{ toJson(github) }}

- name: Build
run: make build
Expand Down Expand Up @@ -81,7 +93,6 @@ jobs:
fetch-depth: 0

- run: echo "${HOME}/.local/bin" >> ${GITHUB_PATH}
- run: cd c2cciutils; npm install
- run: python3 -m pip install --user --requirement=requirements.txt
- run: poetry build
env:
Expand Down Expand Up @@ -125,7 +136,6 @@ jobs:
github-gopass-ci-token: ${{secrets.GOPASS_CI_GITHUB_TOKEN}}

- run: python3 -m pip install --user --requirement=requirements.txt
- run: cd c2cciutils; npm install
- run: ~/.local/bin/poetry build
env:
POETRY_DYNAMIC_VERSIONING_BYPASS: 0.0.0
Expand Down
104 changes: 104 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
repos:
- repo: local
hooks:
- id: jsonschema
name: jsonschema
language: python
files: ^c2cciutils/schema.*\.json$
types:
- json
pass_filenames: false
entry: .github/jsonschema-precommit
- id: check-poetry
name: poetry check
description: Validates the structure of the pyproject.toml file
entry: poetry check
language: python
additional_dependencies:
- poetry==1.2.1
pass_filenames: false
files: ^pyproject\.toml$
- id: lock-poetry
name: poetry lock
description: Lock the from the pyproject.toml file
entry: poetry lock --no-update
language: python
additional_dependencies:
- poetry==1.2.1
pass_filenames: false
files: ^pyproject\.toml$
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: detect-private-key
- id: check-merge-conflict
- id: check-ast
- id: debug-statements
- id: check-toml
- id: check-yaml
- id: check-json
- id: end-of-file-fixer
- id: trailing-whitespace
- id: mixed-line-ending
- repo: https://github.com/sbrunner/pre-commit-copyright
rev: 0.1.4
hooks:
- id: copyright
- repo: https://github.com/codespell-project/codespell
rev: v2.2.2
hooks:
- id: codespell
exclude: ^(.*/)?poetry\.lock$
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.7.1
hooks:
- id: prettier
additional_dependencies:
- prettier@2.8.1 # npm
- prettier-plugin-sh@0.12.8 # npm
- prettier-plugin-toml@0.3.1 # npm
- '@prettier/plugin-xml@0.12.0' # npm
- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.9.0.2
hooks:
- id: shellcheck
- repo: https://github.com/jumanjihouse/pre-commit-hooks
rev: 3.0.0
hooks:
- id: git-check
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.20.0
hooks:
- id: check-github-workflows
- id: check-renovate
additional_dependencies:
- pyjson5==1.6.2 # pypi
- repo: https://github.com/sirwart/ripsecrets
rev: v0.1.5
hooks:
- id: ripsecrets
- repo: https://github.com/psf/black
rev: 22.12.0
hooks:
- id: black
- repo: https://github.com/PyCQA/isort
rev: 5.11.4
hooks:
- id: isort
- repo: https://github.com/PyCQA/autoflake
rev: v2.0.0
hooks:
- id: autoflake
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args:
- --py38-plus
- repo: https://github.com/PyCQA/prospector
rev: v1.8.4
hooks:
- id: prospector
args:
- --tool=pydocstyle
- --die-on-tool-error
28 changes: 28 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
- id: workflows-require-timeout
name: workflows require timeout
description: Check that the workflows have a timeout
entry: c2cciutils-checks
args:
- --check=workflow
files: ^\.github/workflows/.+\.ya?ml$
language: python
- id: check-poetry
name: poetry check
description: Validates the structure of the pyproject.toml file
entry: poetry check
language: python
additional_dependencies:
- poetry
pass_filenames: false
files: ^pyproject\.toml$
- id: lock-poetry
name: poetry lock
description: Lock the from the pyproject.toml file
entry: poetry lock
args:
- --no-update
language: python
additional_dependencies:
- poetry
pass_filenames: false
files: ^pyproject\.toml$
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,3 @@ jsonschema: ## Generate files depends on the JSON schema
jsonschema-gentypes
jsonschema2md c2cciutils/schema.json config.md
jsonschema2md c2cciutils/schema-applications.json applications.md
c2cciutils-checks --fix --check=prettier
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ The goals of C2C CI utils are:
- Git attributes
- That the timeout is present in the GitHub workflow files
- That the stabilization version (get from the Security.md) are used everywhere it's needed
- Check the code style:
- End of files
- Check the code style with [pre-commit](https://pre-commit.com):
- Black
- Isort
- Code spell
- Prettier
- ...
- Snyk tests
- Test (never failed)
- Code test (never failed, disabled by default)
Expand Down Expand Up @@ -374,3 +374,12 @@ volumePermissions.enabled: 'true'
```

See also: [Parameters documentations](https://github.com/bitnami/charts/tree/master/bitnami/postgresql#parameters).

## Contributing

Install the pre-commit hooks:

```bash
pip install pre-commit
pre-commit install
```
6 changes: 4 additions & 2 deletions c2cciutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def print_versions(config: c2cciutils.configuration.PrintVersions) -> bool:
config: The print configuration
"""

for version in config.get("versions", []):
for version in config.get("versions", c2cciutils.configuration.PRINT_VERSIONS_VERSIONS_DEFAULT):
try:
sys.stdout.flush()
sys.stderr.flush()
Expand Down Expand Up @@ -565,7 +565,7 @@ def get_codespell_command(config: c2cciutils.configuration.Configuration, fix: b
config: The full configuration
fix: If we should fix the errors
"""
codespell_config = config.get("checks", {}).get("codespell", {})
codespell_config = config.get("codespell", {})
codespell_config = codespell_config if isinstance(codespell_config, dict) else {}
command = ["codespell"]
if fix:
Expand All @@ -592,4 +592,6 @@ def snyk_exec() -> Tuple[str, Dict[str, str]]:
if "SNYK_ORG" in env:
subprocess.run(["snyk", "config", "set", f"org={env['SNYK_ORG']}"], check=True, env=env)

if not os.path.exists(os.path.join(os.path.dirname(os.path.abspath(__file__)), "node_modules")):
subprocess.run(["npm", "install"], check=True, cwd=os.path.dirname(os.path.abspath(__file__)))
return os.path.join(os.path.dirname(os.path.abspath(__file__)), "node_modules/snyk/bin/snyk"), env
Loading

0 comments on commit 9d907f1

Please sign in to comment.