Skip to content

Commit bbfaef8

Browse files
author
MDW
committed
Add pre-commit configuration and ci
1 parent 20d3032 commit bbfaef8

File tree

2 files changed

+146
-0
lines changed

2 files changed

+146
-0
lines changed

.github/workflows/pre-commit.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
name: pre-commit
3+
on:
4+
pull_request:
5+
push:
6+
jobs:
7+
pre-commit:
8+
runs-on: ubuntu-latest
9+
env:
10+
RAW_LOG: pre-commit.log
11+
CS_XML: pre-commit.xml
12+
steps:
13+
- run: sudo apt-get update && sudo apt-get install cppcheck uncrustify
14+
- name: Add backports repository, install from there
15+
run: |
16+
echo "deb http://archive.ubuntu.com/ubuntu $(lsb_release -cs)-backports main restricted universe multiverse" | sudo tee /etc/apt/sources.list.d/backports.list
17+
sudo apt-get update
18+
sudo apt-get install -y --no-install-recommends -t $(lsb_release -cs)-backports cppcheck uncrustify
19+
- uses: actions/checkout@v4
20+
- run: python -m pip install pre-commit
21+
- uses: actions/cache/restore@v4
22+
with:
23+
path: ~/.cache/pre-commit/
24+
key: pre-commit-4|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
25+
- name: Run pre-commit hooks
26+
env:
27+
SKIP: no-commit-to-branch
28+
run: |
29+
set -o pipefail
30+
pre-commit gc
31+
pre-commit run --show-diff-on-failure --color=always --all-files | tee ${RAW_LOG}
32+
- name: Convert Raw Log to Checkstyle format (launch action)
33+
uses: mdeweerd/[email protected]
34+
if: ${{ failure() }}
35+
with:
36+
in: ${{ env.RAW_LOG }}
37+
# out: ${{ env.CS_XML }}
38+
- uses: actions/cache/save@v4
39+
if: ${{ ! cancelled() }}
40+
with:
41+
path: ~/.cache/pre-commit/
42+
key: pre-commit-4|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
43+
- name: Provide log as artifact
44+
uses: actions/upload-artifact@v4
45+
if: ${{ ! cancelled() }}
46+
with:
47+
name: precommit-logs
48+
path: |
49+
${{ env.RAW_LOG }}
50+
${{ env.CS_XML }}
51+
retention-days: 2

.pre-commit-config.yaml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
---
2+
exclude:
3+
(?x)^(
4+
__NONE__)$
5+
repos:
6+
- repo: https://github.com/executablebooks/mdformat
7+
# Do this before other tools "fixing" the line endings
8+
rev: 0.7.22
9+
hooks:
10+
- id: mdformat
11+
name: Format Markdown
12+
stages: [manual]
13+
entry: mdformat # Executable to run, with fixed options
14+
language: python
15+
types: [markdown]
16+
args: [--wrap, '75', --number]
17+
additional_dependencies:
18+
- mdformat-toc
19+
- mdformat-gfm
20+
- mdformat-beautysh
21+
- repo: https://github.com/pre-commit/pre-commit-hooks
22+
rev: v5.0.0
23+
hooks:
24+
# - id: no-commit-to-branch
25+
# args: [--branch, main]
26+
- id: debug-statements
27+
- id: end-of-file-fixer
28+
exclude: ^(tests/.*)$
29+
- id: trailing-whitespace
30+
exclude: ^(tests/.*|.*\.md)$
31+
- id: check-json
32+
- id: mixed-line-ending
33+
exclude: ^(tests/.*)$
34+
- id: check-builtin-literals
35+
args: [--ignore=dict]
36+
- id: check-ast
37+
- id: check-merge-conflict
38+
- id: check-executables-have-shebangs
39+
- id: check-shebang-scripts-are-executable
40+
exclude: ^(test/.*)$
41+
- id: check-docstring-first
42+
- id: fix-byte-order-marker
43+
exclude: ^(tests/.*)$
44+
- id: check-case-conflict
45+
- id: check-toml
46+
- repo: https://github.com/lovesegfault/beautysh.git
47+
rev: v6.2.1
48+
hooks:
49+
- id: beautysh
50+
args: [--indent-size=4]
51+
exclude: (?x)^(test/test\..*|config/missing|configure|autogen.sh)$
52+
additional_dependencies:
53+
- setuptools
54+
- repo: https://github.com/codespell-project/codespell
55+
rev: v2.4.1
56+
hooks:
57+
- id: codespell
58+
args:
59+
- -L
60+
- secur,te
61+
# - --toml
62+
# - pyproject.toml
63+
additional_dependencies:
64+
- tomli
65+
- repo: https://github.com/pocc/pre-commit-hooks
66+
rev: v1.3.5
67+
# Install dependencies on windows:
68+
# choco install llvm uncrustify cppcheck
69+
hooks:
70+
- id: uncrustify
71+
exclude: ^(tests/.*|documentation/.*)$
72+
args: [--replace, --no-backup, -c, uncrustify.cfg]
73+
- id: cppcheck
74+
exclude: ^(tests/.*|documentation/.*)$
75+
args:
76+
- --force
77+
- --language=c
78+
- --std=c99
79+
- -Isrc
80+
- '--template={file}({line}): {severity} ({id}): {message}'
81+
- --inline-suppr
82+
- --check-level=exhaustive
83+
- --suppress=unusedFunction
84+
- --suppress=unmatchedSuppression
85+
- id: cpplint
86+
exclude: ^(tests/.*|documentation/.*)$
87+
args: ["--filter=-build/header_guard,-legal/copyright,-whitespace/indent,-whitespace/newline,-whitespace/braces,-whitespace/comments,-whitespace/line_length,-whitespace/parens,-build/include_order,-readability/todo,-readability/fn_size,-build/include_subdir"]
88+
additional_dependencies:
89+
- cpplint>=1.6.1
90+
- repo: https://github.com/shellcheck-py/shellcheck-py
91+
rev: v0.10.0.1
92+
hooks:
93+
- id: shellcheck
94+
# exclude: (?x)^(__NONE__)$
95+
# args: [-x,-e1007,-e1009,-e1072,-e1073]

0 commit comments

Comments
 (0)