From 6a1e435d0ab9a9d49318dbe4dd1345cc26e92fcb Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Sep 2023 20:55:18 +0200 Subject: [PATCH 1/3] Add pre-commit flow --- .pre-commit-config.yaml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..a55ef9b --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,33 @@ +--- +files: ^(.*\.(py|json|md|sh|yaml|cfg|txt))$ +exclude: ^(\.[^/]*cache/.*|.*/_user.py)$ +repos: + - repo: https://github.com/executablebooks/mdformat + # Do this before other tools "fixing" the line endings + rev: 0.7.17 + hooks: + - id: mdformat + name: Format Markdown + entry: mdformat # Executable to run, with fixed options + language: python + types: [markdown] + args: [--wrap, '75', --number] + additional_dependencies: + - mdformat-toc + - mdformat-beautysh + # -mdformat-shfmt + # -mdformat-tables + - mdformat-config + - mdformat-black + - mdformat-web + - mdformat-gfm + - repo: https://github.com/codespell-project/codespell + rev: v2.2.5 + hooks: + - id: codespell + args: + # - --builtin=clear,rare,informal,usage,code,names,en-GB_to_en-US + - --builtin=clear,rare,informal,usage,code,names + - --ignore-words-list=aci,master,jupyter,lite,ws,wan,hass,cmak,aks,tim,offen + - --skip="./.*" + - --quiet-level=2 From 7d65d2c644722ad2e78c7d92b8d188e240c22305 Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 21 Sep 2023 21:27:38 +0200 Subject: [PATCH 2/3] Add more spelling exceptions --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a55ef9b..58aa198 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,6 +28,6 @@ repos: args: # - --builtin=clear,rare,informal,usage,code,names,en-GB_to_en-US - --builtin=clear,rare,informal,usage,code,names - - --ignore-words-list=aci,master,jupyter,lite,ws,wan,hass,cmak,aks,tim,offen + - --ignore-words-list=aci,master,jupyter,lite,ws,wan,hass,cmak,aks,tim,offen,som,iterm - --skip="./.*" - --quiet-level=2 From 147b8a68cfe6feb15676dc1def6a5a1620428faf Mon Sep 17 00:00:00 2001 From: MDW Date: Sun, 14 Jan 2024 22:19:34 +0100 Subject: [PATCH 3/3] ci: Add workflow (check spelling, formatting excluded) --- .codespellrc | 5 +++ .github/workflows/pre-commit.yml | 66 ++++++++++++++++++++++++++++++++ .pre-commit-config.yaml | 6 --- 3 files changed, 71 insertions(+), 6 deletions(-) create mode 100644 .codespellrc create mode 100644 .github/workflows/pre-commit.yml diff --git a/.codespellrc b/.codespellrc new file mode 100644 index 0000000..51147b5 --- /dev/null +++ b/.codespellrc @@ -0,0 +1,5 @@ +[codespell] +builtin=clear,rare,informal,usage,code,names +ignore-words-list=aci,master,jupyter,lite,ws,wan,hass,cmak,aks,tim,offen,som,iterm,man-in-the-middle +skip="./.*" +quiet-level=2 diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 0000000..05372a2 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,66 @@ +--- +name: pre-commit +on: + pull_request: + push: +jobs: + pre-commit: + runs-on: ubuntu-latest + env: + LOG_TO_CS: .github/logToCs.py + RAW_LOG: pre-commit.log + CS_XML: pre-commit.xml + steps: + - name: Install required tools + run: sudo apt-get update && sudo apt-get install cppcheck + if: false + # Checkout git sources to analyze + - uses: actions/checkout@v4 + # Needed to ensuire expected file exists + - name: Create requirements.txt if no requirements.txt or pyproject.toml + run: |- + [ -r requirements.txt ] || [ -r pyproject.toml ] || touch requirements.txt + # Install python and pre-commit tool + - uses: actions/setup-python@v4 + with: + cache: pip + python-version: '3.11' + - run: python -m pip install pre-commit + # Restore previous cache of precommit + - uses: actions/cache/restore@v4 + with: + path: ~/.cache/pre-commit/ + key: pre-commit-4|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }} + # Run all the precommit tools (defined into pre-commit-config.yaml). We can force exclusion of some of them here. + - name: Run pre-commit hooks + env: + # SKIP is used by pre-commit to not execute certain hooks + SKIP: mdformat + 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/logToCheckStyle@v2024.2.9 + if: ${{ failure() }} + with: + in: ${{ env.RAW_LOG }} + + # Save the precommit cache + - uses: actions/cache/save@v4 + if: ${{ ! cancelled() }} + with: + path: ~/.cache/pre-commit/ + key: pre-commit-4|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') + }} + # Upload result log files of precommit into the Artifact shared store + - name: Provide log as artifact + uses: actions/upload-artifact@v3 + if: ${{ always() }} + with: + name: precommit-logs + path: | + ${{ env.RAW_LOG }} + ${{ env.CS_XML }} + retention-days: 2 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 58aa198..47c8723 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -25,9 +25,3 @@ repos: rev: v2.2.5 hooks: - id: codespell - args: - # - --builtin=clear,rare,informal,usage,code,names,en-GB_to_en-US - - --builtin=clear,rare,informal,usage,code,names - - --ignore-words-list=aci,master,jupyter,lite,ws,wan,hass,cmak,aks,tim,offen,som,iterm - - --skip="./.*" - - --quiet-level=2