-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
qual: Add pre-commit configuration & action
# qual: Add pre-commit configuration & action This pre-commit configuration adds different quality checks to the repository.
- Loading branch information
Showing
2 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
--- | ||
name: pre-commit | ||
on: | ||
pull_request: | ||
push: | ||
jobs: | ||
pre-commit: | ||
runs-on: ubuntu-latest | ||
env: | ||
RAW_LOG: pre-commit.log | ||
CS_XML: pre-commit.xml | ||
steps: | ||
- run: sudo apt-get update && sudo apt-get install cppcheck | ||
if: false | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v4 | ||
if: false | ||
with: | ||
cache: pip | ||
python-version: 3.12.1 | ||
- run: python -m pip install pre-commit regex | ||
- uses: actions/cache/restore@v4 | ||
with: | ||
path: | | ||
~/.cache/pre-commit/ | ||
bash_unit | ||
key: pre-commit-4|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') | ||
}} | ||
- name: Run pre-commit hooks | ||
env: | ||
SKIP: no-commit-to-branch | ||
run: | | ||
set -o pipefail | ||
pre-commit gc | ||
pre-commit run --show-diff-on-failure --color=always --all-files | tee ${RAW_LOG} | ||
- name: Convert Raw Log to annotations | ||
uses: mdeweerd/[email protected] | ||
if: ${{ failure() }} | ||
with: | ||
in: ${{ env.RAW_LOG }} | ||
# Out can be omitted if you do not need the xml output | ||
# out: ${{ env.CS_XML }} | ||
|
||
- uses: actions/cache/save@v4 | ||
if: ${{ always() }} | ||
with: | ||
path: | | ||
~/.cache/pre-commit/ | ||
bash_unit | ||
key: pre-commit-4|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') | ||
}} | ||
- name: Provide log as artifact | ||
uses: actions/upload-artifact@v4 | ||
if: ${{ always() }} | ||
with: | ||
name: precommit-logs | ||
path: | | ||
${{ env.RAW_LOG }} | ||
${{ env.CS_XML }} | ||
retention-days: 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
--- | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.5.0 | ||
hooks: | ||
- id: no-commit-to-branch | ||
args: [--branch, master] | ||
- id: check-yaml | ||
args: [--unsafe] | ||
- id: check-json | ||
- id: mixed-line-ending | ||
- id: trailing-whitespace | ||
exclude_types: [markdown] | ||
- id: end-of-file-fixer | ||
- id: check-merge-conflict | ||
- id: check-executables-have-shebangs | ||
- id: check-shebang-scripts-are-executable | ||
exclude: ^tests/test_.*$ | ||
- id: fix-byte-order-marker | ||
- id: check-case-conflict | ||
|
||
# Beautify shell scripts | ||
- repo: https://github.com/lovesegfault/beautysh.git | ||
rev: v6.2.1 | ||
hooks: | ||
- id: beautysh | ||
exclude: (?x)^(tests/test_(.*))$ | ||
args: [-i, "2"] | ||
|
||
# Run local script | ||
- repo: local | ||
hooks: | ||
- id: local-precommit-script | ||
name: Run local script before commit if it exists | ||
language: system | ||
entry: bash -c '[ ! -x local.sh ] || ./local.sh' | ||
pass_filenames: false | ||
|
||
# Prettier (format code, only for non common files) | ||
- repo: https://github.com/pre-commit/mirrors-prettier | ||
rev: v4.0.0-alpha.8 | ||
hooks: | ||
- id: prettier | ||
stages: [manual] | ||
exclude_types: | ||
- executable | ||
- binary | ||
- shell | ||
- markdown | ||
|
||
# Check format of yaml files | ||
- repo: https://github.com/adrienverge/yamllint.git | ||
rev: v1.35.1 | ||
hooks: | ||
- id: yamllint | ||
args: | ||
- --no-warnings | ||
- -d | ||
- '{extends: relaxed, rules: {line-length: {max: 120}}}' | ||
|
||
# Execute codespell to fix typo errors (setup of codespell into dev/tools/codespell/) | ||
- repo: https://github.com/codespell-project/codespell | ||
rev: v2.2.6 | ||
hooks: | ||
- id: codespell | ||
args: | ||
- --ignore-words-list=master,als | ||
- --builtin=clear,rare,informal,usage,code,names,en-GB_to_en-US | ||
exclude_types: [image] | ||
|
||
# Check some shell scripts | ||
- repo: https://github.com/shellcheck-py/shellcheck-py | ||
rev: v0.9.0.6 | ||
hooks: | ||
- id: shellcheck | ||
args: [-W, '100'] | ||
|
||
# Run tests | ||
- repo: local | ||
hooks: | ||
- id: tests | ||
stages: [manual] | ||
name: Run tests | ||
language: system | ||
entry: bash -c "./bash_unit tests/*" | ||
pass_filenames: false |