From c2c263ae9d5e7ccd670434c290a1a31fe5e0b34f Mon Sep 17 00:00:00 2001 From: MDW Date: Fri, 5 Jan 2024 20:00:40 +0100 Subject: [PATCH 1/3] ci: pre-commit & generate actions --- .github/workflows/generate.yml | 39 ++++++++++++++ .github/workflows/pre-commit.yml | 49 +++++++++++++++++ .pre-commit-config.yaml | 91 ++++++++++++++++++++++++++++++++ pyproject.toml | 18 +++++++ 4 files changed, 197 insertions(+) create mode 100644 .github/workflows/generate.yml create mode 100644 .github/workflows/pre-commit.yml create mode 100644 .pre-commit-config.yaml create mode 100644 pyproject.toml diff --git a/.github/workflows/generate.yml b/.github/workflows/generate.yml new file mode 100644 index 0000000..2d89ffc --- /dev/null +++ b/.github/workflows/generate.yml @@ -0,0 +1,39 @@ +--- +name: Generate files (documentation, autotools) +on: + push: + paths: [man.md, aclocal.m4, configure.ac] + workflow_dispatch: +jobs: + convert_via_pandoc: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + - uses: dorny/paths-filter@v2 + id: changes + with: + filters: | + man: + - 'man.md' + autotools: + - 'aclocal.m4' + - 'configure.ac' + - uses: docker://pandoc/core:2.17 + if: ${{ github.event_name == 'workflow_dispath' || steps.changes.outputs.man == 'true' }} + with: + args: -s man.md -t man -o shc.1 + - uses: docker://pandoc/core:2.17 + if: ${{ github.event_name == 'workflow_dispath' || steps.changes.outputs.man == 'true' }} + with: + args: -s man.md -t html -o man.html + - run: |- + ./autogen.sh + if: ${{ github.event_name == 'workflow_dispath' || steps.changes.outputs.autotools == 'true' }} + - name: Commit changes + if: ${{ github.event_name == 'workflow_dispath' || steps.changes.outputs.man == 'true' || steps.changes.outputs.autotools }} + run: |- + for r in $(git remote) ; do git remote get-url --all $r ; done + git config user.name github-actions + git config user.email github-actions@github.com + git commit -a -m "ci: Github Action Generate Files" + git push diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 0000000..5f4bad5 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,49 @@ +--- +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 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + cache: pip + python-version: "3.12.1" + - run: python -m pip install pre-commit + - uses: actions/cache/restore@v4 + with: + path: ~/.cache/pre-commit/ + key: pre-commit-4|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') + }} + - name: Run pre-commit hooks + 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.3.5 + if: ${{ failure() }} + with: + in: ${{ env.RAW_LOG }} + - uses: actions/cache/save@v4 + if: ${{ ! cancelled() }} + with: + path: ~/.cache/pre-commit/ + key: pre-commit-4|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') + }} + - name: Provide log as artifact + uses: actions/upload-artifact@v4 + if: ${{ ! cancelled() }} + 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 new file mode 100644 index 0000000..efaca4d --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,91 @@ +--- +exclude: + (?x)^( + configure\..*| + .cache/.* + )$ +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 + stages: [manual] + entry: mdformat # Executable to run, with fixed options + language: python + types: [markdown] + args: [--wrap, '75', --number] + additional_dependencies: + - mdformat-toc + - mdformat-gfm + - mdformat-beautysh + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.6.0 + hooks: + # - id: no-commit-to-branch + # args: [--branch, main] + - id: debug-statements + - id: end-of-file-fixer + exclude: ^(test/.*)$ + - id: trailing-whitespace + exclude: .*\.md$ + - id: check-json + - id: mixed-line-ending + - id: check-builtin-literals + args: [--ignore=dict] + - id: check-ast + - id: check-merge-conflict + - id: check-executables-have-shebangs + - id: check-shebang-scripts-are-executable + exclude: ^(test/.*)$ + - id: check-docstring-first + - id: fix-byte-order-marker + - id: check-case-conflict + - id: check-toml + - repo: https://github.com/lovesegfault/beautysh.git + rev: v6.2.1 + hooks: + - id: beautysh + exclude: ^(test/.*)$ + additional_dependencies: + - setuptools + - repo: https://github.com/codespell-project/codespell + rev: v2.3.0 + hooks: + - id: codespell + args: + - --toml + - pyproject.toml + additional_dependencies: + - tomli + - repo: https://github.com/pocc/pre-commit-hooks + rev: v1.3.5 + # Install dependencies on windows: + # choco install llvm uncrustify cppcheck + hooks: + - id: uncrustify + stages: [manual] + args: [--replace, --no-backup, -c, uncrustify.cfg] + - id: cppcheck + args: + - --force + #- --std=c99 + - --language=c + #- -IInc + - '--template={file}({line}): {severity} ({id}): {message}' + - id: cpplint + args: ["--filter=-build/header_guard,-build/include,-build/include_subdir,-legal/copyright,-readbility/casting,-readability/fn_size,-whitespace/blank_line,-whitespace/braces,-whitespace/comma,-whitespace/comments,-whitespace/line_length,-whitespace/newline,-whitespace/operators,-whitespace/parens,-whitespace/semicolon,-whitespace/tab,-whitespace/todo"] + additional_dependencies: + - cpplint>=1.6.1 + - repo: https://github.com/shellcheck-py/shellcheck-py + rev: v0.10.0.1 + hooks: + - id: shellcheck + # args: [-x,-e1007,-e1009,-e1072,-e1073] + - repo: https://github.com/pocc/pre-commit-hooks + rev: v1.3.5 + hooks: + - id: clang-format + stages: [manual] + args: [-i] diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..07d179c --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,18 @@ +[build-system] +requires = ["setuptools>=61.2"] +build-backend = "setuptools.build_meta" + +[project] +dynamic = ["version"] + +[tool.codespell] +ignore-words-list = """ +stdio,master,scrpt +""" +skip = """./.*,*/.metadata,*.xml,configure,*Makefile*,config*,*.m4,man.html""" +quiet-level=2 +ignore-regex = '\\[fnrstv]' +builtin = "clear,rare,informal,usage,code,names" + +[tool.setuptools] +include-package-data = false From a984badcc758244e7a0f08cb1a81303226686d2e Mon Sep 17 00:00:00 2001 From: MDW Date: Sun, 11 Aug 2024 22:41:55 +0200 Subject: [PATCH 2/3] Do test with sanitize on --- .github/workflows/ci.yml | 46 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..07c0f67 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,46 @@ +name: CI + +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-24.04 + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install dependencies + run: sudo apt-get update -q && sudo apt install -y dash bash ksh zsh tcsh csh rc + + - name: Build and Test (with sanitize) + run: | + SANITIZE="${SANITIZE} -fsanitize=address" + #SANITIZE="${SANITIZE} -fsanitize=thread" + SANITIZE="${SANITIZE} -fsanitize=leak" + SANITIZE="${SANITIZE} -fsanitize=undefined" + SANITIZE="${SANITIZE} -fsanitize=integer-divide-by-zero" + # SANITIZE="${SANITIZE} -fsanitize=vla-bound" + SANITIZE="${SANITIZE} -fsanitize=null" + SANITIZE="${SANITIZE} -fsanitize=signed-integer-overflow" + SANITIZE="${SANITIZE} -fsanitize=bounds" + #SANITIZE="${SANITIZE} -fsanitize=bounds-strict" + SANITIZE="${SANITIZE} -fsanitize=bool" + SANITIZE="${SANITIZE} -fsanitize=enum" + SANITIZE="${SANITIZE} -fsanitize-recover" # will try to continue running the program + #SANITIZE_LINK="-static-libasan -static -lasan -static -lubsan -ldl -lm" + SANITIZE_LINK="-l:libasan.a -l:libubsan.a -ldl -lm" + SANITIZE="${SANITIZE} -fno-sanitize=alignment" + ./autogen.sh + ./configure + make clean + make CFLAGS="${SANITIZE} -g -O2" LDFLAGS="${SANITIZE_LINK}" + make CC=gcc CFLAGS="${SANITIZE} -g -O2" LDFLAGS="${SANITIZE_LINK}" test + + - name: Build and Test (Normal) + run: | + ./autogen.sh + ./configure + make clean + make + make test From 52b7f6b0254c940b0f384bd3474a8292d16eb8a7 Mon Sep 17 00:00:00 2001 From: MDW Date: Sun, 11 Aug 2024 23:03:29 +0200 Subject: [PATCH 3/3] Sanitizer: stop the program when a leak is detected --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 07c0f67..01eba61 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,7 +27,7 @@ jobs: #SANITIZE="${SANITIZE} -fsanitize=bounds-strict" SANITIZE="${SANITIZE} -fsanitize=bool" SANITIZE="${SANITIZE} -fsanitize=enum" - SANITIZE="${SANITIZE} -fsanitize-recover" # will try to continue running the program + #SANITIZE="${SANITIZE} -fsanitize-recover" # will try to continue running the program #SANITIZE_LINK="-static-libasan -static -lasan -static -lubsan -ldl -lm" SANITIZE_LINK="-l:libasan.a -l:libubsan.a -ldl -lm" SANITIZE="${SANITIZE} -fno-sanitize=alignment"