Skip to content

Commit 308c139

Browse files
mdeweerdpgrange
authored andcommitted
qual: Add pre-commit configuration & action
# qual: Add pre-commit configuration & action This pre-commit configuration adds different quality checks to the repository.
1 parent 439988c commit 308c139

File tree

2 files changed

+146
-0
lines changed

2 files changed

+146
-0
lines changed

.github/workflows/pre-commit.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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
14+
if: false
15+
- uses: actions/checkout@v4
16+
- uses: actions/setup-python@v4
17+
if: false
18+
with:
19+
cache: pip
20+
python-version: 3.12.1
21+
- run: python -m pip install pre-commit regex
22+
- uses: actions/cache/restore@v4
23+
with:
24+
path: |
25+
~/.cache/pre-commit/
26+
bash_unit
27+
key: pre-commit-4|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml')
28+
}}
29+
- name: Run pre-commit hooks
30+
env:
31+
SKIP: no-commit-to-branch
32+
run: |
33+
set -o pipefail
34+
pre-commit gc
35+
pre-commit run --show-diff-on-failure --color=always --all-files | tee ${RAW_LOG}
36+
- name: Convert Raw Log to annotations
37+
uses: mdeweerd/[email protected]
38+
if: ${{ failure() }}
39+
with:
40+
in: ${{ env.RAW_LOG }}
41+
# Out can be omitted if you do not need the xml output
42+
# out: ${{ env.CS_XML }}
43+
44+
- uses: actions/cache/save@v4
45+
if: ${{ always() }}
46+
with:
47+
path: |
48+
~/.cache/pre-commit/
49+
bash_unit
50+
key: pre-commit-4|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml')
51+
}}
52+
- name: Provide log as artifact
53+
uses: actions/upload-artifact@v4
54+
if: ${{ always() }}
55+
with:
56+
name: precommit-logs
57+
path: |
58+
${{ env.RAW_LOG }}
59+
${{ env.CS_XML }}
60+
retention-days: 2

.pre-commit-config.yaml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
---
2+
repos:
3+
- repo: https://github.com/pre-commit/pre-commit-hooks
4+
rev: v4.5.0
5+
hooks:
6+
- id: no-commit-to-branch
7+
args: [--branch, master]
8+
- id: check-yaml
9+
args: [--unsafe]
10+
- id: check-json
11+
- id: mixed-line-ending
12+
- id: trailing-whitespace
13+
exclude_types: [markdown]
14+
- id: end-of-file-fixer
15+
- id: check-merge-conflict
16+
- id: check-executables-have-shebangs
17+
- id: check-shebang-scripts-are-executable
18+
exclude: ^tests/test_.*$
19+
- id: fix-byte-order-marker
20+
- id: check-case-conflict
21+
22+
# Beautify shell scripts
23+
- repo: https://github.com/lovesegfault/beautysh.git
24+
rev: v6.2.1
25+
hooks:
26+
- id: beautysh
27+
exclude: (?x)^(tests/test_(.*))$
28+
args: [-i, "2"]
29+
30+
# Run local script
31+
- repo: local
32+
hooks:
33+
- id: local-precommit-script
34+
name: Run local script before commit if it exists
35+
language: system
36+
entry: bash -c '[ ! -x local.sh ] || ./local.sh'
37+
pass_filenames: false
38+
39+
# Prettier (format code, only for non common files)
40+
- repo: https://github.com/pre-commit/mirrors-prettier
41+
rev: v4.0.0-alpha.8
42+
hooks:
43+
- id: prettier
44+
stages: [manual]
45+
exclude_types:
46+
- executable
47+
- binary
48+
- shell
49+
- markdown
50+
51+
# Check format of yaml files
52+
- repo: https://github.com/adrienverge/yamllint.git
53+
rev: v1.35.1
54+
hooks:
55+
- id: yamllint
56+
args:
57+
- --no-warnings
58+
- -d
59+
- '{extends: relaxed, rules: {line-length: {max: 120}}}'
60+
61+
# Execute codespell to fix typo errors (setup of codespell into dev/tools/codespell/)
62+
- repo: https://github.com/codespell-project/codespell
63+
rev: v2.2.6
64+
hooks:
65+
- id: codespell
66+
args:
67+
- --ignore-words-list=master,als
68+
- --builtin=clear,rare,informal,usage,code,names,en-GB_to_en-US
69+
exclude_types: [image]
70+
71+
# Check some shell scripts
72+
- repo: https://github.com/shellcheck-py/shellcheck-py
73+
rev: v0.9.0.6
74+
hooks:
75+
- id: shellcheck
76+
args: [-W, '100']
77+
78+
# Run tests
79+
- repo: local
80+
hooks:
81+
- id: tests
82+
stages: [manual]
83+
name: Run tests
84+
language: system
85+
entry: bash -c "./bash_unit tests/*"
86+
pass_filenames: false

0 commit comments

Comments
 (0)